Skip to content

Commit e40b252

Browse files
committed
Add "anchorPointer" for in-instance contexts
This will need a bit more work after "anchor" is merged in, as the improved wording about what the default context is is all in that other PR. But the key points are well enough developed for review. In the interst of getting the main points out for review, I referenced the long-expired Relative JSON Pointer I-D. Maybe that's OK since this is not even a working group document yet, or we can talk about how to either move the relevant parts in, or re-submit that I-D ourselves as well. This goes along with "hrefPointers", which adjusts template variable resolution in the same way that this keyword adjusts context location.
1 parent a426f3a commit e40b252

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

jsonschema-hyperschema.xml

+87
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<!ENTITY rfc5988 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5988.xml">
1111
<!ENTITY rfc6570 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6570.xml">
1212
<!ENTITY rfc7231 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7231.xml">
13+
<!ENTITY I-D.luff-relative-json-pointer SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-luff-relative-json-pointer-00.xml">
1314
]>
1415
<?rfc toc="yes"?>
1516
<?rfc symrefs="yes"?>
@@ -906,6 +907,91 @@ GET /foo/
906907
</t>
907908
</section>
908909

910+
<section title="anchorPointer" anchor="anchorPointer">
911+
<t>
912+
This property changes the point within the instance that is considered
913+
to be the context resource of the link. The value of the property is a
914+
<xref target="I-D.luff-relative-json-pointer">Relative JSON Pointer</xref>,
915+
starting from the default context (the part of the instance that validated
916+
against the schema containing the LDO).
917+
</t>
918+
<t>
919+
While an alternate context with a known URI is best set with the
920+
"anchor" keyword, the lack of a fragment identifier
921+
syntax for application/json means that it is usually not possible to
922+
change the context within a JSON instance.
923+
</t>
924+
<t>
925+
Even in "+json" media types that define JSON Pointer as a fragment identifier
926+
syntax, if the default context is nested within an array, it is not possible to
927+
obtain the index of the default context's position in that array in order
928+
to construct a pointer to another property in that same nested JSON object.
929+
</t>
930+
931+
<figure>
932+
<preamble>
933+
For example, given this hyper-schema:
934+
</preamble>
935+
<artwork>
936+
<![CDATA[{
937+
"type": "object",
938+
"properties": {
939+
"theThing": {
940+
"type": "object",
941+
"properties": {
942+
"name": {"type": "string"}
943+
}
944+
},
945+
"examples": {
946+
"title": "The collection of example for the thing",
947+
"type": "array",
948+
"items": {
949+
"type": "object",
950+
"properties": {
951+
"id": {"type": "integer"}
952+
},
953+
"links": [{
954+
"rel": "item",
955+
"href": "/examples/{id}",
956+
"anchorPointer": "1"
957+
}]
958+
}
959+
}
960+
}
961+
}]]>
962+
</artwork>
963+
<postamble>
964+
The "item" relation indicates that each array entry can be used to construct
965+
a link from the collection embedded in this instance to a resource for that
966+
specific item. The default context of this link is the individual array
967+
element. But the context of an "item" relation should be the collection,
968+
which is the entire "examples" array. The Relative JSON Pointer of "1"
969+
accomplishes this as follows:
970+
</postamble>
971+
</figure>
972+
<figure>
973+
<preamble>
974+
Given this instance of media type application/json:
975+
</preamble>
976+
<artwork>
977+
<![CDATA[{
978+
"theThing": {"name": "An actual thing"},
979+
"examples": [{"id": 1234}, {"id": 5678}]
980+
}]]>
981+
</artwork>
982+
<postamble>
983+
The default context for the link to "/examples/1234" is the first
984+
array entry, and for the link to "/examples/5678" it is the second array
985+
entry. But "anchorPointer" moves this up one instance level (the "1"
986+
Relative JSON Pointer) to be the array containing each entry.
987+
</postamble>
988+
</figure>
989+
<t>
990+
If both "anchor" and "anchorPointer" are defined, and do not resolve to
991+
the same link context, the resulting behavior is undefined.
992+
</t>
993+
</section>
994+
909995
<section title="title">
910996
<t>
911997
This property defines a title for the link.
@@ -1227,6 +1313,7 @@ GET /foo/
12271313
&rfc3986;
12281314
<!--&rfc4287;-->
12291315
&rfc6570;
1316+
&I-D.luff-relative-json-pointer;
12301317
<reference anchor="json-schema">
12311318
<front>
12321319
<title>JSON Schema: A Media Type for Describing JSON Documents</title>

0 commit comments

Comments
 (0)