json-schema-org / website

JSON Schema website
https://json-schema.org
Other
58 stars 149 forks source link

prefixItems should not allow arrays of variable length #193

Open markoutso opened 2 years ago

markoutso commented 2 years ago

The documentation states that the keyword prefixItems is used for tuple validation. In the realm of programming and mathematics a tuple is something that has specific length. Quoting Wikipedia:

In computer science, tuples come in many forms. Most typed functional programming languages implement tuples directly as product types,[1] tightly associated with algebraic data types, pattern matching, and destructuring assignment.[2] Many programming languages offer an alternative to tuples, known as record types, featuring unordered elements accessed by label.[3] A few programming languages combine ordered tuple product types and unordered record types into a single construct, as in C structs and Haskell records. Relational databases may formally identify their rows (records) as tuples.

The json schema specification should follow common conventions or choose a better description for this validation.

In my opinion referring to arrays with variable as length as tuples is something that goes against the definition of the tuple and creates unnecessary confusion.

I would suggest that prefixItems stays as it is and it requires that all sub schemas validate the array elements in order. No more elements or should be allowed.

gregsdennis commented 2 years ago

Tuples are but one application of this keyword. I agree that it's odd they are highlighted as the reasoning behind the keyword, but it's current function does have merit.

Perhaps we can improve this section by focusing on what it does rather than try to illustrate one use case.

@jdesrosiers what do you think of moving the tuples language out of the spec and into the UJS content?

Relequestual commented 2 years ago

The documentation states...

@markoutso @gregsdennis I don't see "tuple" in this repo at all. Which documentation do you mean specifically? (Likely need to migrate the issue.)

I usually describe it as "tuple form" validation as opposed to tuple validation.

markoutso commented 2 years ago

Thanks everyone for looking at this! @Relequestual I double checked and you are right. This belongs to the Understanding Json Schema book.

jdesrosiers commented 2 years ago

I agree "tuple" isn't a perfect description, but I think it's more helpful than misleading. prefixItems (or previously array-form-items) is primarily useful for describing a tuple. I think the way it's written makes it sound like, if you're using this keyword then you're describing a tuple, which isn't always true. I think I'd like the example to be a tuple and call it a tuple, but make it more clear that you can describe things that are not quite tuples with this keyword as well.

In any case, I have another three months before I'll have a chance to work on this. So, don't wait on me if anyone wants to put up a PR.

gregsdennis commented 2 years ago

is primarily useful for describing a tuple

I think this is an incorrect assumption, and probably the basis of this confusion.

Julian commented 11 months ago

I've also previously expressed I think this language isn't really standard and is particularly confusing in languages which has a type called tuple. So +1 from me at least for avoiding it, I wouldn't change any keywords at all personally, but I definitely do not use the word "tuple" in the context of JSON Schema or JSON more broadly myself.

benjagm commented 10 months ago

Hi all. What could be the best term we should use to replace Tuple in our docs?

gregsdennis commented 7 months ago

"Tuple" appears on these pages:

github-actions[bot] commented 3 months ago

Hello! :wave:

This issue has been automatically marked as stale due to inactivity :sleeping:

It will be closed in 180 days if no further activity occurs. To keep it active, please add a comment with more details.

There can be many reasons why a specific issue has no activity. The most probable cause is a lack of time, not a lack of interest.

Let us figure out together how to push this issue forward. Connect with us through our slack channel : https://json-schema.org/slack

Thank you for your patience :heart: