Skip to content

Fix $ref with siblings in pre-2019-09 tests #458

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
Mar 10, 2021

Conversation

jdesrosiers
Copy link
Member

@jdesrosiers jdesrosiers commented Mar 4, 2021

This is something that has been bothering me for a while. I have some time right now, so let's get this fixed. Before the nature of $ref was changed in draft 2019-09, any properties with an object with a $ref in it were members of the reference where they had no meaning rather than being part of the schema and interpreted as keywords. We have this test ...

{
  "definitions": {
    "a": {"type": "integer"},
    "b": {"$ref": "#/definitions/a"},
    "c": {"$ref": "#/definitions/b"}
  },
  "$ref": "#/definitions/c"
}

In this case, definitions and everything it contains should be considered part of the reference and ignored. It should not be something the $ref can reference, because it's not part of the schema.

This works in a lot of implementations. I think that's wrong, but the behavior in this case is, in the most generous interpretation, is undefined. If a test like this should be kept around at all, it should be with the "optional" tests. I wouldn't even include it in "optional" because it's at best a highly discouraged pattern and I don't think the test suite should encourage it by including an example.

@Julian
Copy link
Member

Julian commented Mar 4, 2021

I disagree with your categorization (I think this interpretation is more correct and obvious than the other), but I agree it's undefined, so lgtm!

(I also disagree with the test suite not including bad examples -- the test suite isn't a style guide, if something is meant to be implemented it should be here even if we discourage it, because implementations are not schema authors, and they should do what the spec says even if someone shouldn't be doing what they're doing. Lots of disagree but yes I suppose today :D -- regardless thanks, this is helpful!)

@jdesrosiers
Copy link
Member Author

I know not everyone is going to agree with my interpretation. I'm ok with that as long as we can agree that it's undefined.

I agree that if it's valid behavior, it should have a test no matter how bad the style. But, it's not valid behavior, it's undefined behavior.

@Julian
Copy link
Member

Julian commented Mar 5, 2021

Yep all good, agree!

@notEthan
Copy link
Contributor

notEthan commented Mar 5, 2021

previously:
#197
#198

#129

@jdesrosiers
Copy link
Member Author

@notEthan, thanks for linking those issues. I knew this wasn't the first time this has come up, but I didn't know it had come to PR, let alone two PRs.

From my reading of those issues, it was agreed that the behavior is not well enough defined. However, the decision was to do nothing and fix it in the next draft. That conclusion doesn't make sense to me because fixing it in the next draft doesn't address the problem with the previous draft. The behavior is still undefined in draft-04/06/-07 no matter what comes after.

As it turned out, the next draft (2019-09) didn't even end up deciding on a behavior. Instead the nature of $ref was changed in a way that this problem no longer existed. Two drafts later, there still is no decision on what this behavior should be and there won't be because $ref went in a different direction.

@Julian
Copy link
Member

Julian commented Mar 5, 2021

That conclusion doesn't make sense to me because fixing it in the next draft doesn't address the problem with the previous draft. The behavior is still undefined in draft-04/06/-07 no matter what comes after.

That conclusion meant simply that the existing tests were sufficiently likely, and in the test suite sufficiently long, that implementations likely have simply followed them for years.

You're making your interpretation seem overly likely :)

My agreement above was mostly "I'm tired of talking about this, and all you're proposing is moving these away or removing them or whatever" -- but the conclusion we came to to me made sense -- that yes fine this is less clear than it should be, but the tests have been here for 6 years+ or whatever -- given that they are not obviously wrong and that the spec can be read that they're correct, that they should have stayed.

@jdesrosiers
Copy link
Member Author

That conclusion meant simply that the existing tests were sufficiently likely
You're making your interpretation seem overly likely :)

Ahh, now I understand what that meant. There is an assumption that there is a correct answer and each interpretation has a likelihood of being correct. That's not the way I see it. If a behavior is not sufficiently defined, any interpretation that doesn't contradict the spec is not wrong. Likelihood has nothing to do with anything when there is no correct answer.

@Julian
Copy link
Member

Julian commented Mar 7, 2021

To be clear here I'm good with whatever resolution here but let's not just leave it undecided again, so probably if someone else wants to weigh in we should go with whatever consensus.

@jdesrosiers
Copy link
Member Author

I don't think it's necessary to decide on an interpretation. I think it's fine to just say it wasn't sufficiently defined in the spec, so use this pattern at your own risk. If you want to use this pattern and be sure it will work, you can upgrade to a more current draft that doesn't have this problem.

@karenetheridge
Copy link
Member

I agree that if it's valid behavior, it should have a test no matter how bad the style. But, it's not valid behavior, it's undefined behavior.

I agree with this and the changes made in this PR.

@Julian
Copy link
Member

Julian commented Mar 8, 2021 via email

Copy link
Member

@ssilverman ssilverman left a comment

Choose a reason for hiding this comment

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

👍

@ssilverman ssilverman merged commit b09e48d into json-schema-org:master Mar 10, 2021
@jdesrosiers jdesrosiers deleted the fix-ref-w-siblings branch November 30, 2022 18:56
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request Aug 19, 2023
I don't think this is really correct according to the
[specification][0], but it matches the previous behavior and seems
useful. Drafts after 7 don't have a problem because they allow all
keywords as `$ref` siblings.

Related:

- #44 (comment)
- json-schema-org/JSON-Schema-Test-Suite#458

[0]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3
davishmcclurg added a commit to davishmcclurg/json_schemer that referenced this pull request Aug 20, 2023
I don't think this is really correct according to the
[specification][0], but it matches the previous behavior and seems
useful. Drafts after 7 don't have a problem because they allow all
keywords as `$ref` siblings.

Related:

- #44 (comment)
- json-schema-org/JSON-Schema-Test-Suite#458

[0]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3
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.

5 participants