将装饰器全局应用到所有控制器 Nestjs

Nig*_*NKY 5 node.js express angularjs swagger nestjs

我正在使用 Nestjs 创建一个 API,并在尝试扩展时意识到我使用了一些每个控制器都需要的装饰器。例如@ApiBearerAuth()。有没有一种方法可以在项目的所有控制器或所有控制器方法上全局应用装饰器。

Oli*_*r.B 1

addSecurityRequirements might be what you need

const config = new DocumentBuilder()
    .setTitle('Title')
    .setDescription('Description...')
    .setVersion('1.0')
    .addBearerAuth(undefined, 'ApiKeyAuth')
    .addSecurityRequirements('ApiKeyAuth')
Run Code Online (Sandbox Code Playgroud)

然后,您可以有选择地为某些端点禁用它 @ApiSecurity([])