Dav*_*ave 10 swagger openapi nestjs authorization-header
我正在使用 NestJS 7.6.11。我的控制器上有以下装饰器......
@Controller('private')
@ApiTags('MyObjects')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@UseInterceptors(new JwtInterceptor())
export class MyController {
Run Code Online (Sandbox Code Playgroud)
是否有任何我可以添加的装饰器会导致生成 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> {
Run Code Online (Sandbox Code Playgroud)
但是当生成 swagger 文档时,尽管我可以输入“授权”标头值,
当我单击“执行”时,它不会包含在我的curl中,它生成为
curl -X GET "http://localhost:8060/myendpoint/abcdef" -H "accept: application/json"
Run Code Online (Sandbox Code Playgroud)
@ApiHeader()、、、、、、都可以在这个@ApiBasicAuth()页面找到。您的具体情况可能会有所不同,但其中之一应该可以解决问题。@ApiBearerAuth()@ApiOAuth2()@ApiSecurity()
| 归档时间: |
|
| 查看次数: |
6597 次 |
| 最近记录: |