Skip to content

Commit d9ee9e9

Browse files
authored
Merge pull request #375 from handrews/if
Specify "if", "then", and "else"
2 parents 0f22800 + ddb3a99 commit d9ee9e9

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

hyper-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
"properties": {
9393
"additionalProperties": { "$ref": "#" }
9494
},
95+
"if": {"$ref": "#"},
96+
"then": {"$ref": "#"},
97+
"else": {"$ref": "#"},
9598
"allOf": { "$ref": "#/definitions/schemaArray" },
9699
"anyOf": { "$ref": "#/definitions/schemaArray" },
97100
"oneOf": { "$ref": "#/definitions/schemaArray" },

jsonschema-hyperschema.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@
218218
<t>
219219
Hyper-schemas MUST NOT be applied to an instance if the instance fails to
220220
validate against the validation keywords within or containing the hyper-schema.
221-
Hyper-schema keywords in branches of an "anyOf" or "oneOf" that do not validate,
222-
or in a "dependencies" subschema that is not relevant to the instance, MUST be
223-
ignored.
221+
Hyper-schema keywords in branches of an "anyOf", "oneOf", or "if"/"then"/"else"
222+
that do not validate, or in a "dependencies" subschema that is not relevant
223+
to the instance, MUST be ignored.
224224
</t>
225225
<t>
226226
Hyper-schema keywords in a subschema contained within a "not", at any depth,

jsonschema-validation.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,78 @@
635635
</section>
636636
</section>
637637

638+
<section title="Keywords for applying subschemas conditionally">
639+
<t>
640+
These keywords work together to implement conditional
641+
application of a subschema based on the outcome of
642+
another subschema.
643+
</t>
644+
<t>
645+
These keywords MUST NOT interact with each other across
646+
subschema boundaries. In other words, an "if" in one
647+
branch of an "allOf" MUST NOT have an impact on a "then"
648+
or "else" in another branch.
649+
</t>
650+
<section title="if">
651+
<t>
652+
This keyword's value MUST be a valid JSON Schema.
653+
</t>
654+
<t>
655+
Instances that successfully validate against this
656+
keyword's subschema MUST also be valid against
657+
the subschema value of the "then" keyword, if
658+
present.
659+
</t>
660+
<t>
661+
Instances that fail to validate against this
662+
keyword's subschema MUST also be valid against
663+
the subschema value of the "else" keyword.
664+
</t>
665+
<t>
666+
Validation of the instance against this keyword
667+
on its own always succeeds, regardless of the
668+
validation outcome of against its subschema.
669+
</t>
670+
</section>
671+
<section title="then">
672+
<t>
673+
This keyword's value MUST be a valid JSON Schema.
674+
</t>
675+
<t>
676+
When present alongside of "if", the instance
677+
successfully validates against this keyword if
678+
it validates against both the "if"'s subschema
679+
and this keyword's subschema.
680+
</t>
681+
<t>
682+
When "if" is absent, or the instance fails to
683+
validate against its subschema, validation against
684+
this keyword always succeeds. Implementations
685+
SHOULD avoid attempting to validate against
686+
the subschema in these cases.
687+
</t>
688+
</section>
689+
<section title="else">
690+
<t>
691+
This keyword's value MUST be a valid JSON Schema.
692+
</t>
693+
<t>
694+
When present alongside of "if", the instance
695+
successfully validates against this keyword if
696+
it fails to validate against the "if"'s
697+
subschema, and successfully validates against
698+
this keyword's subschema.
699+
</t>
700+
<t>
701+
When "if" is absent, or the instance successfully
702+
validates against its subschema, validation against
703+
this keyword always succeeds. Implementations
704+
SHOULD avoid attempting to validate against
705+
the subschema in these cases.
706+
</t>
707+
</section>
708+
</section>
709+
638710
<section title="Keywords for applying subschemas with boolean logic">
639711
<section title="allOf">
640712
<t>

schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
]
149149
},
150150
"format": { "type": "string" },
151+
"if": {"$ref": "#"},
152+
"then": {"$ref": "#"},
153+
"else": {"$ref": "#"},
151154
"allOf": { "$ref": "#/definitions/schemaArray" },
152155
"anyOf": { "$ref": "#/definitions/schemaArray" },
153156
"oneOf": { "$ref": "#/definitions/schemaArray" },

0 commit comments

Comments
 (0)