Skip to content

Commit f28a7f6

Browse files
committed
Add general validation principles and examples.
This paritally addresses issue json-schema-org#55 plus concerns raised in the comments of issue json-schema-org#101. I replaced "linearity" with "independence" as I think it is more general and intuitive. The general considerations section has been reorganized to start with the behavior of the empty schema, then explain keyword independence, and finally cover type applicability. In draft 04, the wording obscured the connection between keyword independence and container/child independence. I thought I needed this primitive type vs child validation section even with the rewritten keywords, but going over it now based on feedback, I agree that it is superfluous. The list of non-independent keywords has been updated to include minimum/maximum and their "exclusive" booleans.
1 parent b5afae7 commit f28a7f6

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

jsonschema-validation.xml

+50-36
Original file line numberDiff line numberDiff line change
@@ -156,54 +156,68 @@
156156

157157
<section title="General validation considerations">
158158

159-
<section title="Keywords and instance primitive types">
159+
<section title="Constraints and missing keywords">
160160
<t>
161-
Most validation keywords only limit the range of values within a certain primitive type.
162-
When the primitive type of the instance is not of the type targeted by the keyword, the
163-
validation succeeds.
161+
Each JSON Schema validation keyword adds constraints that
162+
an instance must satisfy in order to successfully validate.
164163
</t>
165164
<t>
166-
For example, the "maxLength" keyword will only restrict certain strings (that are too long) from being valid.
167-
If the instance is a number, boolean, null, array, or object, the keyword passes validation.
168-
</t>
165+
Validation keywords that are missing never restrict validation.
166+
In some cases, this no-op behavior is identical to a keyword that
167+
exists with certain values, and these values are noted where relevant.
168+
</t>
169+
<figure>
170+
<preamble>
171+
From this principle, it follows that all JSON values
172+
successfully validate against the empty schema:
173+
</preamble>
174+
<artwork>
175+
<![CDATA[
176+
{}
177+
]]>
178+
</artwork>
179+
</figure>
180+
<figure>
181+
<preamble>
182+
Similarly, it follows that no JSON value successfully
183+
validates against the empty schema's negation:
184+
</preamble>
185+
<artwork>
186+
<![CDATA[
187+
{
188+
"not": {}
189+
}
190+
]]>
191+
</artwork>
192+
</figure>
169193
</section>
170194

171-
<section title="Validation of primitive types and child values">
172-
<t>
173-
Two of the primitive types, array and object, allow for child values. The validation of
174-
the primitive type is considered separately from the validation of child instances.
175-
</t>
176-
<t>
177-
For arrays, primitive type validation consists of validating restrictions on length.
178-
</t>
195+
<section title="Keyword independence">
179196
<t>
180-
For objects, primitive type validation consists of validating restrictions on the presence
181-
or absence of property names.
197+
Validation keywords typically operate independently, without
198+
affecting each other's outcomes.
182199
</t>
183-
</section>
184-
185-
<section title="Missing keywords">
186200
<t>
187-
Validation keywords that are missing never restrict validation.
188-
In some cases, this no-op behavior is identical to a keyword that exists with certain values,
189-
and these values are noted where known.
201+
For schema author convenience, there are some exceptions:
202+
<list>
203+
<t>"additionalProperties", whose behavior is defined in terms of "properties" and "patternProperties"</t>
204+
<t>"additionalItems", whose behavior is defined in terms of "items"</t>
205+
<t>"minimum" and "maximum", whose behaviors are modified by "exclusiveMinimum" and "exclusiveMaximum", respectively</t>
206+
</list>
190207
</t>
191208
</section>
192209

193-
<section title="Linearity">
194-
<!-- I call this "linear" in the same manner e.g. waves are linear, they don't interact with each other -->
210+
<section title="Keywords and instance primitive types">
195211
<t>
196-
Validation keywords typically operate independent of each other, without affecting each other.
212+
Most validation keywords only limit the range of values within a certain primitive type.
213+
When the primitive type of the instance is not of the type targeted by the keyword, the
214+
validation succeeds.
197215
</t>
198216
<t>
199-
For author convienence, there are some exceptions:
200-
<list>
201-
<t>"additionalProperties", whose behavior is defined in terms of "properties" and "patternProperties"; and</t>
202-
<t>"additionalItems", whose behavior is defined in terms of "items"</t>
203-
</list>
217+
For example, the "maxLength" keyword will only restrict certain strings (that are too long) from being valid.
218+
If the instance is a number, boolean, null, array, or object, the keyword passes validation.
204219
</t>
205220
</section>
206-
207221
</section>
208222

209223
<section title="Validation keywords">
@@ -505,7 +519,7 @@
505519
</t>
506520
<t>
507521
For all such properties, child validation succeeds if the child instance
508-
validates agains the "additionalProperties" schema.
522+
validates against the "additionalProperties" schema.
509523
</t>
510524
</section>
511525

@@ -663,7 +677,7 @@
663677
<t>
664678
Both of these keywords can be used to decorate a user interface with
665679
information about the data produced by this user interface. A title will
666-
preferrably be short, whereas a description will provide explanation about
680+
preferably be short, whereas a description will provide explanation about
667681
the purpose of the instance described by this schema.
668682
</t>
669683
<t>
@@ -812,11 +826,11 @@
812826

813827
<section title="Security considerations">
814828
<t>
815-
JSON Schema validation defines a vocabulary for JSON Schema core and conserns all the security considerations listed there.
829+
JSON Schema validation defines a vocabulary for JSON Schema core and concerns all the security considerations listed there.
816830
</t>
817831
<t>
818832
JSON Schema validation allows the use of Regular Expressions, which have numerous different (often incompatible) implementations.
819-
Some implementations allow the embedding of arbritrary code, which is outside the scope of JSON Schema and MUST NOT be permitted.
833+
Some implementations allow the embedding of arbitrary code, which is outside the scope of JSON Schema and MUST NOT be permitted.
820834
Regular expressions can often also be crafted to be extremely expensive to compute (with so-called "catastrophic backtracking"),
821835
resulting in a denial-of-service attack.
822836
</t>

0 commit comments

Comments
 (0)