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

Consider all siblings in unevaluated keywords #164

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

davishmcclurg
Copy link
Owner

This uses all adjacent (same schema) results to calculate unevaluated keys/items, whether the keywords validated successfully or not. Previously, it only considered valid results, which causes confusing errors:

schemer = JSONSchemer.schema({
  'properties' => {
    'x' => {
      'type' => 'integer'
    }
  },
  'unevaluatedProperties' => false
})
schemer.validate({ 'x' => 'invalid' }).map { _1.fetch_values('schema_pointer', 'error') }
 # =>
 # [["/properties/x", "value at `/x` is not an integer"],
 #  ["/unevaluatedProperties", "value at `/x` does not match schema"]]

The overall validation result shouldn't be affected, since the only additional keywords that it considers are failed ones (meaning the entire schema fails regardless of the unevaluated keys/items). Duplicate/unhelpful error messages are reduced, though, which is the main reason for making this change.

Generally, this interpretation doesn't align with my reading of the spec, but there's been a lot of discussion around it and I think it makes sense from a user experience perspective. Hopefully it will get clarified in a future draft.

Closes: #157

Related:

This uses all adjacent (same schema) results to calculate unevaluated
keys/items, whether the keywords validated successfully or not.
Previously, it only considered valid results, which causes confusing
errors:

```ruby
schemer = JSONSchemer.schema({
  'properties' => {
    'x' => {
      'type' => 'integer'
    }
  },
  'unevaluatedProperties' => false
})
schemer.validate({ 'x' => 'invalid' }).map { _1.fetch_values('schema_pointer', 'error') }
 # =>
 # [["/properties/x", "value at `/x` is not an integer"],
 #  ["/unevaluatedProperties", "value at `/x` does not match schema"]]
```

The overall validation result shouldn't be affected, since the only
additional keywords that it considers are failed ones (meaning the
entire schema fails regardless of the unevaluated keys/items).
Duplicate/unhelpful error messages are reduced, though, which is the
main reason for making this change.

Generally, this interpretation doesn't align with my reading of the
spec, but there's been a lot of [discussion][0] around it and I think it
makes sense from a user experience perspective. Hopefully it will get
clarified in a future draft.

Closes: #157

Related:
- json-schema-org/json-schema-spec#1172
- https://github.com/orgs/json-schema-org/discussions/67
- https://github.com/orgs/json-schema-org/discussions/57
- https://github.com/json-schema-org/json-schema-spec/blob/2cb7c7447f9b795c9940710bf0eda966a92c937f/adr/2022-04-08-cref-for-ambiguity-and-fix-later-gh-spec-issue-1172.md

[0]: json-schema-org/json-schema-spec#1172
And change `additionalProperties` message to be consistent.
@davishmcclurg davishmcclurg changed the base branch from 2.1.2 to 2.2.0 January 20, 2024 03:28
@davishmcclurg davishmcclurg merged commit ead0180 into 2.2.0 Jan 20, 2024
62 checks passed
@davishmcclurg davishmcclurg deleted the unevaluated-properties branch January 20, 2024 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid error output with OpenApi 3.1 schema
1 participant