Support subtype look-up per field/method
GH-24 introduced the ability to determine specific subtypes of an encountered type in order to list them explicitly (via anyOf).
However, sometimes there are very generic type declarations which by convention are only ever populated with a few specific subtypes even though there are technically more. Some libraries (like Jackson) cater for the specific declaration of subtypes on a per-type basis as well as on a property (field/method) basis.
-
[x] The Schema Generator should allow for this per-property look-up of eligible subtypes, which should override the more general per-type look-up, e.g. when encountering an
Animalsupertype that has various implementations (such asDog,Cat,Elephant,Boar) on a field called "pet", maybe onlyDogandCatare eligible subtypes – hopefully, indicated in the code somehow. (#48 and released in v4.7.0) -
[x] Additionally, the jackson module could be enhanced to consider the
@JsonSubTypesannotation. (#55 + #58 and released in v4.8.0)
Hi Carsten,
I am doing a project in which a JSON Schema is generated as definition of an API. To do this I made a number of enhancements on the Generator and the Jackson/Addon modules. One of the things I did was what you mention "Additionally, the jackson module could be enhanced to consider the @JsonSubTypes annotation.".
Can we discuss this? Maybe on my gmail adress: jan.labrie@g.....
Regards,
Jan
Hi Jan,
I responded via email as you proposed regarding the issues with infinite loops when using createStandardDefinition().
Now I'd also be interested in the enhancements you've made. It seems to me, including some of them here might benefit others as well.
As of release v4.8.0, the main generator library supports this now and the jackson module does it by default (but can be disabled via JacksonOptions provided in its constructor if need be).