#Using generics inside type of swagger nestjs

4 messages · Page 1 of 1 (latest)

candid solar
#

I have something like DataGridDto<ProductDto>

Im trying to use inside the type of ApiOkResponse and is accusing of boolean, but is just a object that has total, result T[]

@ApiOkResponse({
type: DataGridDto<ProductDto> })

Any ideas?

errant sinew
#
Aitor Alonso | Full-Stack Software Engineer

In this post I show you how to use TypeScript generics inside a Nest.js DTO in a way that allows Swagger to generate the correct OpenAPI schema definition.

candid solar
#

Jeez thanks a lot the second approach was the solution that I needed, as we already talking about swagger and nest. I have a lot of validators exception that can be throwed with a lot of different messages.

ApiUnprocessableEntity({type: ValidationSwagger})

and i create example for each one, like name invalid, or email invalid. Passing as parameters to the validationSwagger that is an objectDto mapped with ApiProperty()

#

Inspired on https://github.com/nestjs/swagger/issues/2260 , the request said that wanted to do something like

@ApiOkResponse({
      type: CatDTO,
      isArray: true,
      example: [{
        name: 'Tom'
      }]
    })

But i didn't find any material that is updated to this usecase

GitHub

Is there an existing issue that is already proposing this? I have searched the existing issues Is your feature request related to a problem? Please describe it When using $ref as the response type ...