【发布时间】:2021-08-29 08:06:57
【问题描述】:
我正在使用 NestJS 7.6.11。我的控制器上有以下装饰器...
@Controller('private')
@ApiTags('MyObjects')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@UseInterceptors(new JwtInterceptor())
export class MyController {
我是否可以添加任何装饰器来生成 Swagger (OpenAPI 3) 文档,从而表明我的控制器中的所有方法都需要具有“授权”标头?
编辑:作为回应,我添加了@ApiHeader,所以我的控制器和方法看起来像
@
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> {
但是当生成 swagger 文档时,虽然我可以输入“授权”标头值,
当我单击“执行”时,它不会包含在我的 curl 中,它生成为
curl -X GET "http://localhost:8060/myendpoint/abcdef" -H "accept: application/json"
【问题讨论】:
标签: swagger nestjs openapi authorization-header