-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v6 hyper-schema: extended templating (vars+template) #52
Comments
Opinions on various points:
|
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.
Having split the most urgent portion of this out into #142, I am going to close this. It's an omnibus that is hard to discuss all at once. Templating My comment tacked on more proposals about user input and validation. That's a complex topic, the requirements for which are being explored in #108 which is a better vehicle for the discussion (it's at least garnered a few comments, while this issue has not). |
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.
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`.
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`.
Originally written by @geraintluff at https://github.com/json-schema/json-schema/wiki/Extended-templating-syntax-(v5-proposal)
Proposed keywords
Uses existing keyword - proposes extension of
href
in LDOs.(Should this syntax also be allowed inside
"$ref"
to allow templating of references?)Purpose
Currently, the only values available for templating in
href
are the object itself, and the immediate children of the object (which must be referred to by their exact name).This proposed new syntax would allow more powerful templating, specifying values from the data using Relative JSON Pointer.
It would also allow the re-naming of template variables. This is useful because in some templates, the variable name is actually included in the results, e.g.
/prefix/{?foo,bar,baz}
->/prefix/?foo=1&bar=2&baz=3
Values
In addition to the existing string values/behaviour for
href
, the following is proposed:The value of
href
may be an object, containing the following properties:template
- containing a URI templatevars
- an object, where all the values are Relative JSON PointersBehaviour
To obtain the URI for the link, the URI template in
template
is expanded. When a variable is referenced by the template, its value is obtained like so:vars
, then:vars
is interpreted as a Relative JSON Pointer, and resolved relative to the current data instance.(Note the complete lack of pre-processing rules - they are not needed here, due to the expressive power of Relative JSON Pointers.)
Example
Data:
Schema:
Concerns
Mismatched pre-processing rules
This syntax is in many ways much simpler than the existing syntax, because there is no need for escaping rules. (The current syntax does pre-processing using
(
,)
and$
.)We are faced with a choice, then - to make the new syntax equally complex, or to have complex pre-processing rules for URI Templates in some situations but not others. (Or, of course, remove the old plain-string syntax, which will impact brevity as well as backwards-compatability.)
Usage inside
$ref
Allowing templating inside
$ref
would force all validators to implement link-parsing - currently, validators can ignore all hyper-schema aspects, which is convenient.Use inside
$ref
would limit static analysis for schemas. However, (like$data
) allowing this keyword in$ref
would open up quite a lot of expressive power.Use inside
$ref
would also ruin our ability to describe$ref
relationships in the meta-schema. Currently, the$ref
behaviour is characterised by afull
link, but allowing templating would undermine that.Current behaviour, and
rel="describedby"
The behaviour of templating
$ref
can currently be mirrored by adding arel="describedby"
link:The only difference is that validators are not obliged to take any notice of links. "Hyper-validators" should, but it is not expected that plain validators would.
The text was updated successfully, but these errors were encountered: