Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
nestjs-swagger-hide-on-prod
Advanced tools
A progressive Node.js framework for building efficient and scalable server-side applications.
Exclude your nestjs controller or endpoint from swagger documentization on production env.
$ yarn add nestjs-swagger-hide-on-prod
or
$ npm i --save nestjs-swagger-hide-on-prod
In default, when NODE_ENV
is set to PROD
or PRODUCTION
, following decorators will exclude the whole controller or specific endpoint
To exclude whole controller on prod :
@Controller('foo')
@ApiTags('Foo API')
@SwaggerHideControllerOnProd() // Add this line to exclude FooController from swagger when process is on production environment
export class FooController {
constructor(private readonly fooService: FooService) {}
@Get(':fooId')
searchFoos(): Promise<any[]> {
return Promise.resolve([]);
}
@Post()
createFoo(): Promise<any> {
return Promise.resolve();
}
}
To Exclude specific endpoint only on prod :
@Controller('foo')
@ApiTags('Foo API')
export class FooController {
constructor(private readonly fooService: FooService) {}
@Get(':fooId')
searchFoos(): Promise<any[]> {
return Promise.resolve([]);
}
@Post()
@SwaggerHideEndpointOnProd() // Exclude POST /foo endpoint from swagger on prod env
createFoo(): Promise<any> {
return Promise.resolve();
}
}
To customize exclusion condition you can use
instead.
Input parameter could be static boolean
or a function
, which returns a boolean
value.
@Controller('foo')
@ApiTags('Foo API')
export class FooController {
constructor(private readonly fooService: FooService) {}
@Get(':fooId')
@ApiOperation({
summary: 'Search foos info',
description: 'This method is depreacted. Please, use GET "v2" instaed',
})
@SwaggerHideEndpoint(() => {
return moment(new Date()).isAfter(`2022-12-31`);
// After year 2022, this method would be excluded from swagger documentization
})
veryOldFooSearchApi(): Promise<any[]> {
return Promise.resolve([]);
}
@Get('v2/:fooId')
@ApiOperation({
summary: `Search foos info`,
description: `Get information matches id`,
})
brandNewFooSearchApi(): Promise<any[]> {
return Promise.resolve([]);
}
}
FAQs
A progressive Node.js framework for
We found that nestjs-swagger-hide-on-prod demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.