json-schema-org / json-schema-spec

The JSON Schema specification
http://json-schema.org/
Other
3.43k stars 251 forks source link

Omitted `prefixItems` vs empty #1480

Closed notEthan closed 2 weeks ago

notEthan commented 5 months ago

The spec says of prefixItems:

The value of "prefixItems" MUST be a non-empty array of valid JSON Schemas.

Then ends with:

Omitting this keyword has the same assertion behavior as an empty array.

Specifying that an omitted prefixItems behaves the same as a value that it must not be looks wrong. Comparing to allOf/anyOf/oneOf which also must be non-empty arrays of schemas, they omit the sentence about omitting the keyword.

I'm not sure why any of these must be non-empty - sure, when empty they end up either just allowing everything (prefixItems, allOf) or nothing (anyOf, oneOf), but plenty of other keywords allow similar degenerate cases, e.g. minItems may be 0 allowing everything and enum may be empty allowing nothing. That's just an observation, not a battle I am itching to take on, and I'm sure it's all been discussed before.

Related: https://github.com/json-schema-org/json-schema-spec/issues/975 / https://github.com/json-schema-org/json-schema-spec/pull/1001

notEthan commented 5 months ago

I suppose this is straightforward enough I'll fix & PR