Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch for @tag and @security on the Controller class #754

Open
loucass003 opened this issue Jan 16, 2024 · 3 comments
Open

Watch for @tag and @security on the Controller class #754

loucass003 opened this issue Jan 16, 2024 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers question Further information is requested

Comments

@loucass003
Copy link
Contributor

loucass003 commented Jan 16, 2024

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);
  }


}
@samchon
Copy link
Owner

samchon commented Jan 17, 2024

Use @apiTag and @apisecurity decorator of @nestjs/swagger to the controller.

Nestia can identify them.

@samchon samchon self-assigned this Jan 17, 2024
@samchon samchon added the question Further information is requested label Jan 17, 2024
@samchon
Copy link
Owner

samchon commented Jan 17, 2024

Ah, I've missed documentation on the https://nestia.io/docs/sdk/swagger article.

I'll do it someday. Thanks for reporting.

@samchon samchon added documentation Improvements or additions to documentation good first issue Good for newcomers enhancement New feature or request labels Jan 17, 2024
@loucass003
Copy link
Contributor Author

loucass003 commented Jan 18, 2024

/**
 * 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants