Skip to content

Commit 17ad94f

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 17ad94f

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

jsonschema-validation.xml

+46-32
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">

0 commit comments

Comments
 (0)