swagger-api / swagger-api/swagger-core
[Bug]: Polymorphic types don't include composite schema reference
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
Description of the problem/issue
This project illustrates the problem. When having polymorphic types and using the swagger-gradle-plugin to generate the OpenAPI descriptor file, subtypes are missing the combined schema reference (allOf) to the parent type.
This is the current output in 2.2.41:
"DateAttributeTypeImpl" : {
"type" : "object",
"properties" : { }
}
And this was the expected output in 2.2.40:
"DateAttributeTypeImpl" : {
"type" : "object",
"allOf" : [ {
"$ref" : "#/components/schemas/AttributeType"
} ]
}
I debugged and the first pass of the model resolver for the parent type populates the reference correctly, however the model is redefined here and the reference is lost. I don't know enough of the model resolution to isolate a fix.
I suspect it might be a regression introduced while resolving https://github.com/swagger-api/swagger-core/issues/5003
Affected Version
2.2.41
Earliest version the bug appears in (if known):
2.2.41
Steps to Reproduce
Expand the project attached and execute:
./gradlew clean resolve
In order to compare the differences between 2.2.41 and 2.2.40, modify the gradle script to downgrade the dependency to swagger-core.
Expected Behavior
Subtypes should include a composite schema to the parent type like so
"DateAttributeTypeImpl" : {
"type" : "object",
"allOf" : [ {
"$ref" : "#/components/schemas/AttributeType"
} ]
}
Actual Behavior
Subtypes are created as independent models with no reference to the parent:
"DateAttributeTypeImpl" : {
"type" : "object",
"properties" : { }
}
Logs / Stack Traces
none
Additional Context
Checklist
- I have searched the existing issues and this is not a duplicate.
- I have provided sufficient information for maintainers to reproduce the issue.
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
Start with ModelResolver.java around line 1133 and reproduce the regression using the attached project with ./gradlew clean resolve. Compare swagger-core 2.2.41 with 2.2.40 and trace where the parent reference is lost during model redefinition. Done means polymorphic subtypes such as DateAttributeTypeImpl again contain an allOf reference to AttributeType.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100