I have a tsoa request, where I'm trying to include a custom required header, but it can only be added as optional like this.
@Header('X-Correlation-Id') correlationId?: string
I really would like it to be required, is there away to achieve this?
@Post('case/businessContact')
public async handleCreateBusinessContactCase(
@Header('X-Correlation-Id') correlationId: string,
@Request() request: koa.Request,
@Body() requestBody: ContactRequest,
): Promise<any> {
correlationId = request.header['x-correlation-id'] as string;
console.log('request: ', request.ctx);
console.log('correlationId: ', correlationId);
//const logCtx = LogContext.getLogContext(request.ctx, 'handleCreateBusinessContactCase');
//console.log(logCtx);
//const repsone = await createBusinessContactCase(logCtx, requestBody);
//return Promise.resolve(repsone);
}
With this setup I get the following error
BadRequestError: {"fields":{"X-Correlation-Id":{"message":"'X-Correlation-Id' is required"}}}
at Object.throw (/Users/jonbrynjar/Development/Typescript/micro.salesforce/node_modules/koa/lib/context.js:97:11)
at Object.<anonymous> (/Users/jonbrynjar/Development/Typescript/micro.salesforce/src/routes.ts:294:30)
at step (/Users/jonbrynjar/Development/Typescript/micro.salesforce/src/routes.ts:33:23)
at Object.next (/Users/jonbrynjar/Development/Typescript/micro.salesforce/src/routes.ts:14:53)
at /Users/jonbrynjar/Development/Typescript/micro.salesforce/src/routes.ts:8:71
at new Promise (<anonymous>)