Skip to content

Implement allOf/anyOf/oneOf#1775

Draft
joelittlejohn wants to merge 1 commit intomasterfrom
allof-anyof-oneof
Draft

Implement allOf/anyOf/oneOf#1775
joelittlejohn wants to merge 1 commit intomasterfrom
allof-anyof-oneof

Conversation

@joelittlejohn
Copy link
Copy Markdown
Owner

This is a vision for allOf/anyOf/oneOf that I've been thinking about for many years. The approach is simple but will hopefully support a very large percentage of use-cases for these keywords.

  • allOf: All schemas are merged together to create a superset of schema rules.
  • anyOf / oneOf: We generate each individual subtype, then create a 'marker' interface which all types implement. When working with types, users may have to rely on type checks and casts, but since Java has no union type (and adding intervening types is ugly) I think this is reasonable.

To achieve polymorphic deserialisation, there's a new 'discriminator' keyword, similar to OpenAPI's discriminator keyword, to specify the JSON property that will indicate the type name.

This PR is not complete, but it shows where I think we'll go.

- Add support for allOf, which merges all rules together
- Add support for anyOf/oneOf, which implement subtypes and a 'marker'
  interface that all subtypes will implement
- Add support for a new 'discriminator' schema property that can be used
  to specify a property that will hold the type name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant