jsonary-js / jsonary

Quickly assemble clients for JSON-based APIs (powered by JSON Schema)
http://jsonary.com/
MIT License
122 stars 14 forks source link

How to access parent data #130

Open pmogren opened 10 years ago

pmogren commented 10 years ago

Hello,

Given a JSON document like this:

"a": {
  "b": "bVal"
  "c": {
    "d": [
      { "e" : "e1" },
      { "e" : "e2" }
     ]
   }
}

Is there any way the URI template of a schema-described link on the items of array 'd' could reference the value of 'b'? For example I am thinking of a URI template like "/example{?e}&b={parent.parent.parent.b}" which on the first item in 'd' would come out to "/example?e=e1&b=bVal"

geraintluff commented 10 years ago

Not in v4, I'm afraid.

It's expected to be in v5, as per this proposal. It would be something like:

{
    "links": [
        "href": {
            "template": "/example{?e,b}",
            "vars": {
                "b": "3/b"
            }
        }
    ]
}

In that example, "e" is treated as a plain variable name, but the value for "b" is resolved using a Relative JSON Pointer that says "go up three levels, then into the b property".

The moment a proposal for v5 is released, I'll put this functionality into Jsonary.

pmogren commented 10 years ago

Thanks for the response.

From: Geraint [mailto:notifications@github.com] Sent: Tuesday, January 14, 2014 11:09 AM To: jsonary-js/jsonary Cc: Paul Mogren Subject: Re: [jsonary] How to access parent data (#130)

Not in v4.

It's expected to be in v5, as per this proposalhttps://github.com/json-schema/json-schema/wiki/Extended-templating-syntax-(v5-proposal). It would be something like:

{

"links": [

    "href": {

        "template": "/example{?e,b}",

        "vars": {

            "b": "3/b"

        }

    }

]

}

In that example, "e" is treated as a plain variable name, but the value for "b" is resolved using a Relative JSON Pointer that says "go up three levels, then into the b property".

The moment a proposal for v5 is released, I'll put this functionality into Jsonary.

— Reply to this email directly or view it on GitHubhttps://github.com/jsonary-js/jsonary/issues/130#issuecomment-32278182.