|
473 | 473 |
|
474 | 474 | <section title="Values for substitution">
|
475 | 475 | <t>
|
476 |
| - After pre-processing, the URI Template is filled out using data from the instance. |
| 476 | + After pre-processing, the URI Template is filled out using data from some combination of user input and the instance. |
| 477 | + |
477 | 478 | To allow the use of any object property (including the empty string), array index, or the instance value itself, the following rules are defined:
|
478 | 479 | </t>
|
479 | 480 |
|
|
487 | 488 | </list>
|
488 | 489 | </t>
|
489 | 490 |
|
| 491 | + <t> |
| 492 | + If <xref target="hrefSchema">"hrefSchema"</xref> is present and |
| 493 | + user input is provided, the input MUST be valid according to the value of "hrefSchema". |
| 494 | + Template variables, after the process listed above, MUST first |
| 495 | + be resolved from the user input instance. Any variables left |
| 496 | + unresolved MUST be resolved from the resource instance. |
| 497 | + </t> |
| 498 | + |
490 | 499 | <section title="Converting to strings">
|
491 | 500 | <t>
|
492 | 501 | 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:
|
|
506 | 515 | <section title="Missing values">
|
507 | 516 | <t>
|
508 | 517 | Sometimes, the appropriate values will not be available.
|
509 |
| - For example, the template might specify the use of object properties, but the instance is an array or a string. |
| 518 | + For example, the template might specify the use of object properties, but no such input was provide (or "hrefSchema" is not present), and the instance is an array or a string. |
510 | 519 | </t>
|
511 | 520 |
|
512 | 521 | <t>
|
513 |
| - 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). |
| 522 | + If any of the values required for the template are present in neither the user input (if relevant) or the JSON instance, then substitute values MAY be provided from another source (such as default values). |
514 | 523 | Otherwise, the link definition SHOULD be considered not to apply to the instance.
|
515 | 524 | </t>
|
516 | 525 | </section>
|
517 | 526 | </section>
|
518 | 527 |
|
519 | 528 | </section>
|
520 | 529 |
|
| 530 | + <section title="hrefSchema" anchor="hrefSchema"> |
| 531 | + <t> |
| 532 | + The value of the "hrefSchema" link description property MUST be |
| 533 | + a valid JSON Schema. This schema is used to validate user input |
| 534 | + for filling out the URI Template in |
| 535 | + <xref target="href">"href"</xref>, as described in that section. |
| 536 | + </t> |
| 537 | + <t> |
| 538 | + Omitting "hrefSchema" or setting the entire schema to "false" prevents |
| 539 | + any user input from being accepted. |
| 540 | + </t> |
| 541 | + <t> |
| 542 | + Implementations MUST NOT attempt to validate values resolved from |
| 543 | + instance data with "hrefSchema". This allows for different |
| 544 | + validation rules for user input, such as supporting spelled-out |
| 545 | + months for date-time input but using the standard date-time |
| 546 | + format for storage. |
| 547 | + </t> |
| 548 | + <figure> |
| 549 | + <preamble> |
| 550 | + For example, this defines a schema for each of the query string |
| 551 | + parameters in the URI template: |
| 552 | + </preamble> |
| 553 | + <artwork> |
| 554 | +<![CDATA[{ |
| 555 | + "href": "/foos{?condition,count,query}", |
| 556 | + "hrefSchema": { |
| 557 | + "properties": { |
| 558 | + "condition": { |
| 559 | + "type": "boolean", |
| 560 | + "default": true |
| 561 | + }, |
| 562 | + "count": { |
| 563 | + "type": "integer", |
| 564 | + "minimum": 0, |
| 565 | + "default": 0 |
| 566 | + }, |
| 567 | + "query": { |
| 568 | + "type": "string" |
| 569 | + } |
| 570 | + } |
| 571 | + } |
| 572 | +}]]> |
| 573 | + </artwork> |
| 574 | + </figure> |
| 575 | + <figure> |
| 576 | + <preamble> |
| 577 | + In this example, the schema for "extra" is given as a reference |
| 578 | + to keep the user input validation constraints identical to the |
| 579 | + instance validation constraints for the corresponding property, |
| 580 | + while "id" is given a false schema to prevent user input for |
| 581 | + that variable. |
| 582 | + </preamble> |
| 583 | + <artwork> |
| 584 | +<![CDATA[{ |
| 585 | + "definitions": { |
| 586 | + "extra": { |
| 587 | + "type": "string", |
| 588 | + "maxLength": 32 |
| 589 | + } |
| 590 | + }, |
| 591 | + "type": "object", |
| 592 | + "properties": { |
| 593 | + "id": { |
| 594 | + "type": "integer", |
| 595 | + "minimum": 1, |
| 596 | + "readOnly": true |
| 597 | + }, |
| 598 | + "extra": {"$ref": "#/definitions/extra"} |
| 599 | + }, |
| 600 | + "links": [{ |
| 601 | + "rel": "self", |
| 602 | + "href": "/things/{id}{?extra}", |
| 603 | + "hrefSchema": { |
| 604 | + "properties": { |
| 605 | + "id": false, |
| 606 | + "extra": {"$ref": "#/definitions/extra"} |
| 607 | + } |
| 608 | + } |
| 609 | + }] |
| 610 | +}]]> |
| 611 | + </artwork> |
| 612 | + </figure> |
| 613 | + </section> |
| 614 | + |
521 | 615 | <section title="rel">
|
522 | 616 | <t>
|
523 | 617 | The value of the "rel" property indicates the name of the relation to the target resource. The value MUST be a registered link relation from the <xref target="RFC5988">IANA Link Relation Type Registry established in RFC 5988</xref>, or a normalized URI following the <xref target="RFC3986">URI production of RFC 3986</xref>.
|
@@ -845,7 +939,10 @@ GET /foo/
|
845 | 939 | </t>
|
846 | 940 |
|
847 | 941 | <t>
|
848 |
| - Note that this does not provide data for any URI templates. |
| 942 | + Note that this does not provide data for any URI templates. That is handed by <xref target="hrefSchema">"hrefSchema"</xref>. If the method is "get" and the resolved URI Template has a query string, the query string produced by input validated agaisnt "schema" replaces the existing query string. |
| 943 | + </t> |
| 944 | + |
| 945 | + <t> |
849 | 946 | This is a separate concept from the "targetSchema" property, which is describing the target information resource (including for replacing the contents of the resource in a PUT request), unlike "schema" which describes the user-submitted request data to be evaluated by the resource.
|
850 | 947 | </t>
|
851 | 948 | </section>
|
|
0 commit comments