Skip to content

Commit a3de90a

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 a560f8b commit a3de90a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

jsonschema-hyperschema.xml

Lines changed: 87 additions & 0 deletions
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"?>
@@ -883,6 +884,91 @@ GET /foo/
883884
</section>
884885
</section>
885886

887+
<section title="anchorPointer" anchor="anchorPointer">
888+
<t>
889+
This property changes the point within the instance that is considered
890+
to be the context resource of the link. The value of the property is a
891+
<xref target="I-D.luff-relative-json-pointer">Relative JSON Pointer</xref>,
892+
starting from the default context (the part of the instance that validated
893+
against the schema containing the LDO).
894+
</t>
895+
<t>
896+
While an alternate context with a known URI is best set with the
897+
"anchor" keyword, the lack of a fragment identifier
898+
syntax for application/json means that it is usually not possible to
899+
change the context within a JSON instance.
900+
</t>
901+
<t>
902+
Even in "+json" media types that define JSON Pointer as a fragment identifier
903+
syntax, if the default context is nested within an array, it is not possible to
904+
obtain the index of the default context's position in that array in order
905+
to construct a pointer to another property in that same nested JSON object.
906+
</t>
907+
908+
<figure>
909+
<preamble>
910+
For example, given this hyper-schema:
911+
</preamble>
912+
<artwork>
913+
<![CDATA[{
914+
"type": "object",
915+
"properties": {
916+
"theThing": {
917+
"type": "object",
918+
"properties": {
919+
"name": {"type": "string"}
920+
}
921+
}},
922+
"examples": {
923+
"title": "The collection of example for the thing",
924+
"type": "array",
925+
"items": {
926+
"type": "object",
927+
"properties": {
928+
"id": {"type": "integer"}
929+
},
930+
"links": [{
931+
"rel": "item"
932+
"href": "/examples/{id}",
933+
"anchorPointer": "1"
934+
}]
935+
}
936+
}
937+
}
938+
}]]>
939+
</artwork>
940+
<postamble>
941+
The "item" relation indicates that each array entry can be used to construct
942+
a link from the collection embedded in this instance to a resource for that
943+
specific item. The default context of this link is the individual array
944+
element. But the context of an "item" relation should be the collection,
945+
which is the entire "examples" array. The Relative JSON Pointer of "1"
946+
accomplishes this as follows:
947+
</postamble>
948+
</figure>
949+
<figure>
950+
<preamble>
951+
Given this instance of media type application/json:
952+
</preamble>
953+
<artwork>
954+
<![CDATA[{
955+
"theThing": {"name": "An actual thing"},
956+
"examples": [{"id": 1234}, {"id": 5678}]
957+
}]]>
958+
</artwork>
959+
<postamble>
960+
The default context for the the link to "/example/1234" is the first
961+
array entry, and for the link to "/example/5678" it is the second array
962+
entry. But "anchorPointer" moves this up one instance level (the "1"
963+
Relative JSON Pointer) to be the array containing each entry.
964+
</postamble>
965+
</figure>
966+
<t>
967+
If both "anchor" and "anchorPointer" are defined, and do not resolve to
968+
the same link context, the resulting behavior is undefined.
969+
</t>
970+
</section>
971+
886972
<section title="title">
887973
<t>
888974
This property defines a title for the link.
@@ -1189,6 +1275,7 @@ GET /foo/
11891275
&rfc3986;
11901276
<!--&rfc4287;-->
11911277
&rfc6570;
1278+
&I-D.luff-relative-json-pointer;
11921279
<reference anchor="json-schema">
11931280
<front>
11941281
<title>JSON Schema: A Media Type for Describing JSON Documents</title>

0 commit comments

Comments
 (0)