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.
NestJS + Swagger: Any way to avoid writing everything manually for DTOs + file upload?
NestJS/Swagger plugin with webpack and NX - Stack Overflow
NRWL + NestJS Trying to use Swagger plugin - Stack Overflow
CLI plugin does not with SWC
» npm install typescript-nestjs-swagger-plugin
» npm install @nestjs/swagger
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?
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
}
}
]
},
}
}
}