Skip to content

Commit 0bc8cde

Browse files
committed
More thorough rewrite of "if"/"then"/"else"
Further feedback indicates the language was still confusing. Rewrote it to be more explicit about how the keywords interact with each other and with both validation and annotation collection. In particular, an "if" on its own collects annotations but never affects validation, annotations are only collected from "them" or "else" if their use is indicated by the validation outcome of an adjacent "if", and there is no default behavior for any of the keywords. Technically, "then" could be assigned an empty schema default without causing problems, but that felt weirdly unbalanced. If "if" has a default of true/empty schema, then "then" on its own would be active, which is counter-intuitive. If "else" had a default it would need to be false rather than true, and saying it has no default seemed simpler, and matches how "not" is handled. "not" is the only other keyword that would otherwise need a false schema as a default value.
1 parent d924055 commit 0bc8cde

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

jsonschema-validation.xml

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,23 @@
746746
branch of an "allOf" MUST NOT have an impact on a "then"
747747
or "else" in another branch.
748748
</t>
749+
<t>
750+
There is no default behavior for any of these keywords
751+
when they are not present. In particular, they MUST NOT
752+
be treated as if present with an empty schema, and when
753+
"if" is not present, both "then" and "else" MUST be
754+
entirely ignored.
755+
</t>
749756
<section title="if">
750757
<t>
751758
This keyword's value MUST be a valid JSON Schema.
752759
</t>
760+
<t>
761+
This validation outcome of this keyword's subschema
762+
has no direct effect on the overall validation
763+
result. Rather, it controls which of the "then"
764+
or "else" keywords are evaluated.
765+
</t>
753766
<t>
754767
Instances that successfully validate against this
755768
keyword's subschema MUST also be valid against
@@ -763,48 +776,46 @@
763776
present.
764777
</t>
765778
<t>
766-
Validation of the instance against this keyword
767-
on its own always succeeds, regardless of the
768-
validation outcome of the instance against its subschema.
779+
If <xref target="annotations">annotations</xref>
780+
are being collected, they are collected from this
781+
keyword's subschema in the usual way, including when
782+
the keyword is present without either "then" or "else".
769783
</t>
770784
</section>
771785
<section title="then">
772786
<t>
773787
This keyword's value MUST be a valid JSON Schema.
774788
</t>
775789
<t>
776-
When present alongside of "if", the instance
777-
successfully validates against this keyword if
778-
it validates against both the "if"'s subschema
779-
and this keyword's subschema.
790+
When "if" is present, and the instance successfully
791+
validates against its subschema, then valiation
792+
succeeds against this keyword if the instance also
793+
successfully validates against this keyword's subschema.
780794
</t>
781795
<t>
782-
When "if" is absent, or the instance fails to
783-
validate against its subschema, validation against
784-
this keyword always succeeds, regardless of the
785-
validation outcome of the instance against its subschema.
786-
Implementations SHOULD avoid attempting to validate against
787-
the subschema in these cases.
796+
This keyword has no effect when "if" is absent, or
797+
when the instance fails to validate against its
798+
subschema. Implementations MUST NOT evaluate
799+
the instance against this keyword, for either validation
800+
or annotation collection purposes, in such cases.
788801
</t>
789802
</section>
790803
<section title="else">
791804
<t>
792805
This keyword's value MUST be a valid JSON Schema.
793806
</t>
794807
<t>
795-
When present alongside of "if", the instance
796-
successfully validates against this keyword if
797-
it fails to validate against the "if"'s
798-
subschema, and successfully validates against
799-
this keyword's subschema.
808+
When "if" is present, and the instance fails to
809+
validate against its subschema, then valiation
810+
succeeds against this keyword if the instance
811+
successfully validates against this keyword's subschema.
800812
</t>
801813
<t>
802-
When "if" is absent, or the instance successfully
803-
validates against its subschema, validation against
804-
this keyword always succeeds, regardless of the
805-
validation outcome of the instance against its subschema.
806-
Implementations SHOULD avoid attempting to validate against
807-
the subschema in these cases.
814+
This keyword has no effect when "if" is absent, or
815+
when the instance successfully validates against its
816+
subschema. Implementations MUST NOT evaluate
817+
the instance against this keyword, for either validation
818+
or annotation collection purposes, in such cases.
808819
</t>
809820
</section>
810821
</section>

0 commit comments

Comments
 (0)