jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.68k stars 199 forks source link

OpenApi Circular reference generation #3451

Closed tpoll closed 4 weeks ago

tpoll commented 4 weeks ago

I have some objects in my jooby API that leverage jackson's polymorphic deserialization. At a high level a simple example is as follows:

resource: https://github.com/tpoll/jooby-example/blob/main/Api1/src/main/java/com/example/api1/resources/Resource1.java#L13 models: https://github.com/tpoll/jooby-example/blob/main/Api1/src/main/java/com/example/api1/models/Pet.java

The generated openApi look like:

https://gist.github.com/tpoll/0fdc4cfcfa59945c0ee1fabcf573f6c2#file-openapi-json-L69

One challenge I've been running into is that the open api generated uses allOf to point my cat object back the the underlying pet object. While some renders like redocly seems to handle it okay, I haven't been able to find other parsers that are able to understand these sort of back references. It seems like most other renderers want oneOf instead of allOf. Basically a structure where the pet schema in openAPI case oneOf [ref->cat, ref->pet]. If I add manual oneOf annotations via swagger, I still have issues with circular references because of allOf back references.

Is there any context on why the structure with allOf was used? It looks like it's used to get the properties from the underlying interface on to the extending object, but it seems conceptually like it's not what openAPI expects. An instance of a request can only have oneOf the implementing classes at any time.

tpoll commented 4 weeks ago

I realize this is a bit tricky to follow. I'll open up an example PR in jooby + a test to show what I'm looking for.

tpoll commented 4 weeks ago

Did some deeper digging here and realized that there is something weird going on, but I think it's just from the swagger parser itself. It doesn't seem to be handling nested interfaces well. I don't think there's anything to do in jooby here.