https://json-schema.org/understanding-json-schema/reference/combining#allOf
Pros:
- widely supported
- add new specific event per entity
- changes to the event schema apply to all events
Cons:
- validation will fail on any schemas where entities referenced in
allOf
haveadditionalProperties: false
Codegen support
- Quicktype - ❌
- json2ts - ✅
https://json-schema.org/understanding-json-schema/reference/combining#oneOf
Pros:
- widely supported
- only 1 file as entry point (dereferencing potentially simpler?)
- changes to the event schema apply to all events
Cons:
- can have an event with
entity_name=draft
andpayload=Property
- when adding new entities we have to modify the central event file
- when generating types we pull all entities even if interested in only few
Codegen support
- Quicktype - ❌
- json2ts - ✅
https://json-schema.org/blog/posts/dynamicref-and-generics
https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-00#rfc.section.8.2.3.2
https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-00#recursive-example
Pros:
- closely resembles generics
- add new specific event per entity
- changes to the event schema apply to all events
Cons:
- latest draft, support might be sketchy (support needs investigation)
- hard to read/understand
- codegen has to run against each specific event unless they are all collected in some kind of
root
schema
Codegen support
- Quicktype - ❌
- json2ts - ❌
Create a template-event
, this event then can be copy-pasted and certain attributes changed to get entity-specific event.
Pros:
- add new specific event per entity
Cons:
- changes to the base event require changes to all entity-specific events
- codegen has to run against each specific event unless they are all collected in some kind of
root
schema
Codegen support
- Quicktype - ✅
- json2ts - ✅
Pros:
- can convert to/from many languages, so using go in the futurte could potentially be covered
cons:
- merges subschemas when using
oneOf
, rather than using unions: GH Issue
Pros:
- Correctly handles union types
Cons:
- Issue with dereferencing, limiting how we structure schemas: GH Issue
- jsonschema - validate JSON against the schema