JornWildt / Mason

Documentation and examples for the Mason media type
MIT License
114 stars 6 forks source link

Templated Query Support #21

Open dillonredding opened 4 years ago

dillonredding commented 4 years ago

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 commented 4 years ago

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

dillonredding commented 4 years ago

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?