Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regarding uniqueItems error interpretation #1099

Closed
nuno-andre opened this issue May 10, 2021 · 4 comments
Closed

Regarding uniqueItems error interpretation #1099

nuno-andre opened this issue May 10, 2021 · 4 comments

Comments

@nuno-andre
Copy link

JSON Schema specs define an array as an ordered sequence of zero or more values and its instance equality as both are arrays and have an equal value item-for-item but, AFAIK, do not state which mathematical object corresponds to this type and therefore neither its concept of multiplicity.

So, for instance, in a uniqueItems validation against [1, 1, 2, 2, 2, 3], how many errors should we say have occurred?

  • Two errors: 1 and 2 are not unique.
  • Three errors: the second 1, the second 2, and the third 2 are repeated elements.
  • Five errors: {1, 1, 2, 2, 2}.
@handrews
Copy link
Contributor

@gregsdennis would you handle this as one entry in the error structure, and any information about how many / what kind of problems would go into the detail string? Or multiple error entries, one for each way in which it could fail? What do you do for additionalProperties: false? One error for all extra properties or one error per extra property?

@karenetheridge
Copy link
Member

karenetheridge commented May 10, 2021

In my implementation I generate one error (all the validation vocabulary keywords generate just one error), and an indication of where in the data the error lies.

For example, the data [ 1, 1, 2, 2, 1 ] evaluated against the schema {"uniqueItems": true } generates this evaluation result:

{
  "errors" : [
    {
      "error" : "items at indices 0 and 1 are not unique",
      "instanceLocation" : "", 
      "keywordLocation" : "/uniqueItems"
    }
  ],
  "valid" : false 
}

(edited data instance to add more duplicate items, to make it clear that even with longer arrays only one error is generated)

@gregsdennis
Copy link
Member

I think a single output unit would suffice here. It's the keyword that failed to validate, so it makes sense to only include a single unit for the keyword.


Bearing that in mind, #973 is considering adding an instance-based structure (instead of a schema-based structure) as a possible output format. If this is used, it may make sense to include each violation. This hasn't been hashed out yet though.

@nuno-andre
Copy link
Author

Yes, I was not precise enough. I was assuming one validation error, the question was about the need to identify the individual errors in verbose or detailed outputs. Luckily, both questions were solved :)

I see that @karenetheridge's implementation adopts the third option, which is consistent with the definition of an array as an indexed set and also probably the most robust approach.

I am going to close this issue and subscribe to #973 to be aware of upcoming changes.

Thank you all for this answer and for all the others, this repo has become my JSON-Schema Bible ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants