-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Make $id
conform to RFC 3986 suggestion for base URI elements
#729
Comments
The painful bit is supporting multiple ways to say That price has been paid, so in some sense the implementation cost is over :) (Cognitive cost for users not withstanding, though I assume that's the point of this ticket) |
@Julian yeah, I think having one clear purpose for |
I think this is a great incremental improvement to |
To clarify, this would basically entail changing: json-schema-spec/jsonschema-core.xml Line 1164 in eb25539
from I'm definitely 👍 on this change. |
@ucarion close! My choice of wording of "MUST resolve to an absolute URI" leaves room for some kinds of relative references, although we can discuss further changes to that in a separate issue. As you no doubt noticed, I've been filing issues on various minimal steps we can take with With this particular issue, in terms of the RFC 3986 ABNF rules, the value would be:
That appears to be the least awkward way to specify it in the ABNF, as there is no The If you would like to discuss restricting |
Gotcha, makes sense! As a nit then, I'm not sure that RFC 3986 URI resolution leaves open the possibility of resolving to an
I think a better phrasing might be to say that, after resolving the |
@ucarion if we start from restricting the value of The paragraph you are quoting is discussing the general case. But constraining the input constrains the output, so we're fine. Fragments do not magically appear during resolution if they were not there before. |
@ucarion if, instead of restricting the values to those ABNF productions, we say that the value MAY contain a fragment which MUST be ignored, then you are correct, the resolved URI will in such cases end up having a fragment, and we will need to say that it MUST be ignored. Either way, it's just a question of getting the wording right once there's something resembling a consensus on forbidding fragments vs requiring them to be ignored. |
I'm going to write a PR for this, possibly in combination with other |
I don't think I have it in me to get this through in draft-08 |
OK, due to it coming up repeatedly over the last month, I'm giving this and #726 a shot in draft-08. |
Per RFC 3986 section 4.3:
Let's please follow this advice and require
$id
to resolve to an absolute URI, without a fragment. By this I mean that it cannot contain a fragment, but MAY be a relative URI reference (resolved in the same way that it is currently). If it makes things easier, rather than "MUST NOT contain a fragment", we can say that "any fragment MUST be ignored." Either option makes it absolutely clear that fragments in$id
have no useful effect.Currently, there are three behavioral cases of fragments in
$id
:"$id": "#foo"
: Plain name fragment definitions. We can replace with"$anchor": "foo"
, analogous to fragment definition keywords in several other media types. Very easy to explain, clearly separate from any concerns over base URIs or embedded documents."$id": "https://example.com/root#"
: Empty fragment in root schema object$id
s. This has absolutely no effect compared to the same thing without a fragment at all. It primarily exists as an explicitly supported case because older meta-schemaid
s were written this way, and we've never bothered to change that.Per section 8.2.3 of the current draft
This note explicitly makes the behavior of JSON Pointer-fragment-only
$id
s undefined, and notes that we have no idea how fragment-plus-other-component$id
s behave, meaning that their behavior is also undefined in the current spec.So there are several problems with the current behavior which this addresses:
$id
as a whole should work. However, this is incorrect- every other non-trivial usage has undefined behavior. Although some of it looks like it should work, at least to some people.$id
confusing. It requires a fairly deep understanding of RFC 3986 to understand why these behaviors can possibly work in the same keyword at all.Removing fragments from
$id
(and using$anchor
for plain name fragment definition instead) solves these problems.$id
MUST be ignored matches how base URIs are computed in RFC 3986$id
Some of the fragment-in-
$id
cases that technically have undefined behavior happen to be effective no-ops, as with the the empty fragment case. (Recall that the empty fragment is technically a JSON Pointer for the entire document).So sometimes we see schemas like this generated by tools:
which is basically a no-op (note that the
$id
fragment matches the actual position). So if we say that fragments in$id
MUST be ignored, its's still a no-op and that's fine. I would prefer an implementation to raise an error in this case going forward, but I don't feel strongly about that.My point here is that the only other fragment usage I've seen in the wild doesn't actually do anything.
@awwright if I'm reading #719 (comment) you are more or less OK with this idea? I agree that the names could be better, but keeping
$id
for the self+base form is less disruptive.@jdesrosiers you are encouraged to comment on the merits of this if you'd like, but please do not discuss your approach from #724 here, as we have already determined (in #179) that mixing the two discussions confuses everyone.
Everyone: fair warning, I feel very strongly about this. Unlike #726 (Eliminate base URI shadowing), which I think we should do but if we don't that's fine, I'm incredibly fed up with the problems with
$id
and feel like many of them come from having such a wide rage of syntactically valid values that have undefined semantics.If you want to keep the current situation of exactly one use of fragments in
$id
having defined semantics, and all other possible uses having undefined semantics, please make an active case for why such a thing is desirable.Yes, changing
"$id"
to"$anchor"
is a breaking change. That is unfortunate. But I feel like$id
as it stands is so problematic that this is worthwhile. And importantly, this just forbids one part of$id
's current syntax, and leaves the rest of$id
's well-defined behavior alone.Although perhaps @Julian can speak to how difficult this would be in his implementation, as I think he found the prior change of
id
to$id
particularly disruptive.The text was updated successfully, but these errors were encountered: