|
366 | 366 | The URI of the normative link description schema is: <eref target="http://json-schema.org/draft-04/links">http://json-schema.org/draft-04/links</eref> (draft-04 version).
|
367 | 367 | </t>
|
368 | 368 |
|
369 |
| - <t> |
370 |
| - "Form"-like functionality can be defined by use of the "method" and "schema" keywords, which supplies a schema describing the data to supply to the server. |
371 |
| - </t> |
| 369 | + <section title="Links and data"> |
| 370 | + <t> |
| 371 | + "Form"-like functionality can be defined by use of the <xref target="method">"method"</xref> and <xref target="schema">"schema"</xref> keywords, which supplies a schema describing the data to supply to the server. |
| 372 | + Functionality equivalent to dynamic URI generation is available through the <xref target="href">"href"</xref> template and <xref target="hrefSchema">"hrefSchema"</xref>. |
| 373 | + </t> |
| 374 | + <t> |
| 375 | + The simplest kind of link has an "href" with no template variables, and no "schema". This does not |
| 376 | + allow for any variance in the link URI, nor does it allow for a request document. |
| 377 | + </t> |
| 378 | + <t> |
| 379 | + An "href" with at least one template variable, but no "hrefSchema" or "schema", allows resolving |
| 380 | + the template variable from the instance, but does not allow resolving it |
| 381 | + from external data, nor does it allow a request document. |
| 382 | + </t> |
| 383 | + <t> |
| 384 | + An "href" with at least one template variable and with an "hrefSchema" allows using external |
| 385 | + data to resolve the template, and falls back to resolving any remaining variables from the instance. |
| 386 | + </t> |
| 387 | + <t> |
| 388 | + A link with a "schema" allows submitting external data either as a request body (if "method" is "post"), |
| 389 | + or as a URI query string (if "method" is "get"). Such a query string replaces any query string |
| 390 | + present after the "href" template is resolved. |
| 391 | + </t> |
| 392 | + <t> |
| 393 | + See the individual keyword descriptions below for details related to each of these cases. |
| 394 | + </t> |
| 395 | + </section> |
372 | 396 |
|
373 | 397 | <!-- Possibly include a short section on motivations, including triples, resources, and progressive disclosure -->
|
374 | 398 |
|
|
473 | 497 |
|
474 | 498 | <section title="Values for substitution">
|
475 | 499 | <t>
|
476 |
| - After pre-processing, the URI Template is filled out using data from the instance. |
| 500 | + After pre-processing, the URI Template is filled out using data from some combination of an externa source and the instance. |
| 501 | + Where either instance data or external data may be used, this section will refer simply to "data" or to a "value". |
| 502 | + When the source is important, it is specified explicitly. |
| 503 | + |
477 | 504 | 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 | 505 | </t>
|
479 | 506 |
|
480 | 507 | <t>
|
481 | 508 | For a given variable name in the URI Template, the value to use is determined as follows:
|
482 | 509 | <list>
|
483 |
| - <t>If the variable name is "%73elf", then the instance value itself MUST be used.</t> |
484 |
| - <t>If the variable name is "%65mpty", then the instances's empty-string ("") property MUST be used (if it exists).</t> |
485 |
| - <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> |
| 510 | + <t>If the variable name is "%73elf", then the value itself MUST be used.</t> |
| 511 | + <t>If the variable name is "%65mpty", then the empty-string ("") property MUST be used (if it exists).</t> |
| 512 | + <t>If the data 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> |
486 | 513 | <t>Otherwise, the variable name should be percent-decoded, and the corresponding object property MUST be used (if it exists).</t>
|
487 | 514 | </list>
|
488 | 515 | </t>
|
489 | 516 |
|
| 517 | + <t> |
| 518 | + If <xref target="hrefSchema">"hrefSchema"</xref> is present and |
| 519 | + external input is provided, the input MUST be a valid instance according |
| 520 | + to the value of "hrefSchema". |
| 521 | + Template variables, after the process listed above, MUST first |
| 522 | + be resolved from the external data instance. Any variables left |
| 523 | + unresolved MUST be resolved from the resource instance data. |
| 524 | + </t> |
| 525 | + |
490 | 526 | <section title="Converting to strings">
|
491 | 527 | <t>
|
492 | 528 | 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 | 542 | <section title="Missing values">
|
507 | 543 | <t>
|
508 | 544 | 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. |
| 545 | + 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 | 546 | </t>
|
511 | 547 |
|
512 | 548 | <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). |
| 549 | + 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 | 550 | Otherwise, the link definition SHOULD be considered not to apply to the instance.
|
515 | 551 | </t>
|
516 | 552 | </section>
|
517 | 553 | </section>
|
518 | 554 |
|
519 | 555 | </section>
|
520 | 556 |
|
| 557 | + <section title="hrefSchema" anchor="hrefSchema"> |
| 558 | + <t> |
| 559 | + The value of the "hrefSchema" link description property MUST be |
| 560 | + a valid JSON Schema. This schema is used to validate user input |
| 561 | + or other external data for filling out the URI Template in |
| 562 | + <xref target="href">"href"</xref>, as described in that section. |
| 563 | + </t> |
| 564 | + <t> |
| 565 | + Omitting "hrefSchema" or setting the entire schema to "false" prevents |
| 566 | + any external data from being accepted. |
| 567 | + </t> |
| 568 | + <t> |
| 569 | + Implementations MUST NOT attempt to validate values resolved from |
| 570 | + resource instance data with "hrefSchema". This allows for different |
| 571 | + validation rules for user input, such as supporting spelled-out |
| 572 | + months for date-time input but using the standard date-time |
| 573 | + format for storage. |
| 574 | + </t> |
| 575 | + <figure> |
| 576 | + <preamble> |
| 577 | + For example, this defines a schema for each of the query string |
| 578 | + parameters in the URI template: |
| 579 | + </preamble> |
| 580 | + <artwork> |
| 581 | +<![CDATA[{ |
| 582 | + "href": "/foos{?condition,count,query}", |
| 583 | + "hrefSchema": { |
| 584 | + "properties": { |
| 585 | + "condition": { |
| 586 | + "type": "boolean", |
| 587 | + "default": true |
| 588 | + }, |
| 589 | + "count": { |
| 590 | + "type": "integer", |
| 591 | + "minimum": 0, |
| 592 | + "default": 0 |
| 593 | + }, |
| 594 | + "query": { |
| 595 | + "type": "string" |
| 596 | + } |
| 597 | + } |
| 598 | + } |
| 599 | +}]]> |
| 600 | + </artwork> |
| 601 | + </figure> |
| 602 | + <figure> |
| 603 | + <preamble> |
| 604 | + In this example, the schema for "extra" is given as a reference |
| 605 | + to keep the external data validation constraints identical to the |
| 606 | + instance validation constraints for the corresponding property, |
| 607 | + while "id" is given a false schema to prevent external data for |
| 608 | + that variable. |
| 609 | + </preamble> |
| 610 | + <artwork> |
| 611 | +<![CDATA[{ |
| 612 | + "definitions": { |
| 613 | + "extra": { |
| 614 | + "type": "string", |
| 615 | + "maxLength": 32 |
| 616 | + } |
| 617 | + }, |
| 618 | + "type": "object", |
| 619 | + "properties": { |
| 620 | + "id": { |
| 621 | + "type": "integer", |
| 622 | + "minimum": 1, |
| 623 | + "readOnly": true |
| 624 | + }, |
| 625 | + "extra": {"$ref": "#/definitions/extra"} |
| 626 | + }, |
| 627 | + "links": [{ |
| 628 | + "rel": "self", |
| 629 | + "href": "/things/{id}{?extra}", |
| 630 | + "hrefSchema": { |
| 631 | + "properties": { |
| 632 | + "id": false, |
| 633 | + "extra": {"$ref": "#/definitions/extra"} |
| 634 | + } |
| 635 | + } |
| 636 | + }] |
| 637 | +}]]> |
| 638 | + </artwork> |
| 639 | + </figure> |
| 640 | + <t> |
| 641 | + <cref> |
| 642 | + The above example simulates the behavior found in earlier drafts using only "hrefSchema", |
| 643 | + which would allow the concurrent use of "schema" on a "post" link. |
| 644 | + </cref> |
| 645 | + </t> |
| 646 | + </section> |
| 647 | + |
521 | 648 | <section title="rel">
|
522 | 649 | <t>
|
523 | 650 | 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>.
|
@@ -784,7 +911,7 @@ GET /foo/
|
784 | 911 | The following properties also apply to Link Description Objects, and provide functionality analogous to <xref target="W3C.CR-html5-20140731">HTML forms</xref>, by providing a means for making a request with client- or user-selected information.
|
785 | 912 | </t>
|
786 | 913 |
|
787 |
| - <section title="method"> |
| 914 | + <section title="method" anchor="method"> |
788 | 915 | <t>
|
789 | 916 | This property specifies that the client can construct a templated query or non-idempotent request to a resource.
|
790 | 917 | </t>
|
@@ -839,13 +966,16 @@ GET /foo/
|
839 | 966 | </t>
|
840 | 967 | </section>
|
841 | 968 |
|
842 |
| - <section title="schema"> |
| 969 | + <section title="schema" anchor="schema"> |
843 | 970 | <t>
|
844 | 971 | This property contains a schema which defines the acceptable structure of the document being encoded according to the "encType" property.
|
845 | 972 | </t>
|
846 | 973 |
|
847 | 974 | <t>
|
848 |
| - Note that this does not provide data for any URI templates. |
| 975 | + 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. |
| 976 | + </t> |
| 977 | + |
| 978 | + <t> |
849 | 979 | 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 | 980 | </t>
|
851 | 981 | </section>
|
@@ -916,6 +1046,7 @@ GET /foo/
|
916 | 1046 | <t hangText="draft-wright-json-schema-hyperschema-01">
|
917 | 1047 | <list style="symbols">
|
918 | 1048 | <t>Fixed examples</t>
|
| 1049 | + <t>Added "hrefSchema" for user input to "href" URI Templates</t> |
919 | 1050 | </list>
|
920 | 1051 | </t>
|
921 | 1052 | <t hangText="draft-wright-json-schema-hyperschema-00">
|
|
0 commit comments