Converting from Draft3 to Draft4: what to do with "required" outside of "properties".

32 views
Skip to first unread message

Ivan Goncharov

unread,
Jul 28, 2015, 11:15:36 AM7/28/15
to JSON Schema
Hello,

I'm working on converting bunch of JSON schemes form draft3 to draft4, using json-schema-compatibility
Problem that I'm facing is "required" outside of "properties", for example:
{
 
"required": "true"
}

Or another example:
{
 
"type": "array",
 
"items": {
   
"required": "true"
 
}
}

It's legal according to Draft3 and it's schema.
Moreover "required" could be used inside any sub schema, like for example "patternProperties".

What would be correct way to convert such restrictions into Draft4 format?

Geraint

unread,
Jul 29, 2015, 9:34:26 AM7/29/15
to JSON Schema, ivan.gon...@gmail.com, ivan.gon...@gmail.com
This kind of ambiguity was a strong reason for changing "required" in draft v4. :)

I believe that "required" should not be used like this in v3 - as such, I'd be happy to remove it.

Prompted by this, I've just published v1.1.0 of the json-schema-compatibility, which removes "required" booleans that cannot be properly resolved into a parent schema.  Given that validators should ignore v3 syntax, this should produce equivalent behaviour.

Geraint

Geraint

unread,
Jul 29, 2015, 9:44:25 AM7/29/15
to JSON Schema, ivan.gon...@gmail.com, ivan.gon...@gmail.com
So I guess my answer is: I think they're at best meaningless, and at worst ambiguous, so I think removing them is the best option.

Known bug: both the new (remove) and old (ignore) behaviours will produce incorrect behaviour in the following situation:
{
    "type": "object",
    "properties": {
        "foo": {"$ref": "#items"}
    },
    "items": {
        "id": "#items",
        "required": true
    }
}

In that situation, "foo" should be required, but it won't be converted properly by any version of json-schema-compatibility.

Resolving this would require a bunch of extra logic (schema resolution) which could make resolution environment-dependent (that is, you can't convert a schema without fetching all schemas that it references).  If you have any schemas that do this, give me a shout.

Geraint

On Tuesday, 28 July 2015 16:15:36 UTC+1, Ivan Goncharov wrote:

Ivan Goncharov

unread,
Jul 29, 2015, 9:59:45 AM7/29/15
to Geraint, JSON Schema
Thanks for fix.

If you have any schemas that do this, give me a shout.
 
It extreme case and I should be very rare in real life scenarios.
But it good candidate for 'Limitations' section inside README.

Another small issue is that you you don't convert:
"$schema": "http://json-schema.org/draft-03/schema"

into:
"$schema": "http://json-schema.org/draft-04/schema"
Reply all
Reply to author
Forward
0 new messages