|
170 | 170 | <postamble>
|
171 | 171 | This example schema defines the properties of the instance as well as link
|
172 | 172 | relations for the instance, with URIs incorporating values from the instance.
|
173 |
| - <cref> |
174 |
| - "id" probably should not normally be a required keyword, since new instances |
175 |
| - will have an unknown "id" property until is it assigned by the server. |
176 |
| - However, this property is used in a link, and without it, multiple different |
177 |
| - instances would be given the same rel=self URI! |
178 |
| - </cref> |
179 | 173 | </postamble>
|
180 | 174 | </figure>
|
181 | 175 |
|
|
540 | 534 |
|
541 | 535 | <section title="Missing values" anchor="missingValues">
|
542 | 536 | <t>
|
543 |
| - Sometimes, the appropriate values will not be available. |
544 |
| - For example, the template might specify the use of object properties, |
545 |
| - but no such data was provided (or "hrefSchema" is not present), and the |
546 |
| - instance is an array or a string. |
| 537 | + Sometimes, the appropriate values will not be available. In many |
| 538 | + cases, the URI Template behavior of simply removing varibles that |
| 539 | + do not have a value will be appropriate. An example of this is |
| 540 | + optional query parameters, the presence or absence of which does |
| 541 | + not change the nature of the link relation type. |
547 | 542 | </t>
|
548 | 543 |
|
549 | 544 | <t>
|
550 |
| - If any of the values required for the template are neither present in |
551 |
| - the user agent data (if relevant) nor the JSON instance, then substitute |
552 |
| - values MAY be provided from another source (such as default values). |
553 |
| - Otherwise, the link definition SHOULD be considered not to apply to the |
554 |
| - instance. |
| 545 | + However, some variables, such as an identifier used in a path component, |
| 546 | + cannot meaningfully be omitted. The resulting URI would be meaningless, |
| 547 | + or would require a different link relation type. While "hrefSchema" can |
| 548 | + express a requirement for those variables that can be supplied via input, |
| 549 | + some variables must be resolved from instance data. When that instance |
| 550 | + data is not required by the context schema, the |
| 551 | + <xref target="hrefRequired">"hrefRequired</xref> keyword may be used to |
| 552 | + indicate that when the instance data is not available, the link does |
| 553 | + not apply. |
555 | 554 | </t>
|
556 | 555 | </section>
|
557 | 556 | </section>
|
|
605 | 604 | "hrefPointers": {
|
606 | 605 | "rootId": "/id",
|
607 | 606 | "parentId": "2/id"
|
608 |
| - } |
| 607 | + }, |
| 608 | + "hrefRequired": ["parentId"] |
609 | 609 | }
|
610 | 610 | ]
|
611 | 611 | }]]>
|
|
657 | 657 | </t>
|
658 | 658 | <t>
|
659 | 659 | For the root node, the relative pointer for the parent doesn't point
|
660 |
| - to anything. As noted under |
661 |
| - <xref target="missingValues">missing values</xref>, such a link should |
662 |
| - simply be ignored. |
663 |
| - <cref> |
664 |
| - GitHub issue #49 tracks the question of distinguishing this situation |
665 |
| - of a missing required variable (common in path components) from |
666 |
| - missing optional variables (common in query string parameters). |
667 |
| - </cref> |
| 660 | + to anything, so <xref target="hrefRequired">"hrefRequired"</xref> |
| 661 | + prevents the link from being used with that node. |
668 | 662 | </t>
|
669 | 663 | </section>
|
670 | 664 |
|
|
759 | 753 | </t>
|
760 | 754 | </section>
|
761 | 755 |
|
| 756 | + <section title="hrefRequired" anchor="hrefRequired"> |
| 757 | + <t> |
| 758 | + The value of this keyword MUST be an array, and the elements MUST be unique. |
| 759 | + Each element SHOULD match a variable in the link's URI Template, without |
| 760 | + percent-encoding. After completing the entire URI Template resolution |
| 761 | + process, if any variable that is present in this array does not have |
| 762 | + a value, the link MUST NOT be used. |
| 763 | + </t> |
| 764 | + <figure> |
| 765 | + <preamble> |
| 766 | + Here is a simplified version of the "up" link from the |
| 767 | + <xref target="hrefPointers">"hrefPointers</xref> tree example, |
| 768 | + modified to only use the parent identifier for its "href" template. |
| 769 | + While each individual node is required to have an "id" field, the |
| 770 | + "up" link uses the parent node's field, and the root node, by definition, |
| 771 | + does not have a parent node. Putting "parentId" in "hrefRequired" ensures |
| 772 | + that the "up" link is correctly unusable with the root node. |
| 773 | + </preamble> |
| 774 | + <artwork> |
| 775 | +<![CDATA[{ |
| 776 | + "rel": "up", |
| 777 | + "href": "/nodes/{parentId}", |
| 778 | + "hrefPointers": { |
| 779 | + "parentId": "2/id" |
| 780 | + }, |
| 781 | + "hrefRequired": ["parentId"] |
| 782 | +}]]> |
| 783 | + </artwork> |
| 784 | + </figure> |
| 785 | + </section> |
| 786 | + |
762 | 787 | <section title="rel" anchor="rel">
|
763 | 788 | <t>
|
764 | 789 | The value of the "rel" property indicates the name of the relation to the target
|
|
0 commit comments