-
-
Notifications
You must be signed in to change notification settings - Fork 227
use key not title for class name #652
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
Comments
Classes also are generated for schemas declared inline in endpoints, so the key within components doesn’t necessarily guarantee uniqueness. We could probably make the source of class names configurable though. I wonder how the openapitools generator selects class names. |
openapi uses the keys from components->samples, inline models I don't know, because I don't have in my current project in an other project (vue3 frontend) I use https://github.com/RicoSuter/NSwag this generates inline models with the same name like Option (first occurrence of model Option), Option1 (second occurrence of model Option), Option2, ... |
Hi there @dbanty - this bug recently caused a problem for my team and I, so we've implemented a fix using the method @erdnax123 described (counting recurrences of duplicate model names, and using the numbering to disambiguate). Wanted to check if you'd be open to a contribution with the fix? |
The main problem I have with the enumeration solution is that two completely equivalent OpenAPI docs could generate different code. Something like re-ordering an endpoint or extracting a model into a reference could cause two models to swap places, or even change the numbering of several models all at once. This makes the generated code quite fragile, especially for consumers not using a type-checker. If it ends up being the only way to generate code, then I suppose we'll just need to slap a big warning on the option which indicates what can happen. Probably a better solution is to fall back through a few naming strategies until we find the most-user-friendly-while-unambiguous one. For example, falling back to the ref model key from the |
in components -> schemas

here i have erros:
why used the title for class names and not the key. The key is always unique, but the title is not necessarily unique.
The text was updated successfully, but these errors were encountered: