Draft 04 | Draft 06 | Draft 07 | Draft 2019-09 | Draft 2020-12 |
The 'additionalProperties' keyword may be a boolean (true, false) value or a schema object.
The value of "additionalProperties" MUST be a boolean or an object. If it is an object, it MUST also be a valid JSON Schema.
The value of "properties" MUST be an object. Each value of this object MUST be an object, and each object MUST be a valid JSON Schema.
The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. Each property value of this object MUST be an object, and each object MUST be a valid JSON Schema.
Successful validation of an object instance against these three keywords depends on the value of "additionalProperties":
if its value is boolean true or a schema, validation succeeds;
if its value is boolean false, the algorithm to determine validation success is described below.
5.4.4.4. If "additionalProperties" has boolean value falseIn this case, validation of the instance depends on the property set of "properties" and "patternProperties". In this section, the property names of "patternProperties" will be called regexes for convenience.
The first step is to collect the following sets:
- s
- The property set of the instance to validate.
- p
- The property set from "properties".
- pp
- The property set from "patternProperties".
Having collected these three sets, the process is as follows:
remove from "s" all elements of "p", if any;
for each regex in "pp", remove all elements of "s" which this regex matches.
Validation of the instance succeeds if, after these two steps, set "s" is empty.
The three keywords implied in this calculation are "properties", "patternProperties" and "additionalProperties".
If "properties" or "patternProperties" are absent, they are considered present with an empty object as a value.
If "additionalProperties" is absent, it is considered present with an empty schema as a value. In addition, boolean value true is considered equivalent to an empty schema.
The calculation below uses the following names:
m
The property name of the child.
p
The property set from "properties".
pp
The property set from "patternProperties". Elements of this set will be called regexes for convenience.
s
The set of schemas for the child instance.
If set "p" contains value "m", then the corresponding schema in "properties" is added to "s".
For each regex in "pp", if it matches "m" successfully, the corresponding schema in "patternProperties" is added to "s".
The schema defined by "additionalProperties" is added to "s" if and only if, at this stage, "s" is empty.
Trying to simplify this;
The name of every member in the instance object must for full at least on of the following;
Furthermore:
If the instance object's member matches by name against a member in 'properties' then the instance value must validate against the corresponding schema.
If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.
The instance object places no restriction on the names of the members it contains.
But:
If the instance object's member matches by name against a member in 'properties' then the instance value must validate against the corresponding schema.
If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.
The instance object places no restriction on the names of the members it contains.
But:
If the instance object's member matches by name a member in 'properties' then the instance value must validate against the corresponding schema.
If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.
The value of any instance object members whose name did not match against 'properties' or 'patternProperties' must validate against the schema contained in 'additionalProperties'.
The UI simplifies the properties and displays them in a logical way, but if you are already familiar with the JSON standard this section describes how the UI is mapped from the source.
Sample Json Schema |
Copy Code
|
---|---|
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "My schema", "type": "object", "additionalProperties": false, "properties": { "MyBooleanProperty": { "type": "boolean" }, "MyArrayProperty": { "type": "array" } }, "patternProperties": { "MyStringProperty[0-9]*": { "type": "string" } } } |
Shown graphically this looks like this
To add the 'additionalProperties' keyword back into the schema you can use the 'Add Properties -> Additional Properties' command from the context menu in the parent schema or the properties container (this will give the schema below).
Sample Json Schema |
Copy Code
|
---|---|
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "My schema", "type": "object", "additionalProperties": true, "properties": { "MyBooleanProperty": { "type": "boolean" }, "MyArrayProperty": { "type": "array" } }, "patternProperties": { "MyStringProperty[0-9]*": { "type": "string" } } } |
Shown graphically this looks like this
Converting 'additionaProperties' back to 'false' can be done by deleting it from the diagram.
To change the representation of 'additionaProperties' from an object to a boolean, the Representation property can be set.
Sample Json Schema |
Copy Code
|
---|---|
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "My schema", "type": "object", "additionalProperties": { "type": "number" }, "properties": { "MyBooleanProperty": { "type": "boolean" }, "MyArrayProperty": { "type": "array" } }, "patternProperties": { "MyStringProperty[0-9]*": { "type": "string" } } } |
Shown graphically this looks like this
The <Additional Properties> entry now holds a schema and can be edited as any other schema.
To make the 'additionaProperties' to false, you can just delete it, or change the representation using the Representation property.