Skip to content

Variable representation of individual template mappings #244

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

Open
tpluscode opened this issue Feb 6, 2022 · 2 comments
Open

Variable representation of individual template mappings #244

tpluscode opened this issue Feb 6, 2022 · 2 comments

Comments

@tpluscode
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor Author

tpluscode commented Mar 28, 2022

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.

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