Resolve a relative embedded meta-schema identifier against its base

VA
1d ago
+543-103

A document whose $schema names a meta-schema it embeds fails when that embedded resource declares a relative $id:

{
  "$schema": "https://example.com/meta",
  "$id": "https://example.com/schema",
  "definitions": {
    "m": { "$id": "meta", "$schema": "http://json-schema.org/draft-07/schema#" }
  }
}

meta resolves against the root base to https://example.com/meta, exactly what $schema names, but it throws Could not resolve the metaschema of the schema. Writing the $id absolutely works, and the same relative $id used as a $ref target already resolves correctly.

An embedded resource's identifier is a URI reference, so a relative one must be resolved against the base of the embedding document. The matcher only compared it raw and canonicalised.

Two sites consult that matcher: embedded_metaschema_candidate finds the resource, and embedded_metaschema_link_valid re-checks each link afterwards, reaching the matcher directly. Fixing only the first still fails, as the second rejects what it just found. Both now take a base computed once in metaschema_try_embedded. Only relative identifiers are resolved, so an absolute one under a different base cannot match.

Tests cover Draft 4, 6 and 7, a nested resource whose base is not the root, and the framing path, plus regressions for the absolute spelling, the $ref path, and a wrong base.