Skip to content
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

Templated Query Support #21

Open
dillonredding opened this issue Mar 25, 2020 · 2 comments
Open

Templated Query Support #21

dillonredding opened this issue Mar 25, 2020 · 2 comments

Comments

@dillonredding
Copy link

Trying to understand Mason's support for queries/templated transitions.

I'm not sure exactly how to specify the action metadata for a request like this:

GET /foo?bar=abc&baz=123 HTTP/1.1

According to draft 2 of the spec:

If encoding is either "json" or "json+files" then the schema should describe the JSON data. schema handling is not defined for other encoding types. [Emphasis mine]

So, I don't think specifying only a control's href and schema is sufficient:

{
  "@controls": {
    "search": {
      "href": "/foo",
      "schema": {
        "type": "object",
        "required": ["foo", "bar"],
        "properties": {
          "foo": { "type": "string" },
          "bar": { "type": "integer" }
        }
      }
    }
  }
}

Draft 2 also states:

If isHrefTemplate is true then href must be interpreted as a URI template according to RFC 6570 - URI Template. The template variables may be described by a schema definition in the schema property or through a referenced schema via the schemaUrl property. [Emphasis mine]

Then would that mean this control is enough?

{
  "@controls": {
    "search": {
      "href": "/foo{?foo,bar}",
      "isHrefTemplated": true,
      "schema": {
        "type": "object",
        "required": ["foo", "bar"],
        "properties": {
          "foo": { "type": "string" },
          "bar": { "type": "integer" }
        }
      }
    }
  }
}

I'm mostly unsure, because draft 2 goes on to say:

All the values for the template variables should be represented in a JSON object. Variable names are then supposed to be JSONPath expressions (without leading slashes) that refer to properties in the JSON object. [Emphasis mine]

I'm also confused by the "without leading slashes" part. JSON path (as far as I know) starts with $. Should this be JSON Pointer instead? If not, does this mean the template needs to be /foo{?%24.foo,%24.bar} (percent encoding to conform to template variable syntax)?

@JornWildt
Copy link
Owner

Thanks for your input. I'll try to take a look at it.

@dillonredding
Copy link
Author

On a related note, for invoking control elements, merging the template and the arguments object (step 4) happens after URI templates are expanded (step 2). Does this mean templates can't be applied to URI templates? How would you go about supplying default values? Possibly through JSON Schema's default keyword?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants