swagger-api / swagger-api/swagger-core
Name collision in api spec possible for colliding supertype names
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the collision using the example repository linked in the issue and inspect its generated OpenAPI spec, especially the conflicting CollidingBase references and allOf sections. The work is done when swagger-core raises an error for colliding supertype names instead of emitting an incorrect specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100