While there seems to be lots of discussion on the topic of $ref, id, and JSON Pointer, I haven't found any discussion on my issue in particular. My issue impacts both how to interpret the v3 draft and making proposals for future drafts.Currently the v3 draft specifies:If id is missing, the current URI of a schema is defined to be that of the parent schema. The current URI of the schema is also used to construct relative references such as for $ref.Literally, this is impossible: two different resources, by definition, cannot have the same URI (a resource is anything uniquely identifiable by a URI). I read this to mean that the URI base of a schema is unchanged from the parent, not that the schema can somehow be identified by the same URI that another schema identifies by.
This issue has also been raised as an issue to abandon the id attribute, but this does not follow. What if two schemas are defined with the same URI? In the Web this is impossible as long as the data being utilized is correct. It's not the library's job to determine what is correct, and what is false or erroneous data. There's plenty of schemas which, while "wrong" (maybe it's malicious, stale, outdated, or otherwise incorrect), will still be internally consistent and will validate instances without raising any error (the error is only uncovered in certain impossible situations, and if uncovered, the validator should raise a Schema Error, the same kind of error it would emit if it's passed {"divisibleBy": 0}). It's the developer's job to make sure that the schemas being passed to a validation library are correct, and if so, this error will never be raised.
Some JSON Schema validators may have an option to automatically deference URIs. In this case, it's taking on responsibility beyond the scope of the JSON Schema, and should make sure that schemas with the same URI re-defined in multiple places are consistent with one another, that the HTTP cache is not stale, that the external URI is a trusted third party or that a malicious party's schema is validated and checked for security, and so on.
Let Parse be the JSON Schema validation function with three arguments: First, the instance being validated; second, the schema being validated against; and third, the base which is the document URI of the schema, or URI to which the URIs in the base of the schema are resolved against (e.g. if in the presence of an HTML <base/> tag);Let superValid = Parse(instance, schema, base);Let subBase = schema.id, if it exists, or <> otherwise (<> being the blank URI), resolved against base;Let subValid = Parse(instance[x], schema.properties[x], subBase)
The schema resolution algorithm Parse I call consistent if subValid returns valid whenever superValid returns valid, and superValid returns invalid whenever subValid returns invalid, and where "properties" is any attribute containing a sub-schema used to process some corresponding instance sub-value, for every possible value of instance, schema, base, and x. (This means every possible value of schema for this test contains a sub-schema.)
I believe consistency is a desirable trait for JSON Schema because it allows developers to combine schemas or substitute them into {"$ref":"..."} expressions with little computational effort or consideration. If the URI <#> were to always resolve against base and not the base of the current schema (i.e. the parent schema id if it exists), this would be inconstistent: If I extracted a JSON Schema from a super schema, the base would change, and thus the meaning of <#> within that schema. Merely extracting a schema from another schema would no longer be enough work, I would have to actually modify the values of $ref properties wherever they appear. If the algorithm were consistent however, I merely need to note the base of the sub-schema, and provide it to the parser as the document URL, and no modification of the schema object itself is necessary.
To create a consistent validation function, I implement the JSON Schema draft v3 with the understanding I mentioned above (that only the schema URI base is inherited, not the id itself). This is also consistent with the behavior of the Web, where any resource may be given any number of URIs (by definition), and where arbitrary fragments may also identify a resource within a document (like anchors in HTML):
- Let target be the value of the
$refproperty resolved against the URI base, which is the parent schema URI (or their parent as necessary, ad infinitum, and failing that, the document URL, if available)- If a schema exists with target, then
- Use the schema at target and end
- Split target into deref and fragment, containing the part before the fragment and the fragment (if any), respectively
- If deref equals target, then
- Raise a schema does-not-exist error and end
- If a schema exists at deref, then
- Let schema be the schema found by starting at the schema identified by deref and walking it according to fragment
- If schema does not exist, then
- Raise a schema does-not-exist error and end
- Else use schema and end
- Else raise a schema does-not-exist error and end
This algorithm, complete with URI resolution relative to a base, is now implemented in <https://github.com/tdegrunt/jsonschema> and it passes all the tests in <https://github.com/json-schema/JSON-Schema-Test-Suite> (except some fragment-escaping-related tests, as described below -- this isn't terribly meaningful since there's a lack of relative URI resolution tests).This allows for a schema to be identified by multiple URIs. This is not a novel concept, and again is seen throughout the Web, like Semantic Web applications (which, I may note, is an increasingly heavy user of JSON and hyper-JSON).
Finally, there is the issue of how to interpret differences between v3 and future drafts. Some people have suggested using the latest draft of JSON Pointer for resolving JSON Schema draft v3 URI fragments. While I don't mind interpreting the specification to make it internally consistent, doing this is not necessary to accomplish a consistent implementation. JSON Schema draft v3 specifies URI encoding of property names only. I'd also like to see this in JSON Pointer, and that the current JSON Pointer syntax is unnecessarily complex by deviating from the URI encoding standard, which starting at v3, and currently, treats ~ as a special character, when it is normally a valid URI character needing no special encoding. %2f is sufficient as an escape for the / character. Since / is a reserved URI character, it is not the same as %2F in a URI (unlike <a> and <%61> which are equivalent URIs).
Finally finally, I'd note I make a subtle distinction between </schema.json> and </schema.json#> where schema.json is an application/json document: The former identifies a byte stream, an information resource, the latter identifies a conceptual resource, a parsed JSON object, like one in memory. They can both be used the same to refer to a JSON Schema, though.
Austin Wright.
On Friday, December 21, 2012 12:54:19 AM UTC, diamon...@users.sourceforge.net wrote:While there seems to be lots of discussion on the topic of $ref, id, and JSON Pointer, I haven't found any discussion on my issue in particular. My issue impacts both how to interpret the v3 draft and making proposals for future drafts.Currently the v3 draft specifies:If id is missing, the current URI of a schema is defined to be that of the parent schema. The current URI of the schema is also used to construct relative references such as for $ref.Literally, this is impossible: two different resources, by definition, cannot have the same URI (a resource is anything uniquely identifiable by a URI). I read this to mean that the URI base of a schema is unchanged from the parent, not that the schema can somehow be identified by the same URI that another schema identifies by.Yes, I think that's the only obvious interpretation.
This issue has also been raised as an issue to abandon the id attribute, but this does not follow. What if two schemas are defined with the same URI? In the Web this is impossible as long as the data being utilized is correct. It's not the library's job to determine what is correct, and what is false or erroneous data. There's plenty of schemas which, while "wrong" (maybe it's malicious, stale, outdated, or otherwise incorrect), will still be internally consistent and will validate instances without raising any error (the error is only uncovered in certain impossible situations, and if uncovered, the validator should raise a Schema Error, the same kind of error it would emit if it's passed {"divisibleBy": 0}). It's the developer's job to make sure that the schemas being passed to a validation library are correct, and if so, this error will never be raised.This was not quite the issue Francis raised - it was not to do with schemas inheriting a (base) URI from a parent schema.His criticism was around the idea that "id" allowed schemas to claim to represent URIs other than the one from which they were fetched, therefore leading to possible inconsistency if the two versions disagree. I agree this is possible, but categorised it as "servers breaking their own promises" which naturally will cause inconsistent behaviour. Given the quite stringent guidlines layed out in the standard about when clients should believe the claims made by "id", I don't have a problem with this at all - servers can only screw themselves up, not other people.But anyway - the argument you mention was not the proposed reason for removing "id".
Some JSON Schema validators may have an option to automatically deference URIs. In this case, it's taking on responsibility beyond the scope of the JSON Schema, and should make sure that schemas with the same URI re-defined in multiple places are consistent with one another, that the HTTP cache is not stale, that the external URI is a trusted third party or that a malicious party's schema is validated and checked for security, and so on.That sounds pretty reasonable, and is pretty much how I feel. The only problem I have with "id" is the fact that some big players aren't using it properly (I'm looking at you, Google... >_>)Let Parse be the JSON Schema validation function with three arguments: First, the instance being validated; second, the schema being validated against; and third, the base which is the document URI of the schema, or URI to which the URIs in the base of the schema are resolved against (e.g. if in the presence of an HTML <base/> tag);Let superValid = Parse(instance, schema, base);Let subBase = schema.id, if it exists, or <> otherwise (<> being the blank URI), resolved against base;Let subValid = Parse(instance[x], schema.properties[x], subBase)The schema resolution algorithm Parse I call consistent if subValid returns valid whenever superValid returns valid, and superValid returns invalid whenever subValid returns invalid, and where "properties" is any attribute containing a sub-schema used to process some corresponding instance sub-value, for every possible value of instance, schema, base, and x. (This means every possible value of schema for this test contains a sub-schema.)Yes - that is how schema validation is defined for things like "properties", "items", and so on. Either the sub-schemas validate, or the parent schema does not.The only exception is "disallow" (replaced with "not" in v4).I believe consistency is a desirable trait for JSON Schema because it allows developers to combine schemas or substitute them into {"$ref":"..."} expressions with little computational effort or consideration. If the URI <#> were to always resolve against base and not the base of the current schema (i.e. the parent schema id if it exists), this would be inconstistent: If I extracted a JSON Schema from a super schema, the base would change, and thus the meaning of <#> within that schema. Merely extracting a schema from another schema would no longer be enough work, I would have to actually modify the values of $ref properties wherever they appear. If the algorithm were consistent however, I merely need to note the base of the sub-schema, and provide it to the parser as the document URL, and no modification of the schema object itself is necessary.That makes sense only if you consider the result of the "$ref" to be actually part of the parent schema document, which I think would be fairly radical. If you instead consider that the target of $ref should be "spliced in", but retain information about its own URI that is separate from the original
To create a consistent validation function, I implement the JSON Schema draft v3 with the understanding I mentioned above (that only the schema URI base is inherited, not the id itself). This is also consistent with the behavior of the Web, where any resource may be given any number of URIs (by definition), and where arbitrary fragments may also identify a resource within a document (like anchors in HTML):
- Let target be the value of the
$refproperty resolved against the URI base, which is the parent schema URI (or their parent as necessary, ad infinitum, and failing that, the document URL, if available)- If a schema exists with target, then
- Use the schema at target and end
- Split target into deref and fragment, containing the part before the fragment and the fragment (if any), respectively
- If deref equals target, then
- Raise a schema does-not-exist error and end
- If a schema exists at deref, then
- Let schema be the schema found by starting at the schema identified by deref and walking it according to fragment
- If schema does not exist, then
- Raise a schema does-not-exist error and end
- Else use schema and end
- Else raise a schema does-not-exist error and end
Interestingly - this sequence of parent schemas is exactly how I interpreted it. Francis, however, understood "parent schema" to be equivalent to "root schema". While I disagree, I do admit that his interpretation is consistent (as well as being quite a lot easier to implement).
I don't understand #4, though - if the fragment part is empty, won't that always fail?
This algorithm, complete with URI resolution relative to a base, is now implemented in <https://github.com/tdegrunt/jsonschema> and it passes all the tests in <https://github.com/json-schema/JSON-Schema-Test-Suite> (except some fragment-escaping-related tests, as described below -- this isn't terribly meaningful since there's a lack of relative URI resolution tests).This allows for a schema to be identified by multiple URIs. This is not a novel concept, and again is seen throughout the Web, like Semantic Web applications (which, I may note, is an increasingly heavy user of JSON and hyper-JSON).Finally, there is the issue of how to interpret differences between v3 and future drafts. Some people have suggested using the latest draft of JSON Pointer for resolving JSON Schema draft v3 URI fragments. While I don't mind interpreting the specification to make it internally consistent, doing this is not necessary to accomplish a consistent implementation. JSON Schema draft v3 specifies URI encoding of property names only. I'd also like to see this in JSON Pointer, and that the current JSON Pointer syntax is unnecessarily complex by deviating from the URI encoding standard, which starting at v3, and currently, treats ~ as a special character, when it is normally a valid URI character needing no special encoding. %2f is sufficient as an escape for the / character. Since / is a reserved URI character, it is not the same as %2F in a URI (unlike <a> and <%61> which are equivalent URIs).No, it's not necessary. Using "id" for fragment resolution, however, is not elegant, and not as flexible. Throw in the fact that Google are mis-using "id", and you can see why we're more keen on JSON Pointer.
If you have complaints about JSON Pointer, then go take it up with the people who wrote that standard. However, it's flexible, we don't have to specify our own fragment-resolution algorithms, and on top of that - I think JSON Pointer is fine, and I have no issue with ~-escaping.
Finally finally, I'd note I make a subtle distinction between </schema.json> and </schema.json#> where schema.json is an application/json document: The former identifies a byte stream, an information resource, the latter identifies a conceptual resource, a parsed JSON object, like one in memory. They can both be used the same to refer to a JSON Schema, though.The web convention is that "<URI>" and "<URI>#" represent the same resource. Given that they should be able to be used interchangeably, I'm afraid I can't quite see the benefit of trying to define any distinction between them.
On Sat, Dec 22, 2012 at 12:47 AM, Austin Wright
<diamon...@users.sourceforge.net> wrote:
[...]
>
> The algorithm that I laid out I believe is easier to implement: Keeping an
> internal table of schemas as a map (AbsURI -> Schema), that whenever you
> lookup a schema from that map, just change your URI base to the looked-up
> URI. But in any event, the point of a JSON Schema implementation is to do
> the heavy lifting so the developer doesn't need to.
>
You seem to be assuming the fact that any fully resolved ID will be
absolute. And that is not the case.
You can perfectly well load this schema locally:
{
"id": "foo",
"whatever": [ "you", "want" ],
"sub": {
"id": "other"
}
}
No URI is absolute here. The Internet does not resolve around HTTP!
But with my implementation, I can fully, and accurately, resolve any
$ref into that schema.
Hopefully I impress why the id attribute is important, though.
That makes sense only if you consider the result of the "$ref" to be actually part of the parent schema document, which I think would be fairly radical. If you instead consider that the target of $ref should be "spliced in", but retain information about its own URI that is separate from the originalWhat do you mean by "parent schema document" exactly? I'm saying the referenced object is not merely substituted in, but the referenced object keeps its own URI base, otherwise equivalent to substitution.
Francis' implementation doesn't lead to consistent results, as I defined consistency. If I have a {"$ref": "#"} expression somewhere in my JSON schema then the result of the lookup would be dependent on the root schema URI, when it instead should always yield the same results whenever the environment URI is the same, e.g., if I have {"id": "http://example.com/cars.json", additionalProperties:{"$ref":""}} then it should always refer to itself no matter where it appears, or the document URI. However, in Francis' implementation, it does not, therefore I would not call it consistent.
The algorithm that I laid out I believe is easier to implement: Keeping an internal table of schemas as a map (AbsURI -> Schema), that whenever you lookup a schema from that map, just change your URI base to the looked-up URI. But in any event, the point of a JSON Schema implementation is to do the heavy lifting so the developer doesn't need to.
I don't understand #4, though - if the fragment part is empty, won't that always fail?That's the point. If no schema at target exists, and there's no fragment, then it's follows there's no schema at the URI without the fragment (it's the same URI of course), so that's a failure.
No, it's not necessary. Using "id" for fragment resolution, however, is not elegant, and not as flexible. Throw in the fact that Google are mis-using "id", and you can see why we're more keen on JSON Pointer.How does one use the id attribute for fragment resolution? If you want to put fragments in "id" I'd think you can do so (e.g. a schema {"id": "http://example.com/spec#schema"} is legal and referencable), but it's largely unnecessary.
If you have complaints about JSON Pointer, then go take it up with the people who wrote that standard. However, it's flexible, we don't have to specify our own fragment-resolution algorithms, and on top of that - I think JSON Pointer is fine, and I have no issue with ~-escaping.It appears to be directly derived from JSON Schema, including the authors. While media types are allowed to define their own fragment resolution schemes, JSON does not do so, nor is JSON Pointer an attempt to to so. Perhaps a new specification entirely is in order.
Finally finally, I'd note I make a subtle distinction between </schema.json> and </schema.json#> where schema.json is an application/json document: The former identifies a byte stream, an information resource, the latter identifies a conceptual resource, a parsed JSON object, like one in memory. They can both be used the same to refer to a JSON Schema, though.The web convention is that "<URI>" and "<URI>#" represent the same resource. Given that they should be able to be used interchangeably, I'm afraid I can't quite see the benefit of trying to define any distinction between them.They'll both go to the same webpage, but they're not (necessarily) the same resource. Tim Berners-Lee's argument that "HTTP URIs (without "#") should be understood as referring to documents, not cars." (I have a slightly different take on the so-called httpRange-14 issue, that cars can have URIs without fragments so long as you use Content-Type negotiation, but I digress, but the point is, <URI> and <URI#> are not necessarily the same resource.)
(did I say "id" was a viper's nest? No? :p)
I'd first like to mention that there is no obligation at all that "id"
be an absolute URI. In fact, draft v3 does not constrain what "id" can
be at all, and that is one of my problems. But nevermind that.
In this situation:
* if all references are resolved against the root schema, "#" refers
to "rootSchema",
* but if they are resolved against the uppermost parent having an id,
here "alsoNested" which has URI "/some/otherNode#withFragment", the
resolved URI gives "/some/otherNode#" which is a dangling ref.
Yes, the fact that "id" can be whatever the author wants is a real
headache here.
On Friday, 21 December 2012 23:47:43 UTC, Austin Wright wrote:The algorithm that I laid out I believe is easier to implement: Keeping an internal table of schemas as a map (AbsURI -> Schema), that whenever you lookup a schema from that map, just change your URI base to the looked-up URI. But in any event, the point of a JSON Schema implementation is to do the heavy lifting so the developer doesn't need to.
I think if there is a difference in implementation difficulty, it's not very significant. Francis's method simply requires that schemas keep a reference to the document URI from which they were fetched, and use that for the URI base instead.
No, it's not necessary. Using "id" for fragment resolution, however, is not elegant, and not as flexible. Throw in the fact that Google are mis-using "id", and you can see why we're more keen on JSON Pointer.How does one use the id attribute for fragment resolution? If you want to put fragments in "id" I'd think you can do so (e.g. a schema {"id": "http://example.com/spec#schema"} is legal and referencable), but it's largely unnecessary.
I believe that's the standard way to do fragment resolution in v3 ( {"id": "#someFragment"} ). In fact, until JSON Pointer was introduced in v4, I think this is the only way to do fragment resolution.
I'm afraid I don't quite know what you want. Do you just want the JSON Pointer standard to change, or are you saying you would prefer JSON Schema to define its own fragment resolution scheme (separate from JSON Pointer)?
They'll both go to the same webpage, but they're not (necessarily) the same resource. Tim Berners-Lee's argument that "HTTP URIs (without "#") should be understood as referring to documents, not cars." (I have a slightly different take on the so-called httpRange-14 issue, that cars can have URIs without fragments so long as you use Content-Type negotiation, but I digress, but the point is, <URI> and <URI#> are not necessarily the same resource.)
OK. What practical impact does that have, though? In what situation would a URI with/without a "#" be actually treated differently?
Austin:
The argument you have made for consistency is true for your definition of consistency: if the sub-schema has an absolute URI as its value of "id", then it can be plucked out of its parent schema and used independently.
But there are a few issues I'd like to raise with it.
Firstly: unless I'm misunderstanding something, it still doesn't work if the URI in "id" is in any way relative. If you plucked the sub-schema out and returned it from a different host, then the behaviour is still inconsistent unless "id" is an absolute URI.
Secondly: it complicates the issue of what should be considered the "document". The JSON Reference (the canonical definition of the "$ref" behaviour) states that the URL in "$ref" should be resolved relative to the document. So we have a few options:Obviously (I hope), I think #1 is not a good idea.
- Don't use JSON Reference - in this case, we shouldn't use "$ref", but should think of some other syntax for it.
- We do some shenanigans to define each schema as its own "document"
- We just deal with it, and resolve everything relative to the root document URI.
I think #2 is very confusing, and raises even more problems. If each schema is its own "document", then how can two schemas have the same URI? How can a "document" have a URI with a fragment in it?
So actually, even though I find your interpretation more intuitive than the one currently settled on for draft v4, I think it has problems that the current interpretation does not.
Also, the adoption of a standard fragment resolution scheme for the application/json media type.
On Sat, Dec 22, 2012 at 4:29 PM, Austin Wright
<diamon...@users.sourceforge.net> wrote:
[...]
>
> This would be an even better way to put it: Whenever you reference a schema
> using a URI, you use that (resolved, absolute) URI as its URI base.
>
Again: a schema URI needs _not_ be absolute.
[...]
>> I'm afraid I don't quite know what you want. Do you just want the JSON
>> Pointer standard to change, or are you saying you would prefer JSON Schema
>> to define its own fragment resolution scheme (separate from JSON Pointer)?
>
>
> I'm thinking standardized fragment resolution scheme would be preferable.
> Then objects could formally be referred to outside the context of a JSON
> Schema document.
>
Well, "standardized fragment resolution scheme" is exactly what JSON
Pointer offers. So, that is not really a problem, is it?
I'll repeat again why JSON Pointer was designed the way it is (note, I
am _not_ the spec author): it allows unambiguous, uniform access to
any part of any JSON value, and context-independent encoding. You can
"decode" a JSON Pointer all you want, you'll always obtain the same
pointer. Not so if you use %-encoded escape sequences. JSON is not
linked to HTTP, nor to URI, nor to JavaScript. JSON Pointer has been
designed (successfully) with this in mind.
On Sat, Dec 22, 2012 at 4:47 PM, Austin Wright
<diamon...@users.sourceforge.net> wrote:
[...]
>
> v3 doesn't use JSON Reference so it's not a problem for that specification.
>
Yes it does, albeit a little disguised: consider the json-ref
metaschema. Consider that the core metaschema itself uses it ({
"$ref": "#" }).
The only way in which JSON Reference is not suitable is when
references like { "$ref": "#foo" } are used, and this is why the
current draft v4 text allows this as an extension. It fits what v3 can
do and plain JSON Reference cannot. The only source of disagreement is
the interpretation of "parent" in section 5.23 of draft v3. Looks like
I've lost the battle of it actually meaning "root". I'll post a wrap
up about that.
> I'd look into simply reverting the behavior for v4, or allowing a string to
> define a URI of a schema in place of an object schema (as v3 seems to
> inconsistently do, and v4 separates types like "object" from schemas so
> there's no potential for this to be ambiguous).
>
Sorry, I don't understand this part at all. Can you elaborate? A URI
in JSON _is_ a JSON string. Also, I don't see where "v4 separates
types like "object" from schemas", it only makes the distinction of an
instance (a JSON value being validated) and a schema (a JSON value
which must be an object by definition).
Sure - no problem. However, "$ref"s would still resolve relative to the "referring document" which would be the "root schema" defined in v4.
Although I believe that, if you're using "id", a schema is not uniquely identified by a URI. For example:
{
"id": "http://example.com/schema/",
"definitions": {
"subSchema": {
"id": "http://example.com/schema/subSchema"
}
}
}
The sub-schema there is equally accurately by both "http://example.com/schema/#/definitions/subSchema" and "http://example.com/schema/subSchema".
Also, the adoption of a standard fragment resolution scheme for the application/json media type.
Sure - my favourite candidate is JSON Pointer. I'm weighing up the possibility of removing the "fragmentResolution" property, to encourage the use of JSON Pointer everywhere.
JSON Pointer doesn't adopt the language necessary to make it formal for all application/json documents.
Not being a URI is a bad thing. URIs are a core Web technology. So I'm suggesting that instead of using "~0" "~1" and "%", that JSON Pointer utilize "~" "%2f" and "%25" respectively. Or, adopt a dedicated fragment resolution syntax. I don't see such a URI-less syntax being necessary unless it concerns more complex logic, similar to XPath or XQuery for XML.
"Uniquely identified" meaning, by the URI only, I can resolve to one and exactly one schema. This doesn't preclude that there may be multiple such URIs capable of uniquely identifying the resource.
I'd appreciate the removal of it, fragment resolution is supposed to be media-type wide, not application-defined. So that just leads to needless complexity.
On Sat, Dec 22, 2012 at 5:08 PM, Geraint (David) <gerai...@gmail.com> wrote:
[...]
>
> What? No! The other definition conflicts with the definition of JSON
> Reference. I am not happy changing it unless those are somehow sorted out.
>
It can be worked around if the draft tells that JSON Reference
resolution must be made relative to the uppermost parent URI (that is,
if you trust "id" at all). This would be JSON Schema specific, but
then "id" is specific enough to have stirred this thread and others ;)
[...]
>
> For the first part, I think he's talking about an old syntax where you
> didn't need "$ref", you just stuck the URL in as a string:
> {
> "type": "array",
> "items": "/path/to/some/schema"
> }
> I don't like it, and prefer the $ref syntax.
>
This syntax is not legal as far as draft v3 is concerned, is it? Or I
have really misread the draft. I know that some schemas on the web
site were not up to date with regards to this, but they have been
updated since then.
OK, I guess we have different definitions of an "absolute URI". For
me, an absolute URI is a URI which starts with a scheme, ie
"foo://bar" is absolute but "/foo/bar" isn't.
Sorry but to my eyes it does. Care to give a counter example?
In case it's relevant: have you seen the JSON Patch standard? It uses JSON Pointers in a non-URI context.
For example, let's look at the following data, fetched from "http://example.com/just-some-document/":
From my point of view, the main reason I wanted "$ref"s and so on to be interpreted relative to the immediate parent schema (and not the document root) is because I wanted to be able to have two schemas like so:
Schema 1:
{
"id": "http://example.com/schemas/",
"title": "Some schema",
"type": "array",
"items": {"$ref": "subSchemas/schema2"}
}
Schema 2:
{
"id": "http://example.com/schemas/subSchemas/schema2",
"title": "Some other schema"
"type": "object",
"allOf": [{"$ref": "schema3"}]
}
If we resolve relative to the parent schema, then we could serve up the following, presenting both schemas in one request:
Schema 1b:
{
"id": "http://example.com/schemas/",
"title": "Some schema",
"type": "array",
"items": {
"id": "http://example.com/schemas/subSchemas/schema2",
"title": "Some other schema"
"type": "object",
"allOf": [{"$ref": "schema3"}]
}
}
You can just dump the contents of the other schema in without modification. However, if you were resolving against the root schema, however, you would need to edit the {"$ref": "schema3"} so that it became {"$ref": "subSchemas/schema3"}.
The thing is, although that would be occasionally very convenient, that's a one-off modification, and it's not actually that bad. So the question for me is: how important is it to be able to do that substitution without any modifications to the schema? Is it worth the other issues it would raise (previous message)?
Sorry but to my eyes it does. Care to give a counter example?
This is in the eye of the beholder. While it may seem more simple to
_you_, it may not be so for others.
Again, implementation does not matter, what we want is consistency.
The more I listen to David's argument about "rel", which is a
fundamental feature of hyper schema, the more it seems that even
though I didn't see these aspects, my initial "out-of-the-wild"
decision was the good one.
OK - I mentioned it in the other thread, so I'll explain it here.
The behaviour of "id" is simply the behaviour of a link with relation "self". Similarly, a "$ref" just defines a link with relation "full". So the behaviour we choose for "id"/"$ref" will affect the behaviour of links more generally.