swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Cyclic dependency with common base type swallows attributes

Open drakenfly opened this issue 1 year ago • 1 comments

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

drakenfly avatar May 06 '24 07:05 drakenfly

Try to use Micronaut OpenAPI - https://github.com/micronaut-projects/micronaut-openapi.

I see, you use jax-rs, to use micrnaut-openapi you need to add mapping jax-rs to micronaut annotation library. Because, micronaut-openapi is an annotation processor, you don't need to use micronaut as a framework, use it only to construct spec file

altro3 avatar Sep 01 '24 09:09 altro3