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 startornest start:dev)
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 startornest start:dev)
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.
Nest plugin can be found under your node_modules directory under: @nestjs/swagger/dist/plugin
This should be set in your complier options:
"compilerOptions": {
"plugins": ["@nestjs/swagger/dist/plugin"]
}
I had exactly the same issue.
I solved it with this:
- Make sure you have nestcli installed:
npm i -g @nestjs/cli - Update nestcli on deployment before you make npm install:
nest update - If this not helps, try another Swagger-Version. I had the problem with version 4.5.9, I upgraded to
@nestjs/swagger": "^4.5.11and it helped.
Hope this works for you.
» npm install @nestjs/swagger
» npm install typescript-nestjs-swagger-plugin
You may have forgotten to load metadata (that was generated by the plugin).
From https://docs.nestjs.com/openapi/cli-plugin#swc-builder
import metadata from './metadata';
...
await SwaggerModule.loadPluginMetadata(metadata);
const document = SwaggerModule.createDocument(app, config);
do you know that the plugin won't touch source files, right? you can compare the .dto.js with and without the plugin enabled
Seems like there is already an open BUG #2147 for the same issue and there are multiple solutions presented in the long on going discussion but none of them are full proof and some have side effects. Nonetheless I would highly recommend you to read discussion and monitor it.
NRWL doesn't use Nest CLI, however you can still achieve the same results by adding the Swagger Plugin to the webpack transformation pipeline that NX uses.
- Open the
project.jsonin the specific app where you want the NestJS Swagger Plugin to be active. - Locate the configuration for the
@nrwl/webpack:webpackexecutor - Add
@nestjs/swagger/pluginto the list oftransformers. - (Optional) configure the plugin's settings like
introspectComments
Below an example:
{
"name": "project-with-swagger-plugin",
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"options": {
// other options
"transformers": [
// register plugins here
{
"name": "@nestjs/swagger/plugin",
"options": {
"introspectComments": true
}
}
]
},
}
}
}