nestia
nestia copied to clipboard
Watch for @tag and @security on the Controller class
It is pretty common for a Controller to have the same security rules on all its endpoints Please allow us to add those annotations on the controller so we do not have to repeat it on all the endpoints.
Here is how a controller would look like
/**
* Controller for the Libraries
*
* @security bearer
* @tag library
*/
@Controller('library')
@Authenticated() < --- having @security on the controller would be usefull for this use case where a guard is there for all the endpoints
export class LibraryController {
constructor(public libraryService: LibraryService) {}
/**
* List all libraries
*
* @security something-else <---- allow for overide just in case, but still add @tag from the controller
*
*/
@TypedRoute.Get('/')
public async libraries(): Promise<Library[]> {
return this.libraryService.getLibraries();
}
/**
* Create a new library and start scanning it <--- here both @security and @tag from the controller would be added as default
*/
@TypedRoute.Post('new')
public async newLibrary(
@Body() createDto: CreateLibraryDTO,
): Promise<boolean> {
return this.libraryService.createLibrary(createDto);
}
}
Use @ApiTag and @ApiSecurity decorator of @nestjs/swagger
to the controller.
Nestia can identify them.
Ah, I've missed documentation on the https://nestia.io/docs/sdk/swagger article.
I'll do it someday. Thanks for reporting.
/**
* Controller for the Libraries
*/
@ApiTags('library')
@ApiSecurity('bearer')
@Controller('library')
@Authenticated()
export class LibraryController {}
Works as expected thanks for support. Nestia is amazing! keep up the good work