swagger
swagger copied to clipboard
Allow multiple schemas with same name
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
In our project we reuse name patterns like "FindOneDto" or "FindAllDto". We now have the problem that the Swagger docs reuse one of the DTOs (perhaps the first one calculated) and display the same DTO as schema in all places where a different DTO with the same name should be displayed.
Describe the solution you'd like
Maybe a solution like in NestJS v8 is possible, where the class reference is used as key instead the name.
Or the build process should throw a warning/error if unique schema names are still required. Now the build will continue with an incorrect result.
Teachability, documentation, adoption, migration strategy
Mention as new feature (or bugfix?) in changelog.
What is the motivation / use case for changing the behavior?
Avoidance of a pitfall for nestjs-swagger users.
I have also encountered the same issue. I believe it's necessary to explicitly specify the type of the class being used or even intentionally break the build when there are multiple classes with the same naming convention. This is important because it's difficult for developers to be aware of the implications when such issues arise.
Ahh this is exactly the issue i'm having (associated issue: https://github.com/hey-api/openapi-ts/issues/42).
You can see here using the metadata generation we have two controllers that both implement their own ListDeviceResponse
:
This subsequently means the swagger actually only ends up with a single definition, which as @bc-m pointed out looks to be the first one.
Which then obviously leads to downstream issues when clients are generated from the swagger etc, they're returning the wrong types.
This is a frustrating gotcha/limitation that will totally catch people off guard, as it doesn't result in any sort of compilation error or warning. For now i'm going to try and write some sort of linting to enforce dto names are unique across a project.