"prefixItems" in draft v7 #535
-
Hello good guys, I have my own implementation of JSON schema validation programmed in JAVA. And so I came across the contained definition of "items" as a boolean: "examples": { Which I didn't understand at first, but now it seems like this has become an alias to the functionality like "additionalItems". Here an example schema from "https://json-schema.org/understanding-json-schema/reference/array#additionalitems": But here comes my question: "prefixItems" is not mentioned in "http://json-schema.org/draft-07/schema#" at all. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In previous versions, you can have the schema form {
"items": { "type": "object" }
} which requires that every item in the array is an object. You can also have the array form {
"items": [
{ "type": "object" }
]
} which only requires that the first item is an object, and you can add more subschemas to validate more items in sequence.
For 2020-12, we split the array form of So in previous drafts, you have {
"items": [
{ "type": "object" }
],
"additionalItems": { "type": "string" }
} but in 2020-12, you have {
"prefixItems": [
{ "type": "object" }
],
"items": { "type": "string" }
} It does look like we're complicating things by renaming keywords, but really we're simplifying things by making
We've been finding a lot of stuff like this since updating the website. Thanks for pointing it out. I've opened an issue. |
Beta Was this translation helpful? Give feedback.
-
That's not exactly what's happening. I think what's confusing you is the concept of boolean schemas. Starting in draft-06, you can use a boolean any place a schema is expected. {
"type": "object",
"properties": {
"foo": true
},
"additionalProperties": false
} The value of the So, the schema you gave as example is equivalent to the following, which probably makes more sense to you. "examples": {
"type": "array",
"items": {}
}, |
Beta Was this translation helpful? Give feedback.
prefixItems
was added in 2020-12 when we split the schema-formitems
and array-form` items.In previous versions, you can have the schema form
which requires that every item in the array is an object.
You can also have the array form
which only requires that the first item is an object, and you can add more subschemas to validate more items in sequence.
additionalItems
validates any items not validated byitems
. This means that for the schema-formitems
,additionalItems
does nothing because there aren't any more items to validate.For 2020-12, we split the array form of
items
off toprefixItems
and got rid of…