-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Feature/ref is delegation 2 #585
Conversation
Other properties of an object containing $ref as a key no longer MUST be ignored.
…d using an interface provided by the implementation. May be just a reiteration of the "loading a referenced schema", but I've added a use case.
…he default behaviour, but MAY be provided as an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of great stuff here @Relequestual, and I'm really glad you're getting into the PR work!
My overall thought here is that I'd like to get a really solid description of the new behavior, as if it were the only behavior that ever existed, nailed down, and then worry about how to make sure people who have been following the project understand the changes.
There are other things here where I may be missing the reasons that you have included some things, so if it seems that I've questioned something you feel is essential it may just be that I'm a bit too deep in the existing spec wording.
jsonschema-core.xml
Outdated
The "$ref" keyword is used to reference a schema, and provides the ability to | ||
validate recursive structures through self-reference. | ||
The "$ref" keyword can be used to reference a schema which is to be applied to the | ||
current instance location. "$ref" is an assertion key word, which MUST produce a boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ref
is an applicator rather than an assertion. It does not produce its own result, it merely conveys the result of the subschema that it applies (in this case the subschema is by reference rather than a literal subschema).
$ref
should return all of the results of the subschema (assertion and annotations).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were your words buddy...
Delegation means that the target of the $ref is processed against the current instance location, and the "results" (boolean assertion outcome and optionally the collected annotations) of $ref are simply the results of the target schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part I'm objecting to is '"$ref" is an assertion keyword', which is not something that I say in that text that you quote. I didn't explicitly classify it, and I'd be fine with not classifying it, but assertion keywords evaluate a condition based on a non-schema value (e.g. "maxLength": 5
) which is not what $ref
does.
Applicators apply a subschema and return its results (assertion and annotations). $ref
applies a subschema by reference rather than directly, so I wasn't particularly trying to fit it into the existing classifications, but if we are doing so then applicator is the correct one (and we might need to tweak the wording defining applicators if it talks specifically about an immediate subschema).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this change sort of obscures the purpose of $ref. We should probably still say it "provides the ability to validate recursive structures through self-reference".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll chang this and mention recursive structures again.
</t> | ||
<t> | ||
The URI is not a network locator, only an identifier. A schema need not be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still true. It relates to section 8.3.1 about loading schema references. You may have something like "$ref": "https://example.com/schemas/foo"
, but that host may be down, or you may be running behind a firewall. In which case you probably have the schema available locally and SHOULD NOT automatically fetch it.
We do need some improved wording about when it's OK to automatically fetch $ref
'd schemas, as some environments will depend on such dynamic fetching. But that was true before this change so I'd suggest we work on that separately.
@@ -814,7 +816,30 @@ | |||
Schemas SHOULD NOT make use of infinite recursive nesting like this; the behavior is | |||
undefined. | |||
</t> | |||
<section title="Loading a referenced schema"> | |||
<t> | |||
A URI reference without a protocol MUST be considered a plain name fragment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this part. There is nothing at all special about URI references in "$ref"
values. Everything that needs to be said about resolving $ref
and $id
is already said in this document, and none of it changes as the result of the whole inclusion/delegation change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have both hit the nail on the head, and missed the point.
The reason for this section change, is trying to highlight specific aspects of how URI work, as the above removed lines (ending 807) clearly wern't suffecient to explain. There have been so many Stack Overflow questions on how resolution works that I've lost count.
These changes don't CHANGE any of the behaviour, but seek to clairfy it with a little structure. Everything that NEEDS to be said technically yes, but not everything that needs to be said to make the technical aspect clear enough in my experinece.
Even when I've pointed people to the spec section, it wasn't enough. So I tried to write stuff which was a simple form of discussions which resulted in people understanding the intent.
jsonschema-core.xml
Outdated
the user to specify a method to perform a network operation (or other operation) to retrieve the reference | ||
content. For example, the behaviour of a URI with a protocol of "file" is not defined. The implementation | ||
provides an interface to define a function which is called when it encounters a URI which uses the specified | ||
URI protocol (which is "file" in this case). The user defines "file" as the protocol, and includes a function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole concept (the regular paragraph on lines 822-825 and this CREF) are implementation notes of the sort that we have not had before. Whether we need them or not, I don't think that delegation vs inclusion makes them more or less necessary.
If we had already gotten agreement in an issue that we need this sort of change, and if the main point of this PR (delegation vs inclusion) was otherwise clear, I'd have no problem doing this in one PR. But I'm not sold on the need for this section, so I'd like to get the agreed-upon changes clear and committed first before opening a new topic on what sort of implementation guidance does or does not need to be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought a better explanation of how things work was in scope under #514 ? "What is "$ref" and how does it work?" is pretty broad. I may want to write additional comments to this part before awaiting a reply =]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue title was pretty broad as I was trying not to prejudice the outcome. It's not that I'm against clarifying, it's that this level of implementation detail doesn't seem quite right to me. Perhaps I'm just not understanding it the way you intended.
@@ -903,6 +928,24 @@ | |||
</t> | |||
</section> | |||
</section> | |||
<section title="Dereferencing By Inclusion"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the previous PR (I think, or maybe on Slack), I think that if this is just to explain the difference from prior behavior, it belongs in an appendix (which would be xref'd from a brief note in the main text). This is what I've been doing for all confusing changes, like the dependencies
split, $defs
vs definitions
, and keywords that moved from validation to core.
If we do want to provide guidance on an inclusion mechanism for things like json-schema-ref-parser that want to do so to the extent it is possible, then it should describe the use with allOf
per #523.
But I don't think there should be a dereference inclusion process as part of the standard. Just a clear description of the behavior, and tools that want to make schema transformations that preserve that behavior can do so (for instance, I know of at least three tools for collapsing allOf
branches into a single schema, which is not part of the spec but follows directly from the described behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I was trying to address the issues raised by making this change (ref is delegation) as per #523.
I make no reference to prior behaviour, so it's not explaining a difference.
If we do want to provide guidance on an inclusion mechanism for things like json-schema-ref-parser that want to do so to the extent it is possible, then it should describe the use with allOf per #523.
I thought we wanted to avoid specific implementation directives where possible (like saying "you should do this by using allOf
)? More, this section puts the nessecary constraints on any process, which may need to resolve by inclusion, as to avoid any interoperability issues.
I think this is REQUIRED. If we don't define constraints around how to implement inclusion, I feel it will be done any number of invalid ways and cause problems.
jsonschema-core.xml
Outdated
</t> | ||
<cref anchor="REF1" source="BH"> | ||
The use of "$ref" MUST NOT effect adjacent keywords. | ||
Given previously the use of "$ref" would negate the use of other keywords in that object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that most of this can be made clear by thoroughly describing the applicator behavior. Otherwise I would put this in the appendix for people who want to understand the changes, as noted in another comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should discuss this as it looks to me like your opinion on applicator or assertation for $ref has changed since the issue was raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of my opinion changing although I certainly accept that I may have been unclear.
@Relequestual note that #589 reorganizes where the I tried to avoid impacting the areas you're working on here as much as possible, but I needed this changes for |
@handrews The issue you mentioned has since been closed with a hope to revisit later. I'll continue with this one. |
@Relequestual yes, don't worry about the specifics of #589. The general idea of static vs dynamic references as two forms of in-place applicators will still be present in the next approach, but I can worry about merging the specifics when I get there. |
…and not an assertion key word. Removed sections which explain implementation detail or use case. Slightly modified language around network addressable locators. Mention recursive structures.
After discussing this with @Relequestual off-github, we decided to split this into three PRs/Issues:
|
How's this one coming along @Relequestual? |
@philsturgeon FYI, those type of comments on github most likely won't reach me due to volume of notifications. Consider Slack as a preference for nudges =] |
I was on leave for the last two days, and the remainder of this week is split between this and another project, so I strongly expect this to be delivered again this week. |
Opened #628 in favour |
@handrews I believe this can now be closed, as I've opened a new PR in favour, and created two new issues, as specified by your previous comment. Please close if you concurr. I'm happy for you to delete the branch, as I believe I'll still retain it on my fork. (And at the least, I'll have a local copy.) |
@Relequestual thanks for all the work revising and splitting this! I agree we can close this. |
#628 Opened in favour of this PR.
Retrying to
resolve#523 andresolve#514.Opened in favour of #580 !
Possibly considered a sidetrack, but I think it's part of #514 :
Redacted previous change of removing comment on infinite loops.
Do we actually want this? Later we say "Validators MUST NOT fall into an infinite loop." which suggests we expect that could be possible based on the schema.
Maybe I just missunderstand the intesnion. Happy to file a new issue if you (collective) find this preferable.