I'm using NestJS 7.6.11. I have the following decorators on my controller ...

@Controller('private')
@ApiTags('MyObjects')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@UseInterceptors(new JwtInterceptor())
export class MyController {

Is there any decorator I can add that would result in Swagger (OpenAPI 3) documentation being generated such that it indicates that all methods in my controller need to have an "authorization" header?

Edit: In response the answer given I added the @ApiHeader so my controller and method look like

@

Controller('myendpoint')
@ApiTags('MyObject')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@ApiHeader({
  name: 'authorization',
  description: 'Auth token',
})
@UseInterceptors(new JwtInterceptor())
export class MyObjectController {

...
 @Get('/:id')
  @ApiOkResponse({
    description: 'OK',
    type: Content,
  })
  @ApiBadRequestResponse()
  @ApiInternalServerErrorResponse()
  @ApiOperation({
    summary: 'Get object by id',
    description: 'Get object by id',
    operationId: 'findObjectById',
  }) 
  findObjectById(@Req() req, @Param('id') id: string): Promise<MyObject> {

but when the swagger docs are generated, although I'm able to enter an "authorization" header value,

enter image description here

it doesn't get included with my curl when I click "Execute", which is generated as

curl -X GET "http://localhost:8060/myendpoint/abcdef" -H  "accept: application/json"
2

There are 2 best solutions below

7
Jay McDoniel On

@ApiHeader(), @ApiBasicAuth(), @ApiBearerAuth(), @ApiOAuth2(), @ApiSecurity(), all of which are found on this page. Your specific case may vary, but one of these should do the trick.

0
Sohail Shrestha On

Add this to your endpoint header:

@ApiBearerAuth('Authorization')