|
183 | 183 | binary data treated as a PNG image.
|
184 | 184 | It also defines link relations for the instance, with URIs incorporating values
|
185 | 185 | from the instance.
|
186 |
| - <cref> |
187 |
| - "id" probably should not normally be a required keyword, since new instances |
188 |
| - will have an unknown "id" property until is it assigned by the server. |
189 |
| - However, this property is used in a link, and without it, multiple different |
190 |
| - instances would be given the same rel=self URI! |
191 |
| - </cref> |
192 | 186 | </postamble>
|
193 | 187 | </figure>
|
194 | 188 |
|
|
644 | 638 |
|
645 | 639 | <section title="Missing values" anchor="missingValues">
|
646 | 640 | <t>
|
647 |
| - Sometimes, the appropriate values will not be available. |
648 |
| - For example, the template might specify the use of object properties, |
649 |
| - but no such data was provided (or "hrefSchema" is not present), and the |
650 |
| - instance is an array or a string. |
| 641 | + Sometimes, the appropriate values will not be available. In many |
| 642 | + cases, the URI Template behavior of simply removing varibles that |
| 643 | + do not have a value will be appropriate. An example of this is |
| 644 | + optional query parameters, the presence or absence of which does |
| 645 | + not change the nature of the link relation type. |
651 | 646 | </t>
|
652 | 647 |
|
653 | 648 | <t>
|
654 |
| - If any of the values required for the template are neither present in |
655 |
| - the user agent data (if relevant) nor the JSON instance, then substitute |
656 |
| - values MAY be provided from another source (such as default values). |
657 |
| - Otherwise, the link definition SHOULD be considered not to apply to the |
658 |
| - instance. |
| 649 | + However, some variables, such as an identifier used in a path component, |
| 650 | + cannot meaningfully be omitted. The resulting URI would be meaningless, |
| 651 | + or would require a different link relation type. While "hrefSchema" can |
| 652 | + express a requirement for those variables that can be supplied via input, |
| 653 | + some variables must be resolved from instance data. When that instance |
| 654 | + data is not required by the context schema, the |
| 655 | + <xref target="hrefRequired">"hrefRequired</xref> keyword may be used to |
| 656 | + indicate that when the instance data is not available, the link does |
| 657 | + not apply. |
659 | 658 | </t>
|
660 | 659 | </section>
|
661 | 660 | </section>
|
|
709 | 708 | "hrefPointers": {
|
710 | 709 | "rootId": "/id",
|
711 | 710 | "parentId": "2/id"
|
712 |
| - } |
| 711 | + }, |
| 712 | + "hrefRequired": ["parentId"] |
713 | 713 | }
|
714 | 714 | ]
|
715 | 715 | }]]>
|
|
761 | 761 | </t>
|
762 | 762 | <t>
|
763 | 763 | For the root node, the relative pointer for the parent doesn't point
|
764 |
| - to anything. As noted under |
765 |
| - <xref target="missingValues">missing values</xref>, such a link should |
766 |
| - simply be ignored. |
767 |
| - <cref> |
768 |
| - GitHub issue #49 tracks the question of distinguishing this situation |
769 |
| - of a missing required variable (common in path components) from |
770 |
| - missing optional variables (common in query string parameters). |
771 |
| - </cref> |
| 764 | + to anything, so <xref target="hrefRequired">"hrefRequired"</xref> |
| 765 | + prevents the link from being used with that node. |
772 | 766 | </t>
|
773 | 767 | </section>
|
774 | 768 |
|
|
863 | 857 | </t>
|
864 | 858 | </section>
|
865 | 859 |
|
| 860 | + <section title="hrefRequired" anchor="hrefRequired"> |
| 861 | + <t> |
| 862 | + The value of this keyword MUST be an array, and the elements MUST be unique. |
| 863 | + Each element SHOULD match a variable in the link's URI Template, without |
| 864 | + percent-encoding. After completing the entire URI Template resolution |
| 865 | + process, if any variable that is present in this array does not have |
| 866 | + a value, the link MUST NOT be used. |
| 867 | + </t> |
| 868 | + <figure> |
| 869 | + <preamble> |
| 870 | + Here is a simplified version of the "up" link from the |
| 871 | + <xref target="hrefPointers">"hrefPointers</xref> tree example, |
| 872 | + modified to only use the parent identifier for its "href" template. |
| 873 | + While each individual node is required to have an "id" field, the |
| 874 | + "up" link uses the parent node's field, and the root node, by definition, |
| 875 | + does not have a parent node. Putting "parentId" in "hrefRequired" ensures |
| 876 | + that the "up" link is correctly unusable with the root node. |
| 877 | + </preamble> |
| 878 | + <artwork> |
| 879 | +<![CDATA[{ |
| 880 | + "rel": "up", |
| 881 | + "href": "/nodes/{parentId}", |
| 882 | + "hrefPointers": { |
| 883 | + "parentId": "2/id" |
| 884 | + }, |
| 885 | + "hrefRequired": ["parentId"] |
| 886 | +}]]> |
| 887 | + </artwork> |
| 888 | + </figure> |
| 889 | + </section> |
| 890 | + |
866 | 891 | <section title="rel" anchor="rel">
|
867 | 892 | <t>
|
868 | 893 | The value of the "rel" property indicates the name of the relation to the target
|
|
0 commit comments