using properties and patternProperties within the same schema

1,461 views
Skip to first unread message

as1234

unread,
Mar 11, 2011, 6:58:43 AM3/11/11
to JSON Schema
I have some questions related to detailed semantics of
patternProperties that are not specified in the spec:

1) When schema "patternProperties" and "properties" together, and the
pattern matches one of the explicitly listed properites, will both
subschema get during validation or only one of them. If both, is the
semantic the same as with "extends"?

2) What if multiple patterns of patternPropertiers apply to a given
json-Property (maybe oven more than 2)? Or is there any kind of order
defined (the first pattern that matches?)

Background:
I want to formalize in JSON-Schema something similar to the definition
of the "format" property: "The property of an object in either on the
the predefined ones, or a URL, and the URI also points to the schema".

Could I write:

{
"type" : "object",
"patternProperties" : {
//some predefined properties with local schema definitions
"(foo|bar)" : { "$ref" : "{\1}.schema.json" },
// otherwise a url that points of a schema
"(.*)" : { "ref" : "{\1}" }
}
}


I know that the back reference in uri-templates is not (yet?)
specified -- see my other message on that topic, that hasn't yet
received an answer ;-)

Any other suggestions?

Gary Court

unread,
Mar 14, 2011, 12:07:27 PM3/14/11
to json-...@googlegroups.com, as1234
On Fri, Mar 11, 2011 at 4:58 AM, as1234 <andreas...@nokia.com> wrote:
> I have some questions related to detailed semantics of
> patternProperties that are not specified in the spec:
>
> 1) When schema "patternProperties" and "properties" together, and the
> pattern matches one of the explicitly listed properites, will both
> subschema get during validation or only one of them. If both, is the
> semantic the same as with "extends"?

Both subschemas will be used to validate the property. They are
validated separately and not merged.

> 2) What if multiple patterns of patternPropertiers apply to a given
> json-Property (maybe oven more than 2)? Or is there any kind of order
> defined (the first pattern that matches?)

Same as if multiple patternProperties match. Each matching schema will
validate the property independently.

> Background:
> I want to formalize in JSON-Schema something similar to the definition
> of the "format" property: "The property of an object in either on the
> the predefined ones, or a URL, and the URI also points to the schema".
>
> Could I write:
>
> {
>    "type" : "object",
>    "patternProperties" : {
>        //some predefined properties with local schema definitions
>        "(foo|bar)" : { "$ref" : "{\1}.schema.json" },
>        // otherwise a url that points of a schema
>        "(.*)" : { "ref" : "{\1}" }
>    }
> }
>

In this specific example, you would be better off using the
"properties" and "additionalProperties" attributes. Also, JSON Schema
doesn't support "{\1}".

-Gary

as1234

unread,
Mar 16, 2011, 9:32:52 AM3/16/11
to JSON Schema
Gary,

thanks for the clarification.

> > {
> >    "type" : "object",
> >    "patternProperties" : {
> >        //some predefined properties with local schema definitions
> >        "(foo|bar)" : { "$ref" : "{\1}.schema.json" },
> >        // otherwise a url that points of a schema
> >        "(.*)" : { "ref" : "{\1}" }
> >    }
> > }
>
> In this specific example, you would be better off using the
> "properties" and "additionalProperties" attributes. Also, JSON Schema
> doesn't support "{\1}".

But how can I express with additionalProperties, that a property name
is a URI and that this URI points to the json-schema of the property
value?

Regarding support for regexp back-references: Would you second an
enhancement of json-schema's uri template within patternProperties for
supporting this ? I stumbled across multiple cases where it would be
very helpful. Those include "predefined extensions points" (like my
first example) as well as compact notations of the service api through
links withing pattern properties (e.g. "there exists a subresource
link for every.property that is equally named as the property")

Best,
Andreas
Reply all
Reply to author
Forward
0 new messages