SamagraX-Stencil / stencil

NestJS on steroids 💪
https://stencil.samagra.io
MIT License
30 stars 33 forks source link

feat: auto generate swagger decorators #164

Open techsavvyash opened 4 months ago

techsavvyash commented 4 months ago

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 commented 4 months ago

https://github.com/user-attachments/assets/544c6412-29c7-4b93-890c-ecc98063c507

techsavvyash commented 4 months ago

@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 commented 4 months ago

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 commented 4 months ago

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