From 32cabecf8334f2260d1578bb4770ea4f9bdd32ae Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Tue, 15 Nov 2016 12:17:07 -0800 Subject: [PATCH] Add general validation principles and examples. This paritally addresses issue #55 plus concerns raised in the comments of issue #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. --- jsonschema-validation.xml | 80 +++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/jsonschema-validation.xml b/jsonschema-validation.xml index 1c3aa1c0..95529481 100644 --- a/jsonschema-validation.xml +++ b/jsonschema-validation.xml @@ -158,55 +158,69 @@
-
+
- Most validation keywords only limit the range of values within a certain primitive type. - When the primitive type of the instance is not of the type targeted by the keyword, the - validation succeeds. + Each JSON Schema validation keyword adds constraints that + an instance must satisfy in order to successfully validate. - For example, the "maxLength" keyword will only restrict certain strings (that are too long) from being valid. - If the instance is a number, boolean, null, array, or object, the keyword passes validation. - + Validation keywords that are missing never restrict validation. + In some cases, this no-op behavior is identical to a keyword that + exists with certain values, and these values are noted where relevant. + +
+ + From this principle, it follows that all JSON values + successfully validate against the empty schema: + + + + +
+
+ + Similarly, it follows that no JSON value successfully + validates against the empty schema's negation: + + + + +
-
- - Two of the primitive types, array and object, allow for child values. The validation of - the primitive type is considered separately from the validation of child instances. - +
- For arrays, primitive type validation consists of validating restrictions on length. + Validation keywords typically operate independently, without + affecting each other's outcomes. - For objects, primitive type validation consists of validating restrictions on the presence - or absence of property names. - -
- -
- - Validation keywords that are missing never restrict validation. - In some cases, this no-op behavior is identical to a keyword that exists with certain values, - and these values are noted where known. + For schema author convenience, there are some exceptions: + + "additionalProperties", whose behavior is defined in terms of "properties" and "patternProperties" + "additionalItems", whose behavior is defined in terms of "items" + "minimum" and "maximum", whose behavior may change for a special value of "exclusiveMinimum" and "exclusiveMaximum", respectively + +
-
- +
- Validation keywords typically operate independent of each other, without affecting each other. + Most validation keywords only limit the range of values within a certain primitive type. + When the primitive type of the instance is not of the type targeted by the keyword, the + validation succeeds. - For author convenience, there are some exceptions: - - "additionalProperties", whose behavior is defined in terms of "properties" and "patternProperties"; - "additionalItems", whose behavior is defined in terms of "items"; and - "minimum" and "maximum", whose behavior may change for a special value of "exclusiveMinimum" and "exclusiveMaximum", respectively. - + For example, the "maxLength" keyword will only restrict certain strings (that are too long) from being valid. + If the instance is a number, boolean, null, array, or object, the keyword passes validation.
-