'How to enable NestJs swagger 4.x plugin
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.
Solution 1:[1]
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
ornest start:dev
)
Solution 2:[2]
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.
Solution 3:[3]
for me it works with:
"plugins": [
"node_modules/@nestjs/swagger/plugin"
]
Solution 4:[4]
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.
Solution 5:[5]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | wkrueger |
Solution 3 | tano |
Solution 4 | Reisy Eytan |
Solution 5 | yspreen |