HydraCG / Specifications

Specifications created by the Hydra W3C Community Group
Other
138 stars 26 forks source link

Variable representation of individual template mappings #244

Open tpluscode opened 2 years ago

tpluscode commented 2 years ago

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 ;
  ] ;
] .
alien-mcl commented 2 years ago

Hmm - I've started preparations to implement all that is necessary for this issue, but something was confusing.

I've took a quick peek at the current specification (and the release candidate and it's visualization and it seems that it is already as you suggest.

The hydra:variableRepresentation has hydra:IriTemplateMapping in it's domain, thus it is actually opposite - you can't define variable representation for whole template with single statement - you've got to do this for each variable being mapped. Could you please confirm that?

tpluscode commented 2 years ago

Indeed, is seems that there is an inconsistency. The text of the current spec does appear to confirm your observation. Example 23 on the other hand shows the variable representation being used with the whole template, which is what I was basing my understanding (and implementation in Alcaeus)

Regardless, I think we should have it both ways, where the template defines the default (using basic representation if unspecified), and each variable should allow overriding that default.