Dynamic links

81 views
Skip to first unread message

andrei....@gmail.com

unread,
Apr 10, 2012, 6:26:59 AM4/10/12
to json-...@googlegroups.com
Is there any way of making a schema with a variable number of links pointing to a specified schema? ie. addresses points to 0-n address-type instances

or maybe this is too hyper-media like (REST), and it is not in the scope of the hyper-schema ?

Nate

unread,
Apr 12, 2012, 5:27:35 PM4/12/12
to json-...@googlegroups.com
I'm not sure it this is close to what you are looking for... 
{
    "description": "JSON-schema for a list of addresses", 
    "type": "array", 
    "items": {
        "$ref": "http://json-schema.org/address"

Andrei Neculau

unread,
Apr 16, 2012, 4:04:12 AM4/16/12
to json-...@googlegroups.com
Close but not close enough.
Consider describing the following into a JSON-schema

"links": [{
  "method": "GET",
  "rel":    "address",
  "url":    "url1"
},{
  "method": "GET",
  "rel":    "address",
  "url":    "url2"
},{
  "method": "POST",
  "rel":    "test",
  "url":    "url3"
}]

So can you describe that links is an array, and can have 1 or more "address" links, but only 1 "test" link?
I'm considering extending the schema with a new property "cardinality" that would validate iff the cardinality of the array-item is matched.

Xample

unread,
Apr 20, 2012, 3:03:57 AM4/20/12
to json-...@googlegroups.com
there is nothing for the cardinality (but unique which is only restricted to single elements). If you can change your design, I would advise to rewrite your list as an object

{
"address": [{ "method":"GET", "url":"url1"},{ "method":"GET", "url":"url2"}]
"test": [{ "method":"post", "url":"url3"}]
}

Then the schema

{
"properties":
{
"address":{"type":"array"},
"test":{"type":"array", "maxItems":"1"}
}
}
Reply all
Reply to author
Forward
0 new messages