Re: Override Schema Included Via $ref

3,667 views
Skip to first unread message

Geraint

unread,
May 10, 2013, 4:15:36 AM5/10/13
to json-...@googlegroups.com, randy...@gmail.com
On Thursday, May 9, 2013 5:49:43 PM UTC+1, randy...@gmail.com wrote:
Quick Json Schema clarification:

I would like to ensure that this is a valid way to override V4 schema definitions:

{
    "id": "sample.json#",
    "type": "object",
    "properties": {
        "ref": {
            "$ref": "#/definitions/ref",
            "minItems": 4
        }
    },
    "definitions": {
        "ref": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1
        }
    }
}

The override of minItems set to 4 seems to work as expected in Francis' tooling, but I could find no explicit mention of using this approach in the specification. Perhaps I missed it. Of course, this is much simpler than using an allOf or similar approach, so I am hoping this is conforming and sanctioned.

Thanks for the advice,

Randy Watler

I'm afraid that is *not* according to the specification - in fact Francis's tool is behaving incorrectly.

In that situation, schema processors should be ignoring "minItems":4, because that schema should be completely replaced with the referenced one. The correct way is to use "allOf", as you mention:
{
    "id": "sample.json#",
    "type": "object",
    "properties": {
        "ref": {
            "allOf": [{"$ref": "#/definitions/ref"}],
            "minItems": 4
        }
    },
    "definitions": {
        "ref": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1
        }
    }
}

Geraint

unread,
May 10, 2013, 4:23:55 AM5/10/13
to json-...@googlegroups.com, randy...@gmail.com
In case it's useful, here's the relevant sentence from the JSON Reference spec:

Any members other than "$ref" in a JSON Reference object SHALL be ignored.

 While it would be convenient to do what you're trying to do, I think the proper syntax (using "allOf") isn't much longer.

Geraint Luff

unread,
May 10, 2013, 12:41:10 PM5/10/13
to json-...@googlegroups.com
Btw, there's nothing saying that a JSON Reference with additional properties is invalid - in fact, it is perfectly valid.  It's just that the extra properties should be ignored when processing.

I don't know what kind of properties you might want in there (an explanation of what the target is?  I don't know), but there wouldn't be a reason to flag them.

On 10 May 2013 15:12, <randy...@gmail.com> wrote:
Geraint/Francis:

My apologies to Francis: I was testing using the wrong json schema validator online tool... there are a few of these with very similar urls!

Francis's tool does indeed parse the schema correctly as one should expect from that fine implementation, but it does not flag the JSON Reference object with additional properties as invalid. I will ask him about that.

Randy Watler 

--
You received this message because you are subscribed to a topic in the Google Groups "JSON Schema" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/json-schema/86GSgHSQ0VI/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Francis Galiegue

unread,
May 17, 2013, 8:57:13 AM5/17/13
to json-...@googlegroups.com, randy...@gmail.com
On Fri, May 10, 2013 at 10:15 AM, Geraint <gerai...@gmail.com> wrote:
[...]
>
> I'm afraid that is *not* according to the specification - in fact Francis's
> tool is behaving incorrectly.
>

It does behave correctly. If I input:

{
"$ref": "#/definitions/foo",
"minItems": 2,
"definitions": { "foo": { "maxItems": 3 } }
}

as a schema, it successfully validates an empty array.

--
Francis Galiegue, fgal...@gmail.com
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Reply all
Reply to author
Forward
0 new messages