0

I'm struggling with the typing of my query params in NestJs, I have a route like this and I want to be able to filter my result with all the keys of my datamining entities. I did this and it's working but I can't find a way to make it appear in my swagger:

@Controller('datamining')
export class DataminingController {
    @Get('short')
    @ApiQuery({ required: false, type: DataminingShort }) // <== how to type this ? Obviously this one is not working.
    findAll(@Query() options?: Partial<DataminingShort>) { // <== DataminingShort is an entity class for typeOrm
       return this.dataminingShortService.findAll(options);
    }
}

I want to avoid doing a specific class just for this since it's exactly the same properties as my typeOrm entity

Nicolas Menettrier
  • 1,647
  • 1
  • 13
  • 28
  • What do you mean by "it't not working"? Do you have your `DataminingShort` class decorated with `@nestjs/swagger` annotations? – Jay McDoniel Jul 26 '22 at 16:04
  • I have the nestjs/swagger plugin installed that is supposed to automatically check the class so you don't have to put the nestjs/swagger annotations (It works with other routes). Here the query params are not even showing in the swagger – Nicolas Menettrier Jul 26 '22 at 16:07
  • @JayMcDoniel What I mean by "it's not working" is that the query params are not displayed in my swagger, I was expecting to have all the properties of my entity DataminingShort displayed so I can filter my query from the swagger. But instead of this it just show nothing – Nicolas Menettrier Jul 26 '22 at 16:12

1 Answers1

0

If your DataminingShort entity isn't showing up in the docs, it might be because your nest-cli.json doesn't specify the correct dtoFileNameSuffix. I assume your DataminingShort is located in a DataminingShort.entity.ts but maybe not.

"compilerOptions": {
    "plugins": [
      {
        "name": "@nestjs/swagger",
        "options": {
          "introspectComments": true,
          "dtoFileNameSuffix": [".dto.ts", ".entity.ts"]
        }
      }
    ],

Another option might be to add @ApiExtraModels(DataminingShort) to your DataminingController controller class.

TPoschel
  • 3,775
  • 2
  • 30
  • 29