$ref replacement

432 views
Skip to first unread message

Konstantin Käfer

unread,
Jun 17, 2012, 7:56:39 AM6/17/12
to JSON Schema
Hi,

I noticed that in the current revision, 5.28 says about $ref: "it
SHOULD replace the current schema with the schema referenced by the
value's URI".

Let's take this schema (Invoice.json):

{
"name": "Invoice",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"delivery": {
"$ref": "Delivery.json",
"required": true
}
}
}

When truly overwriting the current object, "required" is thrown away.
How can I specify another schema as /required/ without *writing* it
into the other schema's (Delivery.json) root?

Konstantin

Francis Galiegue

unread,
Jun 17, 2012, 9:38:21 AM6/17/12
to json-...@googlegroups.com
This is one more motivation to change the definition of the "required" keyword!

As was already explained earlier, the "required" keyword has no role
in the schema is it attached to, it only makes sense to its containing
"properties". In draft v4, this keyword will change and your schema
will become:

{
"name": "Invoice",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"delivery": {
"$ref": "Delivery.json"
}
},
"required": [ "delivery" ]
}

Basically, it means that when validating a "properties" schema at the
moment, you have to lookup all "required" keywords in property schemas
to build the list of required properties for an object instance. With
draft v4 it will no longer be the case.

As such, "$ref" replacement doesn't really matter. But "required" as
defined in draft v3 is certainly confusing.

Hope this helps,
--
Francis Galiegue, fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)

Konstantin Käfer

unread,
Jun 18, 2012, 6:13:18 AM6/18/12
to json-...@googlegroups.com
Alright, thanks for confirming that I'm not misusing the property but that it's indeed a flaw in the spec.

Francis Galiegue

unread,
Jun 18, 2012, 7:37:27 AM6/18/12
to json-...@googlegroups.com
On Mon, Jun 18, 2012 at 12:13 PM, Konstantin Käfer <kka...@gmail.com> wrote:
> Alright, thanks for confirming that I'm not misusing the property but that
> it's indeed a flaw in the spec.
>

Not only that, but draft v3 as such does not make any reference to the
JSON Reference spec[1]. It is scheduled for draft v4.

Now, I wish I had completed my work on my own implementation of Json
Schema earlier so that I fulfill a promise I have made earlier on the
list :/

[1] http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-02

Chris Miles

unread,
Jun 19, 2012, 6:17:27 AM6/19/12
to json-...@googlegroups.com
You can do:

{
"name": "Invoice",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"delivery": {
"extends": {"$ref": "Delivery.json"},
"required": true
}
}
}

Chris

N. Morse

unread,
Jun 19, 2012, 12:13:09 PM6/19/12
to json-...@googlegroups.com
@Chris That is the form I would use as well.

On Tue, Jun 19, 2012 at 6:17 AM, Chris Miles <ch...@moonfruit.com> wrote:
You can do:

{
   "name": "Invoice",
   "type": "object",
   "properties": {
       "id": {
           "type": "integer"
       },
       "delivery": {
           "extends": {"$ref": "Delivery.json"},
           "required": true
       }
   }
}

Chris

On 17/06/12 12:56, Konstantin Käfer wrote:
> Hi,
>
> I noticed that in the current revision, 5.28 says about $ref: "it
> SHOULD replace the current schema with the schema referenced by the
> value's URI".
>
> Let's take this schema (Invoice.json):
>
> {
>     "name": "Invoice",
>     "type": "object",
>     "properties": {
>         "id": {
>             "type": "integer"
>         },
>         "delivery": {
>             "$ref": "Delivery.json",
>             "required": true
>         }
>     }
> }
>
> When truly overwriting the current object, "required" is thrown away.
> How can I specify another schema as /required/ without *writing* it
> into the other schema's (Delivery.json) root?
>
> Konstantin
>

--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To post to this group, send email to json-...@googlegroups.com.
To unsubscribe from this group, send email to json-schema...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.




--
Nate Morse
Programmer
SmartCatalog
217 Commercial Street, Suite 406
Portland, ME 04101
800 770-8425
207 774-4769
207 780-0129 fax
www.academiccatalog.com
Reply all
Reply to author
Forward
0 new messages