-
-
Notifications
You must be signed in to change notification settings - Fork 429
✨ Proposal: "itemsMultipleOf" #1641
Copy link
Copy link
Open
Labels
proposalInitial discussion of a new idea. A project will be created once a proposal document is created.Initial discussion of a new idea. A project will be created once a proposal document is created.
Metadata
Metadata
Assignees
Labels
proposalInitial discussion of a new idea. A project will be created once a proposal document is created.Initial discussion of a new idea. A project will be created once a proposal document is created.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Describe the inspiration for your proposal
Splitting out this comment into its own issue, as suggested, since my use-case requires a much less powerful syntax than the
itemsPatternproposed there.Use-case: it's common to have arrays that contain flattened lists of tuples, such as x,y-coordinates. So it would be great to be able to say: "the number of items must be a multiple of 2".
Describe the proposal
Currently, every numeric constraint is also supported for array lengths, except
multipleOf.minimum: n->minItems: nmaximum: n->maxItems: nexclusiveMinimum: n->minItems: n + 1exclusiveMaximum: n->maxItems: n - 1multipleOf: n->???So I propose
itemsMultipleOfto fill that last little gap.Describe alternatives you've considered
I also considered the following possibilities:
{ // 1. "itemCountMultipleOf": 2, // 2. "arrayLength": {"multipleOf": 2}, // 3. "countItems": {"multipleOf": 2}, // 4. "count": {"multipleOf": 2} }But as @jdesrosiers mentioned, allowing length to be a whole subschema on its own (in cases 2, 3, and 4) seems like overkill when there is only one thing missing from the numeric schema:
multipleOf.Credit where credit is due: GPT 5 (extended thinking) came up with the name
itemsMultipleOfin response to the question "What would be the most logical new extension to json schema that would allow you to specify that the number of items is a multiple of a certain integer, e.g. 2?"Additional context
No response