@@ -1731,7 +1731,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
1731
1731
},
1732
1732
"email": false
1733
1733
}
1734
- }
1734
+ },
1735
1735
"submissionMediaType":
1736
1736
"multipart/alternative; boundary=ab2",
1737
1737
"submissionSchema": {
@@ -1802,10 +1802,106 @@ Link: <https://schema.example.com/entry> rel=describedBy
1802
1802
</list >
1803
1803
</t >
1804
1804
</section >
1805
- <section title =' "anchor" and "base" as URI Templates' >
1806
- <t ><cref >
1807
- "base" used as a template with both "anchor" and "href" templates.
1808
- </cref ></t >
1805
+ <section title =' "anchor", "base" and URI Template resolution' >
1806
+ <t >
1807
+ A link is a typed connection from a context resource to a target resource.
1808
+ Older link serializations support a "rev" keyword that takes a link relation
1809
+ type as "rel" does, but reverses the semantics. This has long been deprecated,
1810
+ so JSON Hyper-Schema does not support it. Instead, "anchor"'s ability to
1811
+ change the context URI can be used to reverse the direction of a link.
1812
+ It can also be used to describe a link between two resources, neither of
1813
+ which is the current resource.
1814
+ </t >
1815
+ <t >
1816
+ As an example, there is an IANA-registered "up" relation, but
1817
+ there is no "down". In an HTTP Link header, you could implement
1818
+ "down" as <spanx style =" verb" >"rev": "up"</spanx >.
1819
+ </t >
1820
+ <figure >
1821
+ <preamble >
1822
+ First let's look at how this could be done in HTTP, showing a "self"
1823
+ link and two semantically identical links, one with "rev": "up"
1824
+ and the other using "anchor" with "rel": "up" (line wrapped due to
1825
+ formatting limitations).
1826
+ </preamble >
1827
+ <artwork >
1828
+ <![CDATA[
1829
+ GET https://api.example.com/trees/1/nodes/123 HTTP/1.1
1830
+
1831
+ 200 OK
1832
+ Content-Type: application/json
1833
+ Link: <https://api.example.com/trees/1/nodes/123> rel=self
1834
+ Link: <https://api.example.com/trees/1/nodes/123> rel=up
1835
+ anchor=<https://api.example.com/trees/1/nodes/456>
1836
+ Link: <https://api.example.com/trees/1/nodes/456> rev=up
1837
+ {
1838
+ "id": 123
1839
+ "treeId": 1,
1840
+ "childIds": [456]
1841
+ }
1842
+ ]]>
1843
+ </artwork >
1844
+ <postamble >
1845
+ Note that the "rel=up" link has a target URI identical
1846
+ to the "rel=self" link, and sets "anchor" (which identifies
1847
+ the link's context) to the child's URI. This sort of reversed
1848
+ link is easily detectable by tools when a "self" link is also present.
1849
+ </postamble >
1850
+ </figure >
1851
+
1852
+ <figure >
1853
+ <preamble >
1854
+ The following hyper-schema, applied to the instance in the response
1855
+ above, would produce the same "self" link and "up" link with "anchor".
1856
+ It also shows the use of a templated "base" URI, plus both absolute
1857
+ and relative JSON Pointers in "tempaltePointers".
1858
+ </preamble >
1859
+ <artwork >
1860
+ <![CDATA[
1861
+ "base": "trees/{treeId}",
1862
+ "properties": {
1863
+ "id": {"type": "integer"},
1864
+ "treeId": {"type": "integer"},
1865
+ "childIds": {
1866
+ "type": "array",
1867
+ "items": {
1868
+ "type": "integer",
1869
+ "links": [
1870
+ {
1871
+ "anchor": "nodes/{thisNodeId}",
1872
+ "rel": "up",
1873
+ "href": "nodes/{childId}",
1874
+ "templatePointers": {
1875
+ "thisNodeId": "/id",
1876
+ "childId": "0"
1877
+ }
1878
+ }
1879
+ ]
1880
+ }
1881
+ }
1882
+ },
1883
+ "links": [
1884
+ {
1885
+ "rel": "self",
1886
+ "href": "nodes/{id}"
1887
+ }
1888
+ ]
1889
+ }]]>
1890
+ </artwork >
1891
+ <postamble >
1892
+ The "base" template is evaluated identically for both the
1893
+ target ("href") and context ("anchor") URIs.
1894
+ </postamble >
1895
+ </figure >
1896
+ <t >
1897
+ Note the two different sorts of templatePointers used.
1898
+ "thisNodeId" is mapped to an absolute JSON Pointer, "/id",
1899
+ while "childId" is mapped to a relative pointer, "0", which
1900
+ indicates the value of the current item. Absolute
1901
+ JSON Pointers do not support any kind of wildcarding, so
1902
+ there is no way to specify a concept like "current item"
1903
+ without a relative JSON Pointer.
1904
+ </t >
1809
1905
</section >
1810
1906
<section title =" Collections" >
1811
1907
<t ><cref >
@@ -1829,8 +1925,8 @@ Link: <https://schema.example.com/entry> rel=describedBy
1829
1925
</t >
1830
1926
<t >
1831
1927
Note that there is an object member called "items", which is an array
1832
- and thefore uses the validation keyword "items" in its own schema. The outer
1833
- "items" is a property name, the inner one is a schema keyword.
1928
+ and therefore uses the validation keyword "items" in its own schema.
1929
+ The outer "items" is a property name, the inner one is a schema keyword.
1834
1930
</t >
1835
1931
<figure >
1836
1932
<artwork >
@@ -1951,7 +2047,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
1951
2047
Here are all of the links that apply to this instance,
1952
2048
including those that are referenced by using the "thing"
1953
2049
schema for the individual items. The "self" links for
1954
- the overal resource and each individual item are
2050
+ the overall resource and each individual item are
1955
2051
distinguished by different context pointers. Note also
1956
2052
that the "item" and "self" links for a given thing have
1957
2053
identical target URIs but different context pointers.
@@ -1962,14 +2058,16 @@ Link: <https://schema.example.com/entry> rel=describedBy
1962
2058
"contextUri": "https://api.example.com/things",
1963
2059
"contextPointer": "",
1964
2060
"rel": "self",
1965
- "targetUri": "https://api.example.com/things?offset=20,limit=2",
2061
+ "targetUri":
2062
+ "https://api.example.com/things?offset=20,limit=2",
1966
2063
"attachmentPointer": ""
1967
2064
},
1968
2065
{
1969
2066
"contextUri": "https://api.example.com/things",
1970
2067
"contextPointer": "",
1971
2068
"rel": "next",
1972
- "targetUri": "https://api.example.com/things?offset=22,limit=2",
2069
+ "targetUri":
2070
+ "https://api.example.com/things?offset=22,limit=2",
1973
2071
"attachmentPointer": ""
1974
2072
},
1975
2073
{
0 commit comments