-
Notifications
You must be signed in to change notification settings - Fork 12
Object
Tony Pujals edited this page Aug 4, 2015
·
6 revisions
Validation for object types.
var schema = json.property('foo');
Generates
{
"properties": {
"foo": {}
}
}
Matches any of the following
{}
{
"foo": 1
}
{
"foo": "hello",
"bar": "world
}
var schema = json.object().property('foo');
Generates
{
"type": "object",
"properties": {
"foo": {}
}
}
Matches the same as the previous example.
var schema = json.object().property('foo', {});
Generates the same as the previous example.
Matches the same as the previous example.
var schema = json.object()
.property('foo', {})
.additionalProperties(true);
Generates
{
"type": "object",
"properties": {
"foo": {}
},
"additionalProperties": true
}
Matches the same as the previous example.
var schema = json.object()
.property('foo', {})
.additionalProperties(true);
Generates
{
"type": "object",
"properties": {
"foo": {}
},
"additionalProperties": true
}
Matches the same as the previous example.
var schema = json.object()
.property('foo', {})
.additionalProperties(false);
Generates
{
"type": "object",
"properties": {
"foo": {}
},
"additionalProperties": false
}
Matches
{}
{
"foo": 1
}
var schema = json.object()
.property('foo', {}, true)
.additionalProperties(false);
or
var schema = json.object()
.property('foo')
.required('foo')
.additionalProperties(false);
Generates
{
"type": "object",
"properties": {
"foo": {}
},
"required": [ "foo" ],
"additionalProperties": false
}
Matches
{
"foo": 1
}
Use optional flag to specify if property is required (default is false
).
var schema = json
.property('foo', json.string(), true)
.property('bar', json.integer());
Generates
{
"properties": {
"foo": { "type": "string" },
"bar": { "type": "integer" }
},
"required": [ "foo" ]
}
Schema
"schema": {"maxProperties": 2}
API
var schema = json.maxProperties(2);
Schema
"schema": {"minProperties": 1}
API
var schema = json.minProperties(1);
Schema
"schema": {
"properties": {
"foo": {},
"bar": {}
},
"required": ["foo"]
}
API
var schema = json
.property('foo', {}, true)
.property('bar', {});
Schema
"schema": {
"additionalProperties": {"type": "boolean"}
}
API
var schema = json.additionalProperties(json.boolean());
Schema
"schema": {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "string"}
}
}
API
var schema = json
.properties({
foo: json.integer(),
bar: json.string()
});
Equivalent usage:
var schema = json
.property('foo', json.integer())
.property('bar', json.string());
Schema
"schema": {
"patternProperties": {
"a*": {"type": "integer"},
"aaa*": {"maximum": 20}
}
}
API
var schema = json
.patternProperty('a*', json.integer())
.patternProperty('aaa*', json.maximum(20));
Schema
"schema": {
"dependencies": {"bar": ["foo"]}
}
API
var schema = json.dependencies({ 'bar': ['foo'] });