Skip to content

Duplicate Tags #1625

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

Closed
jkraml opened this issue Apr 21, 2022 · 2 comments
Closed

Duplicate Tags #1625

jkraml opened this issue Apr 21, 2022 · 2 comments
Labels
invalid This doesn't seem right

Comments

@jkraml
Copy link

jkraml commented Apr 21, 2022

Describe the bug
The OpenAPI specification states: "Each tag name in the list MUST be unique.". However, in certain cases you can get duplicate tags.

Springdoc appears to ensure tag uniqueness using Sets which delegate to Tag.equals which includes more fields than just name. Thus allowing duplicates if e.g. the description differs.

We encountered this while migrating from Springfox, since we declare tags on controller classes and additionally in a global configuration where we add descriptions. A stripped-down example including a fix can be seen here.

To Reproduce

  • Create two controllers with @Tag(name="foo") and @Tag(name="foo", description="d")
  • Open OpenAPI Description (/v3/api-docs) and inspect the tags list. It will contain two entries with name "foo":
    "tags":[{"name":"foo"},{"name":"foo","description":"d"}]
  • Alternatively: declare tags programmatically (see example linked above)

Expected behavior

  • Include each tag name only once in the OpenAPI Description
  • Log a warning when there are duplicate tags. Trying to de-duplicate the tags would be even better.

Additional context
Swagger UI appears to only use the first/last tag it encounters. If a tag is duplicated with and without a description, you'd sometimes see the description in the UI and sometimes not, depending on the tag order in the OpenAPI Description. That is how we noticed this.

As indicated in the example linked above, it would be nice if a solution would allow using a tag on multiple controllers without having to redeclare its description every time.

@jkraml
Copy link
Author

jkraml commented Apr 21, 2022

If I may suggest a default de-deduplication strategy: return a Tag object containing just the name. That loses all additional data, but is correct and universal.

@bnasslahsen
Copy link
Collaborator

@jkraml,

There are no plan for this deduplication.
The generated code, reflects your OpenAPI description.

Try correcting your OpenAPI description, or use your custom OpenApiCustomiser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants