9

How do you use the new swagger plugin? I have it in my compiler options:

  "compilerOptions": {
    "plugins": ["@nestjs/swagger/plugin"]
  }

And I am running the application with nest start as described: https://docs.nestjs.com/recipes/swagger#migration-to-40

However, no automated-magic documentation appears to be happening.

1
  • I'm trying to reproduce your environment with a basic est ew project with swagger ad I'm rather getting the error: Error "@nestjs/swagger/plugin" plugin could not be found! Can you please provide your package.json, did you istall the swagger plugin.... Dec 17, 2019 at 12:36

5 Answers 5

27

It was an issue with global dependencies conflicting with local ones, as well as the old build (set to incremental mode) conflicting with the new property generation. Did the following to resolve the issue:

  • If nest cli is globally installed, manually upgrade it: yarn global upgrade upgrade @nestjs/cli, or with npm (npm update -g @nestjs/cli)
  • Upgrade local service nest to most recent version: nest update
  • Add the following to your nest-cli.json:
  "compilerOptions": {
    "plugins": ["@nestjs/swagger/plugin"]
  }
  • Remove your local dist folder (or do a yarn build)
  • Start the server with the nest cli commands (i.e. nest start or nest start:dev)
8
  • 3
    Please precise that we should run nest start to start the server. I was actually running npm run start:dev (which use nodemon) and it was not working. Now everything is OK, thanks ! Apr 12, 2020 at 22:45
  • 2
    I did all the steps, used a file named *.dto.ts, and it's still not working : / May 15, 2020 at 21:03
  • Very helpful answer, this solved my problem. It works with and without watch-mode for me now.
    – Nils
    Apr 10, 2021 at 11:23
  • 4
    Removing the /dist/ folder and starting again solved my problem, with and without the watch flag Aug 29, 2021 at 9:11
  • 3
    As of now, only "plugins": ["@nestjs/swagger"]is necessary.
    – FabZbi
    May 26, 2022 at 21:03
3

My fix was...

The plugin filters the files it looks up based on a suffix rule.

  • If you use a different naming convention than Angular's, you need to pass custom plugin options to fix it;
  • If your controller or Dto is not inside a file with the name suffix, it wont be upgraded.
1
  • You just saved me from going crazy, had the DTO inlined for testing... I was close to getting mad.
    – CaKa
    Apr 16, 2022 at 16:30
1

My fix was:

I changed my filenames to one of the following suffixes: ['.dto.ts', '.entity.ts'] (e.g., create-user.dto.ts)

as described in the document:

https://docs.nestjs.com/openapi/cli-plugin

and then it worked for me.

0

for me it works with:

"plugins": [
  "node_modules/@nestjs/swagger/plugin"
]
0

because I've spent hours on this and couldn't find this fix mentioned anywhere:
make sure you install the dependency reflect-metadata. that's what I was missing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.