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

Add tests for unevaluated with dynamic reference #696

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

jdesrosiers
Copy link
Member

Fixes #691

@jdesrosiers jdesrosiers requested a review from a team as a code owner October 24, 2023 19:00
Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My impl passes for the 2020-12 but fails for the 2019-09 because prefixItems is ignored and the $recursiveRef is never hit.

"$recursiveAnchor": true,

"type": "array",
"prefixItems": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefixItems is 2020-12.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I seems I accidentally have prefixItems registered as a 2019-09 keyword, so the test passed when I tested on my implementation.

@jdesrosiers jdesrosiers force-pushed the unevaluated-dynamicref branch from f13fb46 to 2834c63 Compare October 24, 2023 21:50
Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing now.

"foo": { "type": "string" }
},
"$dynamicRef": "#addons",
"unevaluatedProperties": false,
Copy link
Contributor

@skryukov skryukov Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of keywords might affect order of execution in implementations, so should we put unevaluatedProperties first, to cover that as well? (that might be a separate issue, since there are a lot of test cases here that have unevaluatedProperties last in the list)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have other tests that ensure key order is not a factor in evaluation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for $dynamicRef and $ref though. My implementation passed this test case but just by luck 😅

Moving "$ref": "#/$defs/bar" down in "unevaluatedItems with $ref", for example, fails.

It's also really important to test references bc they are not explicitly listed in the spec section: https://json-schema.org/draft/2020-12/json-schema-core#name-unevaluatedproperties

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for $dynamicRef and $ref though.

I don't think it's practical to check order of keywords for every combination of keywords. We have tests that ensure order of keywords is irrelevant. It's expected that this is applied across an implementation, not just for those tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also really important to test references bc they are not explicitly listed in the spec section: https://json-schema.org/draft/2020-12/json-schema-core#name-unevaluatedproperties

The spec does address references:

"This includes but is not limited to the in-place applicators defined in this document."

References are in-place applicators because they evaluate the instance against the schema they're referencing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that it's impractical to test ordering for every combination of keywords, I'm of the opinion that anything that exposed a real bug in an implementation belongs in the test suite. I'll move unevaluated* to be the first keyword and include a note explaining why.

@jdesrosiers
Copy link
Member Author

I applied the suggested changes. I also realized that I forgot to add the tests to draft-next, so I added that as well.

@Julian
Copy link
Member

Julian commented Nov 15, 2023

CI is failing here (for correct reasons, it's saying you have invalid JSON), AFAICT that's the only thing preventing merging this, it's got an approval, yes?

@Julian Julian added the waiting for author A pull request which is waiting for an update from its author. label Nov 15, 2023
@jdesrosiers
Copy link
Member Author

I didn't notice the build failure. Thanks for pointing that out. I was waiting for review on the requested changes and then completely forgot about this when no review happened.

@Julian
Copy link
Member

Julian commented Nov 16, 2023

Cool, thanks! Merging.

@Julian Julian merged commit d38ddd5 into json-schema-org:main Nov 16, 2023
2 checks passed
Julian added a commit to python-jsonschema/jsonschema that referenced this pull request Nov 16, 2023
This was previously correct for $refs, but not $dynamicRefs,
which had no test in the JSON Schema test suite.

This behavior is now properly compliant with the 2020 spec (as well as
2019, for $recursiveRef).

Refs: json-schema-org/JSON-Schema-Test-Suite#696
@karenetheridge
Copy link
Member

karenetheridge commented Nov 26, 2023

This introduced duplicate identifiers: "https://example.com/extended-tree" is used as a URI across multiple tests in the same specification version.

There are also duplicate identifiers produced with "baseSchema" and "tree" -- "https://example.com/baseSchema" and "https://example.com/tree" end up referring to multiple locations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author A pull request which is waiting for an update from its author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing test for unevaluatedProperties and $dynamicRef
5 participants