forked from json-schema-org/json-schema-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonschema-hyperschema.xml
1071 lines (972 loc) · 51.6 KB
/
jsonschema-hyperschema.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY rfc2045 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2045.xml">
<!ENTITY rfc2046 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2046.xml">
<!ENTITY rfc2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY rfc3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
<!ENTITY rfc4287 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4287.xml">
<!ENTITY rfc5226 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5226.xml">
<!ENTITY rfc5988 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5988.xml">
<!ENTITY rfc6570 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6570.xml">
<!ENTITY rfc7231 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7231.xml">
<!ENTITY html401 SYSTEM "http://xml.resource.org/public/rfc/bibxml4/reference.W3C.REC-html401-19991224.xml">
]>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc strict="no"?>
<?rfc rfcedstyle="yes"?>
<rfc category="info" docName="draft-luff-json-hyper-schema-01" ipr="trust200902">
<front>
<title abbrev="JSON Hyper-Schema">JSON Hyper-Schema: Hypertext definitions for JSON Schema</title>
<author fullname="Geraint Luff" initials="G" surname="Luff" role="editor">
<address>
<postal>
<street></street>
<city>Cambridge</city>
<country>UK</country>
</postal>
<email>[email protected]</email>
</address>
</author>
<author fullname="Kris Zyp" initials="K" surname="Zyp">
<organization>SitePen (USA)</organization>
<address>
<postal>
<street>530 Lytton Avenue</street>
<city>Palo Alto, CA 94301</city>
<country>USA</country>
</postal>
<phone>+1 650 968 8787</phone>
<email>[email protected]</email>
</address>
</author>
<author fullname="Gary Court" initials="G" surname="Court">
<address>
<postal>
<street></street>
<city>Calgary, AB</city>
<country>Canada</country>
</postal>
<email>[email protected]</email>
</address>
</author>
<date year="2016" />
<workgroup>Internet Engineering Task Force</workgroup>
<keyword>JSON</keyword>
<keyword>Schema</keyword>
<keyword>JavaScript</keyword>
<keyword>Object</keyword>
<keyword>Notation</keyword>
<keyword>Hyper Schema</keyword>
<keyword>Hypermedia</keyword>
<abstract>
<t>
JSON Schema is a JSON based format for defining the structure of JSON data.
This document specifies hyperlink- and hypermedia-related keywords of JSON Schema.
</t>
</abstract>
</front>
<middle>
<section title="Introduction">
<t>
JSON Schema is a JSON based format for defining the structure of JSON data.
This document specifies hyperlink- and hypermedia-related keywords of JSON Schema.
</t>
<t>
The term JSON Hyper-Schema is used to refer to a JSON Schema that uses these keywords.
</t>
<t>
This specification will use the terminology defined by the <xref target="json-schema-core">JSON Schema core
specification</xref>. It is advised that readers have a copy of this specification.
</t>
</section>
<section title="Conventions and Terminology">
<t>
<!-- The text in this section has been copied from the official boilerplate,
and should not be modified.-->
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
interpreted as described in <xref target="RFC2119">RFC 2119</xref>.
</t>
<t>
The terms "schema", "instance", "property" and "item" are to be interpreted as defined in the <xref target="json-schema-core">JSON Schema core
specification</xref>.
</t>
</section>
<section title="Overview">
<t>
This document describes how JSON Schema can be used to define hyperlinks on instance data. It also defines how to provide additional information required to interpret JSON data as rich multimedia documents.
</t>
<t>
Just as with the core JSON schema keywords, all the keywords described in the "Schema Keywords" section are optional.
</t>
<figure>
<preamble>Here is an example JSON Schema defining hyperlinks, and providing a multimedia interpretation for the "imgData" property:</preamble>
<artwork>
<![CDATA[
{
"title": "Written Article",
"type": "object",
"properties": {
"id": {
"title": "Article Identifier",
"type": "number"
},
"title": {
"title": "Article Title",
"type": "string"
},
"authorId": {
"type": "integer"
},
"imgData": {
"title": "Article Illustration (small)",
"type": "string",
"media": {
"binaryEncoding": "base64",
"type": "image/png"
}
}
},
"required" : ["id", "title", "authorId"],
"links": [
{
"rel": "full",
"href": "{id}"
},
{
"rel": "author",
"href": "/user?id={authorId}"
}
]
}
]]>
</artwork>
<postamble>
This example schema defines the properties of the instance.
For the "imgData" property, it specifies that that it should be base64-decoded and the resulting binary data treated as a PNG image.
It also defines link relations for the instance, with URIs incorporating values from the instance.
</postamble>
</figure>
<figure>
<preamble>An example of a JSON instance described by the above schema might be:</preamble>
<artwork>
<![CDATA[
{
"id": 15,
"title": "Example data",
"authorId": 105,
"imgData": "iVBORw...kJggg=="
}
]]>
</artwork>
<postamble>The base-64 data has been abbreviated for readability.</postamble>
</figure>
<section title="Design Considerations">
<t>
The purpose of this document is to define keywords for the JSON Schema that allow JSON data to be understood as hyper-text.
</t>
<t>
JSON data on its own requires special knowledge from the client about the format in order to be interpretable as hyper-text.
This document proposes a way to describe the hyper-text and hyper-media interpretation of such JSON formats, without defining reserved keywords or otherwise restricting the structure of the JSON data.
</t>
</section>
</section>
<section title="Schema keywords">
<section title="links">
<t>
The "links" property of schemas is used to associate Link Description Objects with instances. The value of this property MUST be an array, and the items in the array must be Link Description Objects, as defined below.
</t>
<figure>
<preamble>An example schema using the "links" keyword could be:</preamble>
<artwork>
<![CDATA[{
"title": "Schema defining links",
"links": [
{
"rel": "full",
"href": "{id}"
},
{
"rel": "parent",
"href": "{parent}"
}
]
}]]>
</artwork>
</figure>
<section title="Multiple links per URI">
<t>
A single URI might have more than one role with relation to an instance. This is not a problem - the same URI can be used in more than one Link Description Object.
</t>
<figure>
<preamble>
For example, this schema describes a format for blog posts, accessed via HTTP.
The links describe how to access the comments for the post, how to search the comments, and how to submit new comments, all with the same URI:</preamble>
<artwork>
<![CDATA[{
"title": "News post",
...
"links": [
{
"rel": "comments",
"href": "/{id}/comments"
},
{
"rel": "search",
"href": "/{id}/comments",
"schema": {
"type": "object",
"properties": {
"searchTerm": {
"type": "string"
},
"itemsPerPage": {
"type": "integer",
"minimum": 10,
"multipleOf": 10,
"default": 20
}
},
"required": ["searchTerm"]
}
},
{
"title": "Post a comment",
"rel": "create",
"href": "/{id}/comments",
"method": "POST",
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": ["message"]
}
}
]
}]]>
</artwork>
</figure>
<t>
If the client follows the first link, the URI might be expanded to "/15/comments".
For the second link, the method is "GET" (the default for HTTP) so a client following this link would add the parameters to the URL to produce something like: "/15/comments?searchTerm=JSON&itemsPerPage=50".
The third link defines a possible interaction where a client would POST to a URI (such as "/15/comments"), where the post-data was a JSON representation of the new comment, for example:
</t>
<figure>
<artwork>
<![CDATA[{
"message": "This is an example comment"
}]]>
</artwork>
</figure>
</section>
</section>
<section title="fragmentResolution">
<t>
When addressing a JSON document, the fragment part of the URI may be used to refer to a particular instance within the document.
</t>
<t>
This keyword indicates the method to use for finding the appropriate instance within a document, given the fragment part.
The default fragment resolution protocol is "json-pointer", which is defined below.
Other fragment resolution protocols MAY be used, but are not defined in this document.
</t>
<t>
If the instance is described by a schema providing the a link with "root" relation, or such a link is provided in using the <xref target="RFC5988">HTTP Link header</xref>, then the target of the "root" link should be considered the document root for the purposes of all fragment resolution methods that use the document structure (such as "json-pointer").
The only exception to this is the resolution of "root" links themselves.
</t>
<section title="json-pointer fragment resolution">
<t>
The "json-pointer" fragment resolution protocol uses a <xref target="json-pointer">JSON Pointer</xref> to resolve fragment identifiers in URIs within instance representations.
</t>
</section>
</section>
<section title="media">
<t>
The "media" property indicates that this instance contains non-JSON data encoded in a JSON string. It describes the type of content and how it is encoded.
</t>
<t>
The value of this property MUST be an object, and SHOULD be ignored for any instance that is not a string.
</t>
<section title="Properties of "media"">
<t>
The value of the "media" keyword MAY contain any of the following properties:
</t>
<section title="binaryEncoding">
<t>
If the instance value is a string, this property defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this property.
<xref target="RFC2045">RFC 2045, Sec 6.1</xref> lists the possible values for this property.
</t>
</section>
<section title="type">
<t>
The value of this property must be a media type, as defined by <xref target="RFC2046">RFC 2046</xref>.
This property defines the media type of instances which this schema defines.
</t>
<t>
If the "binaryEncoding" property is not set, but the instance value is a string, then the value of this property SHOULD specify a text document type, and the character set SHOULD be the character set into which the JSON string value was decoded (for which the default is Unicode).
</t>
</section>
</section>
<section title="Example">
<figure>
<preamble>Here is an example schema, illustrating the use of "media":</preamble>
<artwork>
<![CDATA[
{
"type": "string",
"media": {
"binaryEncoding": "base64",
"type": "image/png"
}
}
]]>
</artwork>
<postamble>Instances described by this schema should be strings, and their values should be interpretable as base64-encoded PNG images.</postamble>
</figure>
<figure>
<preamble>Another example:</preamble>
<artwork>
<![CDATA[
{
"type": "string",
"media": {
"mediaType": "text/html"
}
}
]]>
</artwork>
<postamble>Instances described by this schema should be strings containing HTML, using whatever character set the JSON string was decoded into (default is Unicode).</postamble>
</figure>
</section>
</section>
<section title="readOnly">
<t>
If it has a value of boolean true, this keyword indicates that the instance property SHOULD NOT be changed, and attempts by a user agent to modify the value of this property are expected to be rejected by a server.
</t>
<t>
The value of this keyword MUST be a boolean.
The default value is false.
</t>
</section>
<section title="pathStart">
<t>
This property is a URI that defines what the instance's URI MUST start with in order to validate.
The value of the "pathStart" property MUST be resolved relative to the current URI base (as defined in the <xref target="json-schema-core">JSON Schema core specification</xref>), using the rules from <xref target="RFC3986">RFC 3986, Sec 5</xref>.
</t>
<t>
When multiple schemas have been referenced for an instance, the user agent can determine if this schema is applicable for a particular instance by determining if the URI of the instance begins with the the value of the "pathStart" property.
If the URI of the instance does not start with this URI, or if another schema specifies a starting URI that is longer and also matches the instance, this schema SHOULD NOT be considered to describe the instance.
Any schema that does not have a pathStart property SHOULD be considered applicable to all the instances for which it is referenced.
</t>
</section>
</section>
<section title="Link Description Object">
<t>
A Link Description Object (LDO) is used to describe a single link relation.
In the context of a schema, it defines the link relations of the instances of the schema, and can be parameterized by the instance values.
A Link Description Object (LDO) must be an object.
</t>
<t>
The link description format can be used without JSON Schema, and use of this format can be declared by referencing the normative link description schema as the schema for the data structure that uses the links.
The URI of the normative link description schema is: <eref target="http://json-schema.org/links">http://json-schema.org/links</eref> (latest version) or <eref target="http://json-schema.org/draft-04/links">http://json-schema.org/draft-04/links</eref> (draft-04 version).
</t>
<t>
"Form"-like functionality can be defined by use of the "schema" keyword, which supplies a schema describing the data to supply to the server.
</t>
<section title="href" anchor="href">
<t>
The value of the "href" link description property is a template used to determine the target URI of the related resource.
The value of the instance property SHOULD be resolved as a URI-Reference per <xref target="RFC3986">RFC 3986</xref> and MAY be a URI reference.
The base URI to be used for relative URI resolution SHOULD be the URI used to retrieve the instance object (not the schema).
</t>
<t>
The base URI to be used for relative URI resolution SHOULD is defined as follows:
<list>
<t>if the data has a link defined, with a relation of "self", then the "href" value of that link is used, unless the relation of the link being resolved is also "self"</t>
<t>otherwise, the URI should be resolved against the link with relation "self" belonging to the closest parent node in the JSON document, if it exists</t>
<t>otherwise, the URI used to fetch the document should be used.</t>
</list>
</t>
<t>This property is not optional.</t>
<section title="URI Templating">
<t>
The value of "href" is to be used as a URI Template, as defined in <xref target="RFC6570">RFC 6570</xref>. However, some special considerations apply:
</t>
<section title="Pre-processing">
<t>
The <xref target="RFC6570">URI Template specification</xref> restricts the set of characters available for variable names.
Property names in JSON, however, can be any UTF-8 string.
</t>
<t>
To allow the use of any JSON property name in the template, before using the value of "href" as a URI Template, the following pre-processing rules MUST be applied, in order:
</t>
<section title="Bracket escaping">
<t>
The purpose of this step is to allow the use of brackets to percent-encode variable names inside curly brackets.
Variable names to be escaped are enclosed within rounded brackets, with the close-rounded-bracket character ")" being escaped as a pair of close-rounded-brackets "))".
Since the empty string is not a valid variable name in RFC 6570, an empty pair of brackets is replaced with "%65mpty".
</t>
<t>
The rules are as follows:
</t>
<t>
Find the largest possible sections of the text such that:
<list>
<t>do not contain an odd number of close-rounded-bracket characters ")" in sequence in that section of the text</t>
<t>are surrounded by a pair of rounded brackets: ( ), where</t>
<t>the surrounding rounded brackets are themselves contained within a pair of curly brackets: { }</t>
</list>
</t>
<t>
Each of these sections of the text (including the surrounding rounded brackets) MUST be replaced, according to the following rules:
<list>
<t>If the brackets contained no text (the empty string), then they are replaced with "%65mpty" (which is "empty" with a percent-encoded "e")</t>
<t>Otherwise, the enclosing brackets are removed, and the inner text used after the following modifications
<list>
<t>all pairs of close-brackets "))" are replaced with a single close bracket</t>
<t>after that, the text is replaced with its percent-encoded equivalent, such that the result is a valid RFC 6570 variable name (note that this requires encoding characters such as "*" and "!")</t>
</list>
</t>
</list>
</t>
</section>
<section title="Replacing $">
<t>
After the above substitutions, if the character "$" (dollar sign) appears within a pair of curly brackets, then it MUST be replaced with the text "%73elf" (which is "self" with a percent-encoded "s").
</t>
<t>
The purpose of this stage is to allow the use of the instance value itself (instead of its object properties or array items) in the URI Template, by the special value "%73elf".
</t>
</section>
<section title="Choice of special-case values">
<t>
The special-case values of "%73elf" and "%65mpty" were chosen because they are unlikely to be accidentally generated by either a human or automated escaping.
</t>
</section>
<section title="Examples">
<t>
<figure>
<preamble>For example, here are some possible values for "href", followed by the results after pre-processing:</preamble>
<artwork>
<![CDATA[
Input Output
-----------------------------------------
"no change" "no change"
"(no change)" "(no change)"
"{(escape space)}" "{escape%20space}"
"{(escape+plus)}" "{escape%2Bplus}"
"{(escape*asterisk)}" "{escape%2Aasterisk}"
"{(escape(bracket)}" "{escape%28bracket}"
"{(escape))bracket)}" "{escape%29bracket}"
"{(a))b)}" "{a%29b}
"{(a (b)))}" "{a%20%28b%29}
"{()}" "{%65mpty}
"{+$*}" "{+%73elf*}
"{+($)*}" "{+%24*}
]]>
</artwork>
<postamble>
Note that in the final example, because the "+" was outside the brackets, it remained unescaped, whereas in the fourth example the "+" was escaped.
</postamble>
</figure>
</t>
</section>
</section>
<section title="Values for substitution">
<t>
After pre-processing, the URI Template is filled out using data from the instance.
To allow the use of any object property (including the empty string), array index, or the instance value itself, the following rules are defined:
</t>
<t>
For a given variable name in the URI Template, the value to use is determined as follows:
<list>
<t>If the variable name is "%73elf", then the instance value itself MUST be used.</t>
<t>If the variable name is "%65mpty", then the instances's empty-string ("") property MUST be used (if it exists).</t>
<t>If the instance is an array, and the variable name is a representation of a non-negative integer, then the value at the corresponding array index MUST be used (if it exists).</t>
<t>Otherwise, the variable name should be percent-decoded, and the corresponding object property MUST be used (if it exists).</t>
</list>
</t>
<section title="Converting to strings">
<t>
When any value referenced by the URI template is null, a boolean or a number, then it should first be converted into a string as follows:
<list>
<t>null values SHOULD be replaced by the text "null"</t>
<t>boolean values SHOULD be replaced by their lower-case equivalents: "true" or "false"</t>
<t>numbers SHOULD be replaced with their original JSON representation.</t>
</list>
</t>
<t>
In some software environments the original JSON representation of a number will not be available (there is no way to tell the difference between 1.0 and 1), so any reasonable representation should be used.
Schema and API authors should bear this in mind, and use other types (such as string or boolean) if the exact representation is important.
</t>
</section>
</section>
<section title="Missing values">
<t>
Sometimes, the appropriate values will not be available.
For example, the template might specify the use of object properties, but the instance is an array or a string.
</t>
<t>
If any of the values required for the template are not present in the JSON instance, then substitute values MAY be provided from another source (such as default values).
Otherwise, the link definition SHOULD be considered not to apply to the instance.
</t>
</section>
</section>
</section>
<section title="rel">
<t>
The value of the "rel" property indicates the name of the relation to the target resource.
This property is not optional.
</t>
<t>
The relation to the target SHOULD be interpreted as specifically from the instance object that the schema (or sub-schema) applies to, not just the top level resource that contains the object within its hierarchy.
A link relation from the top level resource to a target MUST be indicated with the schema describing the top level JSON representation.
</t>
<t>
Relationship definitions SHOULD NOT be media type dependent, and users are encouraged to utilize existing accepted relation definitions, including those in existing relation registries (see <xref target="RFC4287">RFC 4287</xref>).
However, we define these relations here for clarity of normative interpretation within the context of JSON Schema defined relations:
<list style="hanging">
<t hangText="self">
If the relation value is "self", when this property is encountered in the instance object, the object represents a resource and the instance object is treated as a full representation of the target resource identified by the specified URI.
</t>
<t hangText="full">
This indicates that the target of the link is the full representation for the instance object.
The instance that contains this link may not be the full representation.
</t>
<t hangText="describedBy">
This indicates the target of the link is a schema describing the instance object.
This MAY be used to specifically denote the schemas of objects within a JSON object hierarchy, facilitating polymorphic type data structures.
</t>
<t hangText="root">
This relation indicates that the target of the link SHOULD be treated as the root or the body of the representation for the purposes of user agent interaction or fragment resolution.
All other data in the document can be regarded as meta-data for the document.
The URI of this link MUST refer to a location within the instance document, otherwise the link MUST be ignored.
</t>
</list>
</t>
<t>
The following relations are applicable for schemas (the schema as the "from" resource in the relation) if they require no parameterization with data from the instance:
<list style="hanging">
<t hangText="instances">
This indicates the target resource that represents a collection of instances of a schema.
</t>
<t hangText="create">
This indicates a target to use for creating new instances of a schema.
This link definition SHOULD be a submission link with a non-safe method (like POST).
</t>
</list>
</t>
<figure>
<preamble>For example, if a schema is defined:</preamble>
<artwork>
<![CDATA[{
"links": [{
"rel": "self",
"href": "{id}"
}, {
"rel": "up",
"href": "{upId}"
}, {
"rel": "children",
"href": "?upId={id}"
}]
}]]>
</artwork>
</figure>
<figure>
<preamble>And if a collection of instance resources were retrieved with JSON representation:</preamble>
<artwork>
<![CDATA[GET /Resource/
[{
"id": "thing",
"upId": "parent"
}, {
"id": "thing2",
"upId": "parent"
}]]]>
</artwork>
<postamble>
This would indicate that for the first item in the collection, its own (self) URI would resolve to "/Resource/thing" and the first item's "up" relation SHOULD be resolved to the resource at "/Resource/parent".
The "children" collection would be located at "/Resource/?upId=thing".
</postamble>
</figure>
<t>
Note that these relationship values are case-insensitive, consistent with their use in HTML and the <xref target="RFC5988">HTTP Link header</xref>.
</t>
<section title="Fragment resolution with "root" links">
<t>
The presence of a link with relation "root" alters what the root of the document is considered to be.
For fragment resolution methods (such as JSON Pointer fragments) that navigate through the document, the target of the "root" link should be the starting point for such methods.
</t>
<t>
The only exception is "root" links themselves.
When calculating the target of links with relation "root", existing "root" links MUST NOT be taken into consideration.
</t>
<t>
<figure>
<preamble>For example, say we have the following schema:</preamble>
<artwork>
<![CDATA[{
"links": [{
"rel": "root",
"href": "#/myRootData"
}]
}]]>
</artwork>
</figure>
</t>
<t>
<figure>
<preamble>And the following data, returned from the URI: "http://example.com/data/12345":</preamble>
<artwork>
<![CDATA[{
"myRootData": {
"title": "Document title"
},
"metaData": {
...
}
}]]>
</artwork>
</figure>
</t>
<t>
To correctly resolve the URL "http://example.com/data/12345", we must take the "root" link into account. Here are some example URIs, along with the data they would resolve to:
<figure>
<artwork>
<![CDATA[
URI Data
-----------------------------------------------------------------------
http://example.com/data/12345 {"title": "Document title"}
http://example.com/data/12345#/title "Document title"
]]>
</artwork>
</figure>
</t>
</section>
<section title="Security Considerations for "self" links">
<t>
When link relation of "self" is used to denote a full representation of an object, the user agent SHOULD NOT consider the representation to be the authoritative representation of the resource denoted by the target URI if the target URI is not equivalent to or a sub-path of the the URI used to request the resource representation which contains the target URI with the "self" link.
<figure>
<preamble>For example, if a hyper schema was defined:</preamble>
<artwork>
<![CDATA[{
"links": [{
"rel": "self",
"href": "{id}"
}]
}]]>
</artwork>
</figure>
<figure>
<preamble>And a resource was requested from somesite.com:</preamble>
<artwork>
<![CDATA[
GET /foo/
]]>
</artwork>
</figure>
<figure>
<preamble>With a response of:</preamble>
<artwork>
<![CDATA[Content-Type: application/json; profile="/schema-for-this-data"
[{
"id": "bar",
"name": "This representation can be safely treated \
as authoritative "
}, {
"id": "/baz",
"name": "This representation should not be treated as \
authoritative the user agent should make request the resource\
from '/baz' to ensure it has the authoritative representation"
}, {
"id": "http://othersite.com/something",
"name": "This representation\
should also not be treated as authoritative and the target\
resource representation should be retrieved for the\
authoritative representation"
}]]]>
</artwork>
</figure>
</t>
</section>
</section>
<section title="title">
<t>
This property defines a title for the link.
The value must be a string.
</t>
<t>
User agents MAY use this title when presenting the link to the user.
</t>
</section>
<section title="targetSchema">
<t>
This property value is advisory only, and is a schema that defines the expected structure of the JSON representation of the target of the link, if the target of the link is returned using JSON representation.
</t>
<section title="Security Considerations for "targetSchema"">
<t>
This property has similar security concerns to that of "mediaType".
Clients MUST NOT use the value of this property to aid in the interpretation of the data received in response to following the link, as this leaves "safe" data open to re-interpretation.
</t>
<t>
<figure>
<preamble>
For example, suppose two programmers are having a discussion about web security using a text-only message board.
Here is some data from that conversation, with a URI of: http://forum.example.com/topics/152/comments/13
</preamble>
<artwork>
<![CDATA[{
"topicId": 152,
"commentId": 13,
"from": {
"name": "Jane",
"id": 5
},
"to": {
"name": "Jason",
"id": 8
},
"message": "It's easy, you just add some HTML like
this: <script>doSomethingEvil()</script>"
}]]>
</artwork>
<postamble>
The message string was split over two lines for readability.
</postamble>
</figure>
</t>
<t>
A third party might then write provide the following Link Description Object at another location:
<figure>
<artwork>
<![CDATA[{
"rel": "evil-attack",
"href": "http://forum.example.com/topics/152/comments/13",
"targetSchema": {
"properties": {
"message": {
"description": "Re-interpret the message text as HTML",
"media": {
"type": "text/html"
}
}
}
}
}]]>
</artwork>
<postamble>
If the client used this "targetSchema" value when interpreting the above data, then it might display the contents of "message" as HTML.
At this point, the JavaScript embedded in the message might be executed (in the context of the "forum.example.com" domain).
</postamble>
</figure>
</t>
</section>
</section>
<section title="mediaType">
<t>
The value of this property is advisory only, and represents the media type <xref target="RFC2046">RFC 2046</xref>, that is expected to be returned when fetching this resource.
This property value MAY be a media range instead, using the same pattern defined in <xref target="RFC7231">RFC 7231, section 5.3.1 - HTTP "Accept" header</xref>.
</t>
<t>
This property is analogous to the "type" property of <a> elements in HTML (advisory content type), or the "type" parameter in the <xref target="RFC5988">HTTP Link header</xref>.
User agents MAY use this information to inform the interface they present to the user before the link is followed, but this information MUST NOT use this information in the interpretation of the resulting data.
When deciding how to interpret data obtained through following this link, the behaviour of user agents MUST be identical regardless of the value of the this property.
</t>
<t>
If this property's value is specified, and the link's target is to be obtained using any protocol that supports the HTTP/1.1 "Accept" header <xref target="RFC7231">RFC 7231, section 5.3.1</xref>, then user agents MAY use the value of this property to aid in the assembly of that header when making the request to the server.
</t>
<t>
If this property's value is not specified, then the value should be taken to be "application/json".
</t>
<figure>
<preamble>For example, if a schema is defined:</preamble>
<artwork>
<![CDATA[
{
"links": [{
"rel": "self",
"href": "/{id}/json"
}, {
"rel": "alternate",
"href": "/{id}/html",
"mediaType": "text/html"
}, {
"rel": "alternate",
"href": "/{id}/rss",
"mediaType": "application/rss+xml"
}, {
"rel": "icon",
"href": "{id}/icon",
"mediaType": "image/*"
}]
}
]]>
</artwork>
<postamble>
A suitable instance described by this schema would have four links defined.
The link with a "rel" value of "self" would have an expected MIME type of "application/json" (the default).
The two links with a "rel" value of "alternate" specify the locations of HTML and RSS versions of the current item.
The link with a "rel" value of "icon" links to an image, but does not specify the exact format.
</postamble>
</figure>
<t>
A visual user agent displaying the item from the above example might present a button representing an RSS feed, which when pressed passes the target URI (calculated "href" value) to an view more suited to displaying it, such as a news feed aggregator tab.
</t>
<t>
Note that presenting the link in the above manner, or passing the URI to a news feed aggregator view does not constitute interpretation of the data, but an interpretation of the link.
The interpretation of the data itself is performed by the news feed aggregator, which SHOULD reject any data that would not have also been interpreted as a news feed, had it been displayed in the main view.
</t>
<section title="Security concerns for "mediaType"">
<t>
The "mediaType" property in link definitions defines the expected format of the link's target.
However, this is advisory only, and MUST NOT be considered authoritative.
</t>
<t>
When choosing how to interpret data, the type information provided by the server (or inferred from the filename, or any other usual method) MUST be the only consideration, and the "mediaType" property of the link MUST NOT be used.
User agents MAY use this information to determine how they represent the link or where to display it (for example hover-text, opening in a new tab).
If user agents decide to pass the link to an external program, they SHOULD first verify that the data is of a type that would normally be passed to that external program.
</t>
<t>
This is to guard against re-interpretation of "safe" data, similar to the precautions for "targetSchema".
</t>
</section>
</section>
<section title="Submission Link Properties">
<t>
The following properties also apply to Link Description Objects, and provide functionality analogous to HTML forms, in providing a means for submitting extra (often user supplied) information to send to a server.
</t>
<section title="method">
<t>
This property defines which method can be used to access the target resource.
In an HTTP environment, this might be "GET" or "POST" (or other HTTP methods).
</t>
<t>
Some link relation values imply a set of appropriate HTTP methods to be used for the link.
For example, a client might assume that a link with a relation of "edit" can be used in conjuction with the "PUT" HTTP method.
If the client does not know which methods might be appropriate, then this SHOULD default to "GET".
</t>
</section>
<section title="encType">
<t>
If present, this property indicates a query media type format that the server supports for querying or posting to the collection of instances at the target resource.
The query can be suffixed to the target URI to query the collection with property-based constraints on the resources that SHOULD be returned from the server or used to post data to the resource (depending on the method).
<figure>
<preamble>For example, with the following schema:</preamble>
<artwork>
<![CDATA[{
"links": [{
"encType": "application/x-www-form-urlencoded",
"method": "GET",
"href": "/Product/",
"properties": {
"name": {
"description": "name of the product"
}
}
}]
}]]>
</artwork>
<postamble>This indicates that the client can query the server for instances that have a specific name.</postamble>
</figure>
<figure>
<preamble>For example:</preamble>
<artwork>
<![CDATA[
/Product/?name=Slinky
]]>
</artwork>
</figure>
If no encType or method is specified, only the single URI specified by the href property is defined.
If the method is POST, "application/json" is the default media type.
</t>
</section>
<section title="schema">
<t>
This property contains a schema which defines the acceptable structure of the submitted request.
For a GET request, this schema would define the properties for the query string and for a POST request, this would define the body.
</t>
<t>
Note that this is separate from the URI templating of "href" (which uses data from the instance, not submitted by the user).
It is also separate from the "targetSchema" property, which provides a schema for the data that the client should expect to be returned when they follow the link.
</t>
</section>
</section>
</section>
<section title="IANA Considerations">
<section title="Registry of Link Relations">
<t>
This registry is maintained by IANA per <xref target="RFC4287">RFC 4287</xref> and this specification adds four values: "full", "create", "instances", "root".
New assignments are subject to IESG Approval, as outlined in <xref target="RFC5226">RFC 5226</xref>.
Requests should be made by email to IANA, which will then forward the request to the IESG, requesting approval.
</t>