Skip to content

Commit 06dc8f0

Browse files
committed
Replace template preprocessing with re-mapping.
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 json-schema-org#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 json-schema-org#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`.
1 parent 5340c4b commit 06dc8f0

File tree

2 files changed

+183
-134
lines changed

2 files changed

+183
-134
lines changed

hyper-schema.json

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"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.",
5151
"type": "string"
5252
},
53+
"baseVars": {
54+
"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",
55+
"type": "object",
56+
"additionalProperties": {"type": "string"}
57+
},
5358
"links": {
5459
"type": "array",
5560
"items": {"$ref": "#/definitions/linkDescription"}
@@ -82,6 +87,11 @@
8287
"description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing",
8388
"type": "string"
8489
},
90+
"hrefVars": {
91+
"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",
92+
"type": "object",
93+
"additionalProperties": {"type": "string"}
94+
},
8595
"rel": {
8696
"description": "relation to the target resource of the link",
8797
"type": "string"

0 commit comments

Comments
 (0)