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.
Jenkins says: @nestjs/swagger/plugin" plugin could not be found!
Error The "@nestjs/swagger" plugin is not compatible with Nest CLI. Neither "after()" nor "before()" nor "afterDeclarations()" function have been provided.
nestjs - Nest/swagger not found - Stack Overflow
nest-cli @nestjs/swagger plugin don't work - Stack Overflow
» 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
}
}
]
},
}
}
}
Hey guys, do I have to write everything manually to integrate Swagger with NestJS?
For example, do I really need to add code like this in every DTO?@ApiProperty({
description: 'Username (3-20 characters, letters, numbers, underscore only)',
example: 'john_doe123',
minLength: 3,
maxLength: 20,
})
and doing the same for the response of each end point
I found the Swagger CLI plugin and installed it. It works, but not as expected.
The problem:
-
My API endpoint receives a
CreateUserDtobody and a file. -
The file validation is handled in the controller.
-
The request should be
multipart/form-data, but Swagger still showsapplication/json, and there's no info about the file. -
The CLI generates something, but not what I need.
Any advice? Or a good video that covers this exact use case (DTO + file upload) without doing everything manually?