-
Notifications
You must be signed in to change notification settings - Fork 440
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
Use unambiguous ref names #313
Conversation
serializer type name may be ambiguous, e.g. in different applications of the same project one may have different `Account` with the same serializer class name but with different set of fields, etc. They will still have the same `$ref` name in API spec. Adding module name to ref name should solve this problem.
Does this mean that for all existing projects all the model names will change? If so i'd say it's not acceptable since it will break every client app that uses existing apis. |
Hello, @rsichny , thanks for your feedback! Yes, it will change names for all models in existing projects, but these names are not part of API itself, so I don't think it should not break anything. Once generated with |
But this means that whenever someone generates a new client using codegen - they'll need to change ALL the code which uses the generated client. Example 1: in our case QAs generate the new client using codegen for api schemas on each release and then they run test suite (thouthands of test cases) using the newly generated client. Global change of the names which are being output by codegen will produce enormous amount of work (they'll need to change each of the references to the old names). Example 2: our partners use swagger definitions to generate the swagger client and use that client in their code. As soon as we decide to add a new field to api they'll need to re-generate the swagger client and all the integration will break. My suggestion is to leave the old behavior by default, and either make this new behavior configurable, or only add prefixes for the cases when the schema is added to the list of definitions if the same definition already exist. |
However in case of dynamic clients like |
Actually, since all the name conflicts can be resolved by using ref_name in serializer i don't think any change is necessary at all. https://drf-yasg.readthedocs.io/en/stable/custom_spec.html#serializer-meta-nested-class |
Yes, I was also thinking about adding some settings to switch this behaviour on keeping old one as a default. However I still believe that it would be nice to have such unambiguous behavior by default, maybe in the next major release. Right now this behavior is very awkward: you will get improper API documentation in case on names clash without any warning and it is really hard to debug. I will leave this PR open for now to gather more opinions and have a look if it is possible to make this problem more clear(raise a warning when app finds ambiguous name, e.g.) |
@kammala how about adding a warning into https://github.com/axnsan12/drf-yasg/blob/master/src/drf_yasg/openapi.py#L540 when the ref names overlap? |
Others may use the swagger spec for live API clients or form generators, so changing stuff suddenly like this is still kinda awkward. Plus, the problem this solves is not that common, I think. This solution might work behind a setting. Maybe a better one would be to always raise an exception when encountering multiple serializers with the same name, forcing explicit disambiguation by the user. |
The warning should already be there: drf-yasg/src/drf_yasg/inspectors/field.py Lines 130 to 133 in 583e404
|
@axnsan12 maybe just change to |
I think I'll just change it to an exception 😄 |
However, this this warning doesn't work for some reason :( |
so this warning will never be printed :( |
looks like #156 wasn't fixed |
serializer type name may be ambiguous, e.g. in different applications of the same project one may have different
Account
with the same serializer class name but with different fields, etc.In current implementation they will have the same
$ref
name in API spec which will lead to improper API representation.Adding module name to ref name should solve this problem.