Closed as not planned
Description
I am opening this as an issue rather than a PR to start, in order to gather feedback and additional content.
There are a number of questions that are asked frequently on stackoverflow, slack, github issues etc that come down to "how do I express this pattern in JSON Schema?" Here are a few of them, and I'm sure we can come up with more:
-
"evaluate this subschema but do not collect annotations" (not so common but it has come up a few times, and it is weird enough that it deserves a mention IMO):
{ not: { not: { ... subschema ... } } }
-
add descriptions to a bunch of enum values, e.g. for form generation:
{
anyOf: [
{
"description": "...",
"const": "value0",
},
{
"description": "...",
"const": "value1",
},
...
]
}
- simulate OpenAPI's "discriminator":
{
allOf: [
{
if: {
type: object,
required: [ "foo" ],
properties: { foo: { const: "value0" } }
},
then: {
.. subschema when data has foo: value0
}
},
{
if: {
type: object,
required: [ "foo" ],
properties: { foo: { const: "value1" } }
},
then: {
.. subschema when data has foo: value1
}
},
{
if: {
type: object,
required: [ "bar" ],
properties: { bar: { const: "value0" } }
},
then: {
.. subschema when data has bar: value0
}
},
...
],
}