Skip to content

fix buggy test with $ref in older drafts #492

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

Merged
merged 1 commit into from
Jun 26, 2021
Merged

Conversation

karenetheridge
Copy link
Member

all keywords adjacent to $ref have no effect in draft7 and earlier.

all keywords adjacent to $ref have no effect in draft7 and earlier.
@karenetheridge karenetheridge requested a review from a team June 25, 2021 04:32
@karenetheridge
Copy link
Member Author

I don't know how all your implementations were passing with this test! Maybe you have a bug?

@gregsdennis
Copy link
Member

Sounds like we should have tests against this scenario if it should have failed.

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.

Can you add a test for the scenario that should fail?

@karenetheridge
Copy link
Member Author

I don't understand what you're asking. The test as it is in the patch is the test that should fail.

@gregsdennis
Copy link
Member

gregsdennis commented Jun 26, 2021

Looking into this more deeply, I don't understand why it should have failed. The $id has no impact on this test (in neither the original nor your change) because the $ref is changing the file name in the base URI anyway, so it doesn't matter whether $ref is a sibling of it.

The only way the $id could have an impact is if it specified a different folder, e.g. http://localhost:1234/subfolder/schema-remote-ref-ref-defs1.json. This would be ignored in the original case, but it would change the base URI in the second.

@karenetheridge
Copy link
Member Author

karenetheridge commented Jun 26, 2021

When the $id is respected, the $ref resolves to "http://localhost:1234/ref-and-defs.json", which maps to a file in the resources/ directory. Without $id, the $ref resolves to "ref-and-defs.json" which doesn't exist (and such resolution is undefined; my implementation aborts evaluation and generates a result object with one single error.

@gregsdennis
Copy link
Member

Okay, so you're saying that without the $id, the domain (locahost:1234) isn't defined, and so $ref can't resolve. That makes sense.

Now that you've corrected the schema to operate as the test cases expect, we still need one that ensures $ref can't resolve when it's a sibling of $id. This is what I'm asking you add.

@karenetheridge
Copy link
Member Author

We already have tests for that, in ref.json.

My goal in this specific PR is to fix a test that should not ever have worked.

@karenetheridge
Copy link
Member Author

There's probably more we can test in here, e.g. with an adjacent $id specifically, or an adjacent definitions, but I'll address that in a separate PR.

@gregsdennis
Copy link
Member

We already have tests for that, in ref.json.

Can you link to where we already have it? The closest I found was this, but it wraps the $ref in an allOf.

My goal in this specific PR is to fix a test that should not ever have worked.

Yes, but in finding this test that should never have worked, you've identified two cases that should be covered: the case that this is attempting to cover and the case of why this should fail. They each need coverage.

@karenetheridge
Copy link
Member Author

The failure case cannot be covered. There is no way of expressing a uri resolution failure in our current testing infrastructure.

The general case of sibling keywords to $ref being ignored is already covered. The $id keyword specifically is not, but I did say I would handle that in a separate PR.

If there are no objections to the changes I have made here, I'm going to merge this.

@gregsdennis
Copy link
Member

gregsdennis commented Jun 26, 2021

$ref being unable to resolve is definitely a case that can be covered. I return an error message in the defined format. Validation fails.

@karenetheridge
Copy link
Member Author

No it can't, because there's no way to express it with the current testing syntax.

If you can come up with something, then by all means.

@karenetheridge karenetheridge merged commit 2f6a498 into master Jun 26, 2021
@karenetheridge karenetheridge deleted the ether/fix-refRemote branch June 26, 2021 04: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.

2 participants