jsonschema-generator icon indicating copy to clipboard operation
jsonschema-generator copied to clipboard

Support subtype look-up per field/method

Open CarstenEnglert opened this issue 6 years ago • 3 comments

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 Animal supertype that has various implementations (such as Dog, Cat, Elephant, Boar) on a field called "pet", maybe only Dog and Cat are 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 @JsonSubTypes annotation. (#55 + #58 and released in v4.8.0)

CarstenEnglert avatar Mar 14 '20 12:03 CarstenEnglert

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

JanLabrie avatar Mar 17 '20 10:03 JanLabrie

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.

CarstenEnglert avatar Mar 17 '20 20:03 CarstenEnglert

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).

CarstenEnglert avatar Mar 30 '20 12:03 CarstenEnglert