Skip to content

Variable representation of individual template mappings #244

Description

@tpluscode

Describe the requirement

Right now it is only possible to set the variable representation of an entire IriTemplate. It would be nice to also allow selecting a specific variable representation of individual variables

Example

Consider a paged collection with a category filter. The template could be {?page,category}. To have the category variable interpreted as an IRI, the entire template is best switched to hydra:ExplicitRepresentation but this unnecessarily blows up the page param in query. Identifier of page 5 would be ?page=%225%22%5E%5Ehttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23integer instead of the simple ?page=5

On the other hand, without explicit representation, the value ?cetegory=https%3A%2F%2Fexample.com%2Fcatergory%2Ffoo would be interpreted as string unless additional processing would be applied by server and/or client.

Proposed solutions

If we relaxed the domain of hydra:variableRepresentation, it will become possible to individually choose the representation of each variable. The template itself would define the default, optionally overridden. Thus, the above could be achieved in two ways:

By making category explicit

[
  a hydra:IriTemplate ;
  hydra:template "?page,category" ;
  hydra:mapping [
    # basic representation by default
    hydra:variable "page" ;
    hydra:property hydra:pageIndex ;
  ] , [
    hydra:variableRepresentation hydra:ExplicitRepresentation ;
    hydra:variable "category" ;
    hydra:property schema:category ;
  ] ;
] .

Or by making the entire template explicit and only page basic

[
  a hydra:IriTemplate ;
  hydra:template "?page,category" ;
  hydra:variableRepresentation hydra:ExplicitRepresentation ;
  hydra:mapping [
    hydra:variableRepresentation hydra:BasicRepresentation ;
    hydra:variable "page" ;
    hydra:property hydra:pageIndex ;
  ] , [
    # explicit representation by default
    hydra:variable "category" ;
    hydra:property schema:category ;
  ] ;
] .

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions