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

feat: auto generate swagger decorators #164

Open
techsavvyash opened this issue Jul 8, 2024 · 4 comments
Open

feat: auto generate swagger decorators #164

techsavvyash opened this issue Jul 8, 2024 · 4 comments
Assignees

Comments

@techsavvyash
Copy link
Member

techsavvyash commented Jul 8, 2024

Description

Write a parser to read through the controller definitions, look for @Query() and @Body() decorators in function signature and generate corresponding swagger decorators like @ApiQuery(), @ApiResponse() and @ApiRequest().

This should be a CLI command, something like stencil add swagger.

Ref: #2

@Savio629 Savio629 self-assigned this Jul 18, 2024
@Savio629
Copy link
Collaborator

book1.controller.ts.-.crud.-.Visual.Studio.Code.2024-07-22.23-04-54.mp4

@techsavvyash
Copy link
Member Author

@Savio629 the decorators don't seem to have types on them, this won't generate the swagger documentation properly on it's own, without types these decorators don't add much value.

@Savio629
Copy link
Collaborator

Yeah actual working on it as well.
Forgot to leave a comment.

Regarding the types, I'll have to retrieve it from the methods itself right?

  @ApiOperation({ summary: 'Create an item' })
  @ApiBody({ type: CreateBook1Dto, description: 'Item data' })
  @ApiResponse({ status: 201, description: 'Item created', type: Book1 })
  @Post()
  async create(@Body() book1Dto: CreateBook1Dto): Promise<Book1> {
    return this.book1Service.create(book1Dto);
  }

Right now I'm generating the swagger decorators from a basic template
image

@techsavvyash
Copy link
Member Author

techsavvyash commented Jul 22, 2024

yes you would have to get them from the function parameter and return types.
Make sure to handle the cases:

  • 1. Some of the endpoints in the controller already have swagger decorators
    • 1.1 Those decorators don't have proper types just decorators
  • 2. Functions don't have proper type annotations -- default to any in this case
  • 3. There are more than one controller of each HTTP method type -- then each controller is annotated
  • 4. Solve for QueryParams in case of requests
  • 5. Solve for path params in case of dynamic endpoints like /user/:id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants