Skip to content

Commit

Permalink
Replace template preprocessing with re-mapping.
Browse files Browse the repository at this point in the history
This change attempts to minimally address the awkwardness and
shortcomings of the current URI template preprocessing approach.

In addition to its dubious aesthetics, preprocessing does not
help with using values other than the current instance or an
immediate property (for an object instance) or element (for an
array instance).

Instead, use an object to map the variable names to locations in
the instance with relative JSON pointers.  This neatly solves both
the UTF-8/illegal variable name problem and the complex data
structure problem with the same mechanism.

This is close to what is proposed in #52, but that proposal includes
several other related features which are understandably more
controversial.  I think this is actually closer to the original
proposal that preceded #52 in the old repo.

The change from `vars` to `hrefVars` was inspired by the terminology
being used in the JSON Home project.  While compatibility with JSON
Home is not a goal, I like how this clarifies exactly what the keyword
is intended to do.

Since `base` is also a template which was defined to use the same
preprocessing as `href`, it likewise gets a corresponding `baseVars`.
  • Loading branch information
handrews committed Nov 17, 2016
1 parent 5340c4b commit 06dc8f0
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 134 deletions.
10 changes: 10 additions & 0 deletions hyper-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"description": "URI Template resolved as for the 'href' keyword in the Link Description Object. The resulting URI Reference is resolved against the current URI base and sets the new URI base for URI references within the instance.",
"type": "string"
},
"baseVars": {
"description": "a mapping from URI template names in \"base\" to relative JSON pointers to be applied to the instance to find the template variable's value",
"type": "object",
"additionalProperties": {"type": "string"}
},
"links": {
"type": "array",
"items": {"$ref": "#/definitions/linkDescription"}
Expand Down Expand Up @@ -82,6 +87,11 @@
"description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing",
"type": "string"
},
"hrefVars": {
"description": "a mapping from URI template names in \"href\" to relative JSON pointers to be applied to the instance to find the template variable's value",
"type": "object",
"additionalProperties": {"type": "string"}
},
"rel": {
"description": "relation to the target resource of the link",
"type": "string"
Expand Down
Loading

0 comments on commit 06dc8f0

Please sign in to comment.