-
Notifications
You must be signed in to change notification settings - Fork 12
Peter Svetlichny edited this page Aug 3, 2015
·
5 revisions
Validation for any instance type.
Schema
"schema": {"enum": [1, 2, 3]}
API
var schema = json.enum([1, 2, 3]);
or simply
var schema = json.enum(1, 2, 3);
Schema
"schema": {"type": "integer"}
API
var schema = json.integer();
Schema
"schema": {"type": ["integer", "string"]}
API
var schema = json.type(['integer', 'string']);
Schema
"schema": {
"properties": {"bar": {"type": "integer"}},
"required": ["bar"],
"allOf" : [
{
"properties": {
"foo": {"type": "string"}
},
"required": ["foo"]
},
{
"properties": {
"baz": {"type": "null"}
},
"required": ["baz"]
}
]
}
API
var schema = json
.property('bar', json.integer(), true)
.allOf([
json.property('foo', json.string(), true),
json.property('baz', json.null(), true)]);
Schema
"schema": {
"type": "string",
"anyOf" : [
{
"maxLength": 2
},
{
"minLength": 4
}
]
}
API
var schema = json
.string()
.anyOf([json.maxLength(2), json.minLength(4)]);
Schema
"schema": {
"type": "string",
"oneOf" : [
{
"minLength": 2
},
{
"maxLength": 4
}
]
}
API
var schema = json
.string()
.oneOf([json.minLength(2), json.maxLength(4)]);
Schema
"schema": {
"not": {"type": ["integer", "boolean"]}
}
API
var schema = json
.not(json.type(['integer', 'boolean']));
Schema
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"}
API
var schema = json.$ref('http://json-schema.org/draft-04/schema#');