-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Sometimes there's the need to express variant of a schema that apply under certain conditions.
Such variant may
A. only change the representation of the schema (e.g. display/hide fields, change labels, etc.)
B. actually change the schema (e.g. add fields or make additional fields mandatory)
JSON-SCHEMA provides the following options:
- >= Draft 7 Draft 2019-09:
- < Draft 2019-09
- > Draft 7:
- < Draft 7:
oneOf: https://json-schema.org/understanding-json-schema/reference/combining#oneOf- in general needs a
discriminator, see also: Proposal: Add propertyDependencies keyword (aka discriminator) json-schema-org/json-schema-spec#1082
- in general needs a
Limitations of JSON-SCHEMA based tools:
- https://github.com/json-editor/json-editor
- supports
dependencies,if-then-else, andoneOf if-then-elsesupport is limited, especially regarding UI modifications (see if-then-else not working in allOf json-editor/json-editor#1440, if-then-else doesn't apply dynamically (at least to nested properties) json-editor/json-editor#1434)
- supports
- https://github.com/koxudaxi/datamodel-code-generator
- supports only
oneOf
- supports only
Current recommendation is to use oneOf for both cases A and B. Once bugs in https://github.com/json-editor/json-editor are fixed, if-then-else is recommended for cases A
Metadata
Metadata
Assignees
Labels
No labels