Globally Apply Decorator to All Controllers Nestjs

Viewed 911

I am creating an API using Nestjs and in trying to scale realized that there are some decorators that I use that are needed for every controller. E.g @ApiBearerAuth(). Is there a way to globally apply decorators on all controllers or all controller methods of a project.

1 Answers

addSecurityRequirements might be what you need

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

You can then disable it selectively for some endpoints with @ApiSecurity([])

Related