Currently, I am using @ApiExcludeEndpoint() ### on top of all methods to hide the end-point in the swagger-ui, like this:
import { Controller, Get, Query, Param } from '@nestjs/common';
import { ResourceService } from './resource.service';
import { Auth } from 'src/auth/auth.decorator';
import {
ApiTags,
ApiSecurity,
ApiOkResponse,
ApiForbiddenResponse,
ApiCreatedResponse,
ApiExcludeEndpoint
} from '@nestjs/swagger';
@Controller()
@ApiTags('Resources')
@ApiSecurity('apiKey')
export class ResourceController {
constructor(private readonly resourceService: ResourceService) {}
@Get('get_url')
@ApiExcludeEndpoint()
@Get()
@ApiOkResponse({
description: 'Resources list has succesfully been returned',
})
@ApiForbiddenResponse({ description: 'You are not allowed' })
@Auth(...common_privileges)
findAll(@Query() query: any): any {
......
}
@Get('get_url/:id')
@ApiExcludeEndpoint()
@ApiOkResponse({ description: 'Resource has succesfully been returned' })
@ApiForbiddenResponse({ description: 'You are not allowed' })
@Auth(...common_privileges)
findById(@Param('id') id: string, @Query() query: any): any {
......
}
}
I Need to know is there a way to hide all the end-point in the controller using a single decorator, I checked some documents it says to use @ApiIgnore() and @Hidden() but I can't find those in nestjs-swagger. Please comment on this
One possibility is to explicitly include the modules that you'd like to include in the swagger docs instead of just "including all modules" by default. Example:
const options = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const catDocument = SwaggerModule.createDocument(app, options, {
include: [LionsModule, TigersModule], // don't include, say, BearsModule
});
SwaggerModule.setup('api/cats', app, catDocument);
Without the explicit include:[]
property, LionsModule
, TigersModule
, and BearsModule
would be automatically included.