Skip to content

Commit 0c16668

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 1d8963e commit 0c16668

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
@@ -9,6 +9,7 @@
99
<!ENTITY rfc5988 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5988.xml">
1010
<!ENTITY rfc6570 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6570.xml">
1111
<!ENTITY rfc7231 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7231.xml">
12+
<!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">
1213
<!ENTITY I-D.reschke-http-jfv SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-reschke-http-jfv-06.xml">
1314
]>
1415
<?rfc toc="yes"?>
@@ -793,6 +794,91 @@ GET /foo/
793794
</t>
794795
</section>
795796

797+
<section title="anchorPointer" anchor="anchorPointer">
798+
<t>
799+
This property changes the point within the instance that is considered
800+
to be the context resource of the link. The value of the property is a
801+
<xref target="I-D.luff-relative-json-pointer">Relative JSON Pointer</xref>,
802+
starting from the default context (the part of the instance that validated
803+
against the schema containing the LDO).
804+
</t>
805+
<t>
806+
While an alternate context with a known URI is best set with the
807+
"anchor" keyword, the lack of a fragment identifier
808+
syntax for application/json means that it is usually not possible to
809+
change the context within a JSON instance.
810+
</t>
811+
<t>
812+
Even in "+json" media types that define JSON Pointer as a fragment identifier
813+
syntax, if the default context is nested within an array, it is not possible to
814+
obtain the index of the default context's position in that array in order
815+
to construct a pointer to another property in that same nested JSON object.
816+
</t>
817+
818+
<figure>
819+
<preamble>
820+
For example, given this hyper-schema:
821+
</preamble>
822+
<artwork>
823+
<![CDATA[{
824+
"type": "object",
825+
"properties": {
826+
"theThing": {
827+
"type": "object",
828+
"properties": {
829+
"name": {"type": "string"}
830+
}
831+
},
832+
"examples": {
833+
"title": "The collection of example for the thing",
834+
"type": "array",
835+
"items": {
836+
"type": "object",
837+
"properties": {
838+
"id": {"type": "integer"}
839+
},
840+
"links": [{
841+
"rel": "item",
842+
"href": "/examples/{id}",
843+
"anchorPointer": "1"
844+
}]
845+
}
846+
}
847+
}
848+
}]]>
849+
</artwork>
850+
<postamble>
851+
The "item" relation indicates that each array entry can be used to construct
852+
a link from the collection embedded in this instance to a resource for that
853+
specific item. The default context of this link is the individual array
854+
element. But the context of an "item" relation should be the collection,
855+
which is the entire "examples" array. The Relative JSON Pointer of "1"
856+
accomplishes this as follows:
857+
</postamble>
858+
</figure>
859+
<figure>
860+
<preamble>
861+
Given this instance of media type application/json:
862+
</preamble>
863+
<artwork>
864+
<![CDATA[{
865+
"theThing": {"name": "An actual thing"},
866+
"examples": [{"id": 1234}, {"id": 5678}]
867+
}]]>
868+
</artwork>
869+
<postamble>
870+
The default context for the link to "/examples/1234" is the first
871+
array entry, and for the link to "/examples/5678" it is the second array
872+
entry. But "anchorPointer" moves this up one instance level (the "1"
873+
Relative JSON Pointer) to be the array containing each entry.
874+
</postamble>
875+
</figure>
876+
<t>
877+
If both "anchor" and "anchorPointer" are defined, and do not resolve to
878+
the same link context, the resulting behavior is undefined.
879+
</t>
880+
</section>
881+
796882
<section title="title">
797883
<t>
798884
This property defines a title for the link.
@@ -1190,6 +1276,7 @@ GET /foo/
11901276
&rfc3986;
11911277
<!--&rfc4287;-->
11921278
&rfc6570;
1279+
&I-D.luff-relative-json-pointer;
11931280
&I-D.reschke-http-jfv;
11941281
<reference anchor="json-schema">
11951282
<front>

0 commit comments

Comments
 (0)