swagger-api / swagger-api/swagger-core
Cyclic dependency with common base type swallows attributes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
Hello,
I recently discovered a bug in Swagger-Core affecting object property resolution. As far as I could debug, it is related to a short circuit in object traversal to prevent StackOverflows - see ModelResolver:394. I could obersve the problem for two objects with a cyclic dependency on each other, whilst sharing a common base type and forcing the OpenAPI generator to traverse the object tree in a specific order using the allOf attribute.
I was able to provide a minimal reproduction in this repository: https://github.com/drakenfly/swagger-inheritance-bug
Performing a mvn clean install in the root of the project will generate an OpenAPI spec in api/target/generatedtest/openapi.[json|yaml].
This spec contains an object called PortfolioViewDto that should contain a list of DepotViewDto, which is missing. Navigating to api/src/main/java/rest/TestEndpoint.java and uncommenting the additional methods (and importing the DTOs of course) will lead to a correct generation of the spec file, as the order of traversal changes with the additional methods.
Is anybody here able to help?
Kind regards
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 the minimal reproduction repository and run mvn clean install to generate api/target/generatedtest/openapi.[json|yaml]. Inspect the object traversal short circuit at ModelResolver:394 and compare the spec with and without the additional methods in api/src/main/java/rest/TestEndpoint.java. Done means PortfolioViewDto contains its expected list of DepotViewDto without relying on traversal order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100