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

Name collision in api spec possible for colliding supertype names #4706

Open
tbvh opened this issue Jun 24, 2024 · 0 comments
Open

Name collision in api spec possible for colliding supertype names #4706

tbvh opened this issue Jun 24, 2024 · 0 comments

Comments

@tbvh
Copy link

tbvh commented Jun 24, 2024

In a project where we use polymorphism quite a lot we identified that supertypes with a shared name might collide. The api spec output is therefore incorrect.
Instead of producing an incorrect swagger spec there should be an error raised.

The issue arises when there exist two (or more) type hierarchies with a common supertype name and the supertypes are annotated with @JsonSubTypes. The resulting model uses the allOf construct to specify the inherited properties. Where the schema is wrong is that only one of the supertype definitions is included. Subtypes of the other (not included) supertype reference the incorrect spec by name, while still referencing the supposed inherited properties (e.g. in the 'required' list).

For example, the supertype and subtype mismatch in the schema can look like this, Foo extends from the CollidingBase shown, but Bar has actually a different CollidingBase supertype:

  "components": {
    "schemas": {
      "CollidingBase": {
        "required": [
          "fooBase"
        ],
        "type": "object",
        "properties": {
          "fooBase": {
            "type": "string"
          }
        }
      },
      "Bar": {
        "required": [
          "bar",
          "barBase"
        ],
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/CollidingBase"
          },
          {
            "type": "object",
            "properties": {
              "bar": {
                "type": "string"
              }
            }
          }
        ]
      },

Versions:
io.swagger.core.v3 » swagger-core-jakarta 2.2.21 via:
org.springdoc:springdoc-openapi-starter-webmvc-ui version 2.5.0
org.springframework.boot version "3.3.0"

Example repository here: https://github.com/tbvh/springdoc-collision-demo (the full spec output is included in the repository)

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

1 participant