diff --git a/hyper-schema.json b/hyper-schema.json index 2498b5e6..be66409a 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -20,6 +20,10 @@ "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", "type": "string" }, + "hrefSchema": { + "description": "a schema for validating user input to the URI template, where the input is in the form of a JSON object with property names matching variable names in \"href\"", + "allOf": [ {"$ref": "#"} ] + }, "rel": { "description": "relation to the target resource of the link", "type": "string" diff --git a/jsonschema-hyperschema.xml b/jsonschema-hyperschema.xml index dfe1ec51..7c3fd305 100644 --- a/jsonschema-hyperschema.xml +++ b/jsonschema-hyperschema.xml @@ -366,9 +366,33 @@ The URI of the normative link description schema is: http://json-schema.org/draft-04/links (draft-04 version). - - "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. - +
+ + "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. + Functionality equivalent to dynamic URI generation is available through the "href" template and "hrefSchema". + + + The simplest kind of link has an "href" with no template variables, and no "schema". This does not + allow for any variance in the link URI, nor does it allow for a request document. + + + An "href" with at least one template variable, but no "hrefSchema" or "schema", allows resolving + the template variable from the instance, but does not allow resolving it + from external data, nor does it allow a request document. + + + An "href" with at least one template variable and with an "hrefSchema" allows using external + data to resolve the template, and falls back to resolving any remaining variables from the instance. + + + A link with a "schema" allows submitting external data either as a request body (if "method" is "post"), + or as a URI query string (if "method" is "get"). Such a query string replaces any query string + present after the "href" template is resolved. + + + See the individual keyword descriptions below for details related to each of these cases. + +
@@ -473,20 +497,32 @@
- After pre-processing, the URI Template is filled out using data from the instance. + After pre-processing, the URI Template is filled out using data from some combination of an externa source and the instance. + Where either instance data or external data may be used, this section will refer simply to "data" or to a "value". + When the source is important, it is specified explicitly. + To allow the use of any object property (including the empty string), array index, or the instance value itself, the following rules are defined: For a given variable name in the URI Template, the value to use is determined as follows: - If the variable name is "%73elf", then the instance value itself MUST be used. - If the variable name is "%65mpty", then the instances's empty-string ("") property MUST be used (if it exists). - 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). + If the variable name is "%73elf", then the value itself MUST be used. + If the variable name is "%65mpty", then the empty-string ("") property MUST be used (if it exists). + 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). Otherwise, the variable name should be percent-decoded, and the corresponding object property MUST be used (if it exists). + + If "hrefSchema" is present and + external input is provided, the input MUST be a valid instance according + to the value of "hrefSchema". + Template variables, after the process listed above, MUST first + be resolved from the external data instance. Any variables left + unresolved MUST be resolved from the resource instance data. + +
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,11 +542,11 @@
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. + 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. - 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). + 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). Otherwise, the link definition SHOULD be considered not to apply to the instance.
@@ -518,6 +554,97 @@
+
+ + The value of the "hrefSchema" link description property MUST be + a valid JSON Schema. This schema is used to validate user input + or other external data for filling out the URI Template in + "href", as described in that section. + + + Omitting "hrefSchema" or setting the entire schema to "false" prevents + any external data from being accepted. + + + Implementations MUST NOT attempt to validate values resolved from + resource instance data with "hrefSchema". This allows for different + validation rules for user input, such as supporting spelled-out + months for date-time input but using the standard date-time + format for storage. + +
+ + For example, this defines a schema for each of the query string + parameters in the URI template: + + + + +
+
+ + In this example, the schema for "extra" is given as a reference + to keep the external data validation constraints identical to the + instance validation constraints for the corresponding property, + while "id" is given a false schema to prevent external data for + that variable. + + + + +
+ + + The above example simulates the behavior found in earlier drafts using only "hrefSchema", + which would allow the concurrent use of "schema" on a "post" link. + + +
+
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 IANA Link Relation Type Registry established in RFC 5988, or a normalized URI following the URI production of RFC 3986. @@ -784,7 +911,7 @@ GET /foo/ The following properties also apply to Link Description Objects, and provide functionality analogous to HTML forms, by providing a means for making a request with client- or user-selected information. -
+
This property specifies that the client can construct a templated query or non-idempotent request to a resource. @@ -839,13 +966,16 @@ GET /foo/
-
+
This property contains a schema which defines the acceptable structure of the document being encoded according to the "encType" property. - Note that this does not provide data for any URI templates. + Note that this does not provide data for any URI templates. That is handed by "hrefSchema". 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. + + + 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.
@@ -916,6 +1046,7 @@ GET /foo/ Fixed examples + Added "hrefSchema" for user input to "href" URI Templates diff --git a/links.json b/links.json index fad6e894..947181e2 100644 --- a/links.json +++ b/links.json @@ -9,6 +9,10 @@ "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", "type": "string" }, + "hrefSchema": { + "description": "a schema for validating user input to the URI template, where the input is in the form of a JSON object with property names matching variable names in \"href\"", + "allOf": [ {"$ref": "#"} ] + }, "rel": { "description": "relation to the target resource of the link", "type": "string"