1

An excerpt from http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.2.4

{
    "$id": "http://example.com/root.json",
    "definitions": {
        "A": { "$id": "#foo" },
        "B": {
            "$id": "other.json",
            "definitions": {
                "X": { "$id": "#bar" },
                "Y": { "$id": "t/inner.json" }
            }
        },
        "C": {
            "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
        }
    }
}

The schemas at the following URI-encoded JSON Pointers [RFC6901] (relative to the root schema) have the following base URIs, and are identifiable by any listed URI in accordance with Section 5 above:

...
#/definitions/B/definitions/X
        http://example.com/other.json#bar
        http://example.com/other.json#/definitions/X
        http://example.com/root.json#/definitions/B/definitions/X
...

Why isn't http://example.com/root.json#bar a valid base URI for #/definitions/B/definitions/X?

Relequestual
  • 11,631
  • 6
  • 47
  • 83
Matt Wlazlo
  • 157
  • 2
  • 7
  • I notice you also posted the same question on the JSON Schema Google Group (which I approved). You are more likely to get answers by posting here, as the community activly monitors and is alerted to the `jsonschema` tag. – Relequestual Oct 12 '18 at 08:28

1 Answers1

2

http://example.com/root.json#bar would not be resolveable with the given schema.

Think of it like anchors in HTML. $id is like defining a new page, so the location of #/definitions/B falls under "the page" $other.json, hence http://example.com/other.json#bar in the list you included that are equivilents for #/definitions/B/definitions/X.

If you create an HTML page which is at http://example.com/root.json, and try to click a link which is #bar, it would not find the # location because it's on the other.json page.

Please let me know if any of this doesn't make sense or is confusing.

Relequestual
  • 11,631
  • 6
  • 47
  • 83
  • I think it's confusing because $id is used to set the base URI for a set of sub-schemas, while at the same time being used for "location independent identifiers". I guess they are not so independent though, since they must remain under the same base URI, and can only be referenced in relation to the top-most base URI (in this case other.json), correct? – Matt Wlazlo Oct 12 '18 at 11:04
  • Location-independent identifiers work similar to HTML elements with ids. It's called location-independent because you don't need to provide a full tree based address, and can address the element directly. Location dependent or otherwise, the id is still effected by the the base URI. They are location-independent with relation to the closest base URI, not the top-most. Does that make sense? (I'm not sure I fully understood your comment, but I'm trying to cover areas I think you're trying to understand here) – Relequestual Oct 12 '18 at 12:08
  • Base URI <-> LII relationship is what I was after, thanks for clearing that up. Cheers. :-) – Matt Wlazlo Oct 12 '18 at 20:36