|
125 | 125 | <section title="Keyword Behaviors">
|
126 | 126 | <t>
|
127 | 127 | JSON Schema keywords fall into several general behavior categories.
|
128 |
| - Assertions validate that an instance satisfies constraints. Annotations |
129 |
| - attach information that applications may use in any way they see fit. |
| 128 | + Assertions validate that an instance satisfies constraints, producing |
| 129 | + a boolean result. Annotations attach information that applications |
| 130 | + may use in any way they see fit. |
130 | 131 | Applicators apply subschemas to parts of the instance and combine
|
131 | 132 | their results.
|
132 | 133 | </t>
|
|
144 | 145 | subschemas have been evaluated, although in some circumstance evaluation
|
145 | 146 | may be short-circuited due to assertion results.
|
146 | 147 | </t>
|
| 148 | + <t> |
| 149 | + Keyword behavior MAY be defined in terms of the annotation results |
| 150 | + of <xref target="root">subschemas</xref> and/or adjacent keywords. |
| 151 | + Such keywords MUST NOT result in a circular dependency. |
| 152 | + Keywords MAY modify their behavior based on the presence or absence |
| 153 | + of another keyword in the same |
| 154 | + <xref target="schema-document">schema object</xref>. |
| 155 | + </t> |
| 156 | + <t> |
| 157 | + A missing keyword MUST NOT produce a false assertion result, MUST |
| 158 | + NOT produce annotation results, and MUST NOT cause any other schema |
| 159 | + to be evaluated as part of its own behavioral definition. |
| 160 | + However, given that missing keywords do not contribute annotations, |
| 161 | + the lack of annotation results may indirectly change the behavior |
| 162 | + of other keywords. |
| 163 | + </t> |
| 164 | + <t> |
| 165 | + In some cases, the missing keyword assertion behavior of a keyword is |
| 166 | + identical to that produced by a certain value, and keyword definitions |
| 167 | + SHOULD note such values where known. However, even if the value which |
| 168 | + produces the default behavior would produce annotation results if |
| 169 | + present, the default behavior still MUST NOT result in annotations. |
| 170 | + </t> |
| 171 | + <t> |
| 172 | + Because annotation collection can add significant cost in terms of both |
| 173 | + computation and memory, implementations MAY opt out of this feature. |
| 174 | + Keywords known to an implementation to have assertion or applicator behavior |
| 175 | + that depend on annotation results MUST then be treated as errors, unless |
| 176 | + an alternate implementation producing the same behavior is available. |
| 177 | + Keywords of this sort SHOULD describe reasonable alternate approaches |
| 178 | + when appropriate. This approach is demonstrated by the |
| 179 | + "<xref target="additionalItems" format="title"/>" and |
| 180 | + "<xref target="additionalProperties" format="title"/>" keywords in this |
| 181 | + document. |
| 182 | + </t> |
147 | 183 | <t>
|
148 | 184 | Extension keywords SHOULD stay within these categories, keeping in mind
|
149 | 185 | that annotations in particular are extremely flexible. Complex behavior
|
|
189 | 225 | </t>
|
190 | 226 | <t>
|
191 | 227 | An instance can only fail an assertion that is present in the schema.
|
192 |
| - In some cases, this no-op behavior is identical to a keyword that exists with |
193 |
| - certain values, and keyword definitions SHOULD note such values where known. |
194 |
| - These default behaviors MUST NOT result in assertion failures. |
| 228 | + |
195 | 229 | </t>
|
196 | 230 | <section title="Assertions and Instance Primitive Types">
|
197 | 231 | <t>
|
|
1243 | 1277 | <section title="Keywords for Applying Subschemas to Arrays">
|
1244 | 1278 | <section title="items">
|
1245 | 1279 | <t>
|
1246 |
| - The value of "items" MUST be either a valid JSON Schema or an array of valid |
1247 |
| - JSON Schemas. |
1248 |
| - </t> |
1249 |
| - <t> |
1250 |
| - This keyword determines how child instances validate for arrays, |
1251 |
| - and does not directly validate the immediate instance itself. |
| 1280 | + The value of "items" MUST be either a valid JSON Schema or |
| 1281 | + an array of valid JSON Schemas. |
1252 | 1282 | </t>
|
1253 | 1283 | <t>
|
1254 | 1284 | If "items" is a schema, validation succeeds if all elements
|
|
1260 | 1290 | same position, if any.
|
1261 | 1291 | </t>
|
1262 | 1292 | <t>
|
1263 |
| - Omitting this keyword has the same behavior as an empty schema. |
| 1293 | + This keyword produces an annotation value which is the largest |
| 1294 | + index to which this keyword applied a subschema. The value |
| 1295 | + MAY be a boolean true if a subschema was applied to every |
| 1296 | + index of the instance, such as when "items" is a schema. |
| 1297 | + </t> |
| 1298 | + <t> |
| 1299 | + Annotation results for "items" keywords from multiple |
| 1300 | + schemas applied to the same instance location are combined |
| 1301 | + by setting the combined result to true if any of the values |
| 1302 | + are true, and otherwise retaining the largest numerical value. |
| 1303 | + </t> |
| 1304 | + <t> |
| 1305 | + Omitting this keyword has the same assertion behavior as |
| 1306 | + an empty schema. |
1264 | 1307 | </t>
|
1265 | 1308 | </section>
|
1266 | 1309 |
|
1267 |
| - <section title="additionalItems"> |
| 1310 | + <section title="additionalItems" anchor="additionalItems"> |
1268 | 1311 | <t>
|
1269 | 1312 | The value of "additionalItems" MUST be a valid JSON Schema.
|
1270 | 1313 | </t>
|
1271 | 1314 | <t>
|
1272 |
| - This keyword determines how child instances validate for arrays, |
1273 |
| - and does not directly validate the immediate instance itself. |
| 1315 | + The behavior of this keyword depends on the presence and |
| 1316 | + annotation result of "items" within the same schema object. |
| 1317 | + If "items" is present, and its annotation result is a number, |
| 1318 | + validation succeeds if every instance element at an index |
| 1319 | + greater than that number validates against "additionalItems". |
1274 | 1320 | </t>
|
1275 | 1321 | <t>
|
1276 |
| - If "items" is an array of schemas, validation succeeds |
1277 |
| - if every instance element at a position greater than the size |
1278 |
| - of "items" validates against "additionalItems". |
| 1322 | + Otherwise, if "items" is absent or its annotation result |
| 1323 | + is the boolean true, "additionalItems" MUST be ignored. |
1279 | 1324 | </t>
|
1280 | 1325 | <t>
|
1281 |
| - Otherwise, "additionalItems" MUST be ignored, as the "items" |
1282 |
| - schema (possibly the default value of an empty schema) is |
1283 |
| - applied to all elements. |
| 1326 | + If the "additionalItems" subschema is applied to any |
| 1327 | + positions within the instance array, it produces an |
| 1328 | + annotation result of boolean true, analogous to the |
| 1329 | + single schema behavior of "items". If any "additionalItems" |
| 1330 | + keyword from any subschema applied to the same instance |
| 1331 | + location produces an annotation value of true, then |
| 1332 | + the combined result from these keywords is also true. |
1284 | 1333 | </t>
|
1285 | 1334 | <t>
|
1286 |
| - Omitting this keyword has the same behavior as an empty schema. |
| 1335 | + Omitting this keyword has the same assertion behavior as |
| 1336 | + an empty schema. |
| 1337 | + </t> |
| 1338 | + <t> |
| 1339 | + Implementations MAY choose to implement or optimize this keyword |
| 1340 | + in another way that produces the same effect, such as by directly |
| 1341 | + checking for the presence and size of an "items" array. |
| 1342 | + Implementations that do not support annotation collection MUST do so. |
1287 | 1343 | </t>
|
1288 | 1344 | </section>
|
1289 | 1345 |
|
|
1293 | 1349 | </t>
|
1294 | 1350 | <t>
|
1295 | 1351 | An array instance is valid against "contains" if at least one of
|
1296 |
| - its elements is valid against the given schema. |
| 1352 | + its elements is valid against the given schema. This keyword |
| 1353 | + does not produce annotation results. |
| 1354 | + <cref> |
| 1355 | + Should it produce a set of the indices for which the |
| 1356 | + array element is valid against the subschema? "contains" |
| 1357 | + does not affect "additionalItems" or any other current |
| 1358 | + or proposed keyword, but the information could be useful, |
| 1359 | + and implementation that collect annotations need to |
| 1360 | + apply "contains" to every element anyway. |
| 1361 | + </cref> |
1297 | 1362 | </t>
|
1298 | 1363 | </section>
|
1299 | 1364 | </section>
|
|
1304 | 1369 | The value of "properties" MUST be an object.
|
1305 | 1370 | Each value of this object MUST be a valid JSON Schema.
|
1306 | 1371 | </t>
|
1307 |
| - <t> |
1308 |
| - This keyword determines how child instances validate for objects, |
1309 |
| - and does not directly validate the immediate instance itself. |
1310 |
| - </t> |
1311 | 1372 | <t>
|
1312 | 1373 | Validation succeeds if, for each name that appears in both
|
1313 | 1374 | the instance and as a name within this keyword's value, the child
|
1314 | 1375 | instance for that name successfully validates against the
|
1315 | 1376 | corresponding schema.
|
1316 | 1377 | </t>
|
1317 | 1378 | <t>
|
1318 |
| - Omitting this keyword has the same behavior as an empty object. |
| 1379 | + The annotation result of this keyword is the set of instance |
| 1380 | + property names matched by this keyword. Annotation results |
| 1381 | + for "properties" keywords from multiple schemas applied to |
| 1382 | + the same instance location are combined by taking the union |
| 1383 | + of the sets. |
| 1384 | + </t> |
| 1385 | + <t> |
| 1386 | + Omitting this keyword has the same assertion behavior as |
| 1387 | + an empty object. |
1319 | 1388 | </t>
|
1320 | 1389 | </section>
|
1321 | 1390 |
|
|
1326 | 1395 | ECMA 262 regular expression dialect. Each property value of this object
|
1327 | 1396 | MUST be a valid JSON Schema.
|
1328 | 1397 | </t>
|
1329 |
| - <t> |
1330 |
| - This keyword determines how child instances validate for objects, |
1331 |
| - and does not directly validate the immediate instance itself. |
1332 |
| - Validation of the primitive instance type against this keyword |
1333 |
| - always succeeds. |
1334 |
| - </t> |
1335 | 1398 | <t>
|
1336 | 1399 | Validation succeeds if, for each instance name that matches any
|
1337 | 1400 | regular expressions that appear as a property name in this keyword's value,
|
1338 | 1401 | the child instance for that name successfully validates against each
|
1339 | 1402 | schema that corresponds to a matching regular expression.
|
1340 | 1403 | </t>
|
1341 | 1404 | <t>
|
1342 |
| - Omitting this keyword has the same behavior as an empty object. |
| 1405 | + The annotation result of this keyword is the set of instance |
| 1406 | + property names matched by this keyword. Annotation results |
| 1407 | + for "patternProperties" keywords from multiple schemas applied to |
| 1408 | + the same instance location are combined by taking the union |
| 1409 | + of the sets. |
| 1410 | + </t> |
| 1411 | + <t> |
| 1412 | + Omitting this keyword has the same assertion behavior as |
| 1413 | + an empty object. |
1343 | 1414 | </t>
|
1344 | 1415 | </section>
|
1345 | 1416 |
|
1346 |
| - <section title="additionalProperties"> |
| 1417 | + <section title="additionalProperties" anchor="additionalProperties"> |
1347 | 1418 | <t>
|
1348 | 1419 | The value of "additionalProperties" MUST be a valid JSON Schema.
|
1349 | 1420 | </t>
|
1350 | 1421 | <t>
|
1351 |
| - This keyword determines how child instances validate for objects, |
1352 |
| - and does not directly validate the immediate instance itself. |
1353 |
| - </t> |
1354 |
| - <t> |
| 1422 | + The behavior of this keyword depends on the presence and |
| 1423 | + annotation results of "properties" and "patternProperties" |
| 1424 | + within the same schema object. |
1355 | 1425 | Validation with "additionalProperties" applies only to the child
|
1356 |
| - values of instance names that do not match any names in "properties", |
1357 |
| - and do not match any regular expression in "patternProperties". |
| 1426 | + values of instance names that do not appear in the annotation |
| 1427 | + results of either "properties" or "patternProperties". |
1358 | 1428 | </t>
|
1359 | 1429 | <t>
|
1360 | 1430 | For all such properties, validation succeeds if the child instance
|
1361 | 1431 | validates against the "additionalProperties" schema.
|
1362 | 1432 | </t>
|
1363 | 1433 | <t>
|
1364 |
| - Omitting this keyword has the same behavior as an empty schema. |
| 1434 | + The annotation result of this keyword is the set of instance |
| 1435 | + property names validated by this keyword's subschema. |
| 1436 | + Annotation results for "additionalProperties" keywords from |
| 1437 | + multiple schemas applied to the same instance location are combined |
| 1438 | + by taking the union of the sets. |
| 1439 | + </t> |
| 1440 | + <t> |
| 1441 | + Omitting this keyword has the same assertion behavior as |
| 1442 | + an empty schema. |
| 1443 | + </t> |
| 1444 | + <t> |
| 1445 | + Implementation MAY choose to implement or optimize this keyword |
| 1446 | + in another way that produces the same effect, such as by directly |
| 1447 | + checking the names in "properties" and the patterns in |
| 1448 | + "patternProperties" against the instance property set. |
| 1449 | + Implementations that do not support annotation collection MUST do so. |
1365 | 1450 | </t>
|
1366 | 1451 | </section>
|
1367 | 1452 |
|
|
0 commit comments