-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NestJS Swagger Plugin when used with SWC references undeclared variable #2636
Comments
I believe I have narrowed this down to these lines, however it seems to be above my TS abilities to triage further. https://github.com/nestjs/swagger/blob/master/lib/plugin/visitors/model-class.visitor.ts#L186-L193 |
@evanwhitten, I faced the same problem. The problem occurs because the required dtos are not exported from the files. And here is a regular expression to add exports throughout the project (in parentheses you need to substitute your dto names without exports): |
I have same issue, any updates? |
As mentioned by @utrumo, you can workaround this by exporting the class. In my example exporting this class , resolves the error. |
@evanwhitten That does not solve the issue, dto classes are already being exported |
Hello, I also encountered the same problem, but I used the method you provided and it did not solve the problem.
|
Is there an existing issue for this?
Current behavior
When
@nestjs/swagger
CLI plugin is used alongside SWC, it generates output in the metadata.ts from thePluginMetadataGenerator
that includes undeclared variables. These variables inside the metadata.ts trigger failures when type checking, also during runtime if the metadata is attempted to be used somewhere likeloadPluginMetadata
.In my reproduction I have
HelloClass
andHelloClassSeperate
demonstrating that this bug is only present when the class exists in the same file as the DTO.metadata.ts -> Problem area:
{ required: true, type: () => [HelloClass] }
Minimum reproduction code
https://github.com/evanwhitten/reproduce-cli-swagger-reference
Steps to reproduce
nest start -b swc --type-check
-> view error from invalid metadata.ts generatedExpected behavior
Expected to have Swagger definitions generated the same as when running the app without SWC.
Without SWC
With SWC
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
@nestjs/swagger
NestJS version
10.2.6
Packages versions
Node.js version
v18.16.1
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: