You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the JSON Schema seems only to allow rear optional items through additionalItems.
Is it possible to allow positional optional items?
Such as this imaginary schema:
{"type": "array","items": [{// user must provide a nickname"type": "string"},{// the age is personal, so it is OPTIONAL// "optional": true,"type": "number"},{// user must provide a email"type": "string"}]}
Given the above imaginary schema, the following values are both valid: ['Tom', 30, '[email protected]']: Tom provides all, including the optional age. ['Alice', '[email protected]']: Alice does not provide the optional age.
Of course, the schema author must ensure the mutually exclusive between the positional-optional item and the following item. In the example above, the positional-optional age's type is number, the email's type is string, they are mutually exclusive, so the schema is unambiguous.
The text was updated successfully, but these errors were encountered:
positions in a json schema items array are fixed to the corresponding numeric index, so you'll need different schemas for different permutations of the indices. something like (yaml):
that should use $refs to avoid duplication, but even still, it would rapidly get out of hand if you have multiple optional elements. arrays where elements can appear at varying indices are not a kind of structure that json-schema is all that well-suited to describe.
This is the kind of complex edge case keyword that a few people need but most people do not, that is great for implementing as a (3rd-party) extension keyword. So I'm transferring it to our repository that holds those sorts of ideas.
handrews
transferred this issue from json-schema-org/json-schema-spec
Apr 25, 2020
Currently, the JSON Schema seems only to allow rear optional items through
additionalItems
.Is it possible to allow positional optional items?
Such as this imaginary schema:
Given the above imaginary schema, the following values are both valid:
['Tom', 30, '[email protected]']
: Tom provides all, including the optionalage
.['Alice', '[email protected]']
: Alice does not provide the optionalage
.Of course, the schema author must ensure the mutually exclusive between the positional-optional item and the following item. In the example above, the positional-optional
age
's type isnumber
, theemail
's type isstring
, they are mutually exclusive, so the schema is unambiguous.The text was updated successfully, but these errors were encountered: