swagger: CLI plugin does not with SWC
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
Currently, the CLI plugin generates an invalid metadata.ts file. It uses invalid import paths on Windows, includes syntax errors with the summary field for @ApiOperation, and also generates missing imports for enums or classes which are used in the DTO but not exported (which it doesn’t have any issues with when using TSC).
- broken paths on windows
- Linux paths (correctly relative to the
srcdirectory) - invalid summary field for endpoints
it’s worth noting that removing the
@ApiOperationtag or disabling theintrospectCommentsoption avoids this bug. - missing imports for non-exported enums/classes used in exported DTOs, when exported they are correctly referenced and imported in the
ttypes array.
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-e46jbt?file=src%2Fmetadata.ts
Steps to reproduce
Note SWC doesn’t work on Stackblitz at the moment so you may want to download it locally, the type-checking does work and the error is present on Stackblitz. Obviously, you’d need a Windows machine for the incorrect path bug.
- create a nestjs project with swc and swagger
- create a dto and use the a dto
- annotate an endpoint with the dto, description and summary.
- run
nest build -b tsc --type-check
Expected behavior
The above errors should not occur, --type-check should be compatible with a codebase that worked with TSC, if not, we should mention how to make it compatible in the docs.
Package version
7.0.4
NestJS version
10.0.3
Node.js version
v18.13.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 23 (9 by maintainers)
I don’t know, maybe i should create a new bug request, but, this bug relevant to this topic.
The thing in PartialType. It doesn’t work with SWC compiler. Like:
export class UpdateEquipmentDTO extends PartialType(CreateEquipmentDTO) {}Made output like that: metadata.ts
models: [ [ import("./equipments/DTO/create-equipment.dto"), { CreateSectionDTO: { title: { required: true, type: () => String, minLength: 1 }, imageURL: { required: false, type: () => String }, }, CreateEquipmentDTO: { title: { required: true, type: () => String, minLength: 1 }, shortDescription: { required: false, type: () => String, maxLength: 300, }, description: { required: false, type: () => String, maxLength: 5000, }, price: { required: true, type: () => Number }, imageURLs: { required: true, type: () => [String] }, previewImageURL: { required: false, type: () => String }, sectionId: { required: true, type: () => Number }, }, }, ], [ import("./equipments/DTO/update-equipment.dto"), { UpdateEquipmentDTO: {} }, ], ...Or screenshot:
DISCORD TOPIC: https://discord.com/channels/520622812742811698/1126116119783161897
Just updated the docs to use
await, great catch!Build command doesn’t wait to run SWC only in the
--watchmode which shouldn’t be used in CIs anyway. It does perform type-checking earlier though, as type-checking is actually required for us to produce the metadata file.As long as this file exists, it can be safely out-of-the-date as it will be updated in CI anyway before the application is launched.
We might need to add more info on that to the docs, great questions!