swagger-api / swagger-api/swagger-core

Cyclic dependency with common base type swallows attributes

Open
#4,666 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.