Skip to content
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

Encountered 2 components with identical names #90

Closed
MahmoudAljabary opened this issue Jun 10, 2020 · 5 comments
Closed

Encountered 2 components with identical names #90

MahmoudAljabary opened this issue Jun 10, 2020 · 5 comments

Comments

@MahmoudAljabary
Copy link

When reusing the same schema model. i encounter the following: Warning #1: Encountered 2 components with identical names "Error". This will very likely result in an incorrect schema. Try renaming one.
Is there is a way to overcome this, disable this or hide it?

@tfranzel
Copy link
Owner

If you have 2 serializers with identical name spectacular notifies your of the conflict. spectacular cannot decide for you what a proper name is. it only has Error to go with and that produces a conflict. to resolve it you have to options:

  1. rename one serializer
  2. use the ref_name feature ported from drf-yasg on one. https://drf-spectacular.readthedocs.io/en/latest/drf_yasg.html?highlight=ref_name#from-drf-yasg-to-openapi-3
    that is an attribute on the serializer Meta class. it overrides default name generation.

this is related to #51. default collision resolution is a pending change, but would just add a random suffix anyway as an intermediate solution to have a correct schema even it is not nice looking.

@jayvdb
Copy link
Contributor

jayvdb commented Jun 11, 2020

A related issue I am running into is that the Router ordering of paths is not understood by the schema generator, which makes the current handling of identical names especially painful. See #92

@MahmoudAljabary
Copy link
Author

@tfranzel adding a random suffix does indeed work, but as you mentioned is not nice looking. suppose "Error" model is used in 10 endpoints. then we have Error1, Error2 .... Error10.
I think if we can find a way to catch and ignore the warning, might be a better approach.

@tfranzel
Copy link
Owner

@jayvdb we will deal with that in #92

@MahmoudAljabary you have to understand that each Serializer needs a unique name for the schema to not be broken for client generation. To me, it sounds a bit weird that you have 10 different Error serializers. spectacular can only utilize the class name and ref_name, as there is no other processable information for uniquely naming the component.

with that warning the spectacular notifies you that it found an issue. for the warning to disappear we would need a resolution for this issue. can you make a alternate suggestion for uniquely name the serializers? because i currently don't see no other good options here.

@tfranzel
Copy link
Owner

closing because this more a feature than a bug. even with a different conflict solution the warning would remain to inform about the "auto conflict resolution" component names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants