-
Notifications
You must be signed in to change notification settings - Fork 265
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 ref_name to disambiguate multiple components with identical names #27
Comments
i guess renaming is not an option when 2 libraries collide with each other. i suppose there is no way around this. 813 warnings? that is a lot... |
It is a lot (mostly caused by django-oscar-api, and a complex auth system), but drf-yasg failed miserably, so I am a huge fan of drf-spectacular atm. |
i looked at the use cases again for this issue and i see 3 distinct cases:
when it comes to lib code (case 1&2) decoration via All you have to do is define something like this anywhere (*) in YOUR code. setting the drf-spectacular/tests/test_regressions.py Lines 380 to 385 in d63c5c6
@MissiaL @jayvdb what do you think? (@foarsitter that general mechanic might also be interesting for you) closing this for now. feel free to suggest a better approach. (*) anywhere == anywhere the interpreter visits at least once. I recommend having a |
I already did. drf-yasg uses ref_name, which is a better approach for libraries to use, and is widely implemented - that search is quite restrictive - more examples can be found with broader search, and that is only OSS code, not the many OSS forks which have been modified to fix this, and non-public django projects running in production. |
I will support @jayvdb |
@jayvdb yes you already did, but imho it does not solve the issues outlined in my comment. how do you solve case 1 let's say you use 2 libraries that both have @MissiaL i can understand that is is more convenient because your code base already supports it. What i don't really understand is why it is more convenvient to use a i was not aware that that other libs support |
You raise an issue in their project to support drf-yasg & drf-spectacular. And fork and fix it yourself, submit a PR, and use It isnt a zero-sum game. Your extension approach is great, but it doesnt mean this library cant also be compatible with drf & drf-yasg where it helps. |
Note that duplicate serializers is implicit in using oscar, which requires "forking" their apps to extend them in order to customise the site. So I receive lots of
Renaming my models definitely breaks oscar, but renaming the serializer may not -- however it would deviate from their instructions which makes the site less understandable/umaintainable by someone else. I could add an 'extension' for all of them, but it is much easier to add |
no one suggested renaming the models. model names are not used in the schema anyway.
i absolutely agree. at the beginning of the issue i wasn't aware of the full picture. there was only the "what" but not the "why" and "how". after the clarifications this makes a lot more sense. for future issues, we should try amd get those questions straightened out from the get-go.
this is interesting. please do. spectacular only processes what it finds in the views. let me know what you find, then we can see how to solve it.
i guess that is leaking issue. as far as i understand those would disappear if the leaking stopped. how would you use |
just as clarification. i absolutely support adding |
I import the oscar serializer and subclass it to add In addition to supporting ref_name, it would be better if the default/worstcase fallback to auto-disambiguate the two (using qualname? or even random gibberish) so then the result of multiple similar-name components can be seen in the generated doc, which will result in better support experience, especially for any 'leaking' of installed objects the project isnt expecting to be in their spec. |
does that mean you have 2 partner serializers in the schema? is that as intended? i did this https://django-oscar-api.readthedocs.io/en/latest/usage/customizing_oscarapi.html for the 2 example serializers and encountered no leaking issues yet. i have a basic oscar setup with the api plugin and those changes. can you provide a snippet for reproduction?
absolutely. that makes sense. if random, i guess it would need to be pseudo random otherwise the schema would change on every run. |
i added |
Awesome. I see the result! Very helpful for me working out those shadows. |
awesome. are those issues completely gone now? if yes you can close this. i'll keep a mental note for the remaining |
I think drf-yasg uses
ref_name
to bypass this problemhttps://drf-yasg.readthedocs.io/en/stable/custom_spec.html#serializer-meta-nested-class
The text was updated successfully, but these errors were encountered: