diff options
Diffstat (limited to 'jsonschema')
-rw-r--r-- | jsonschema/_utils.py | 13 | ||||
-rw-r--r-- | jsonschema/schemas/draft3.json | 1 | ||||
-rw-r--r-- | jsonschema/schemas/draft4.json | 1 | ||||
-rw-r--r-- | jsonschema/validators.py | 244 |
4 files changed, 17 insertions, 242 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 5129272..7e748cb 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -1,5 +1,7 @@ import itertools +import json import re +import os from jsonschema.compat import str_types, urlparse, MutableMapping @@ -36,6 +38,17 @@ class URIDict(MutableMapping): return repr(self.store) +def load_schema(name): + """ + Load a schema from ./schemas/``name``.json and return it. + + """ + schemadir = os.path.join(os.path.dirname(__file__), 'schemas') + schemapath = os.path.join(schemadir, '%s.json' % (name,)) + with open(schemapath) as f: + return json.load(f) + + def indent(string, times=1): """ A dumb version of :func:`textwrap.indent` from Python 3.3. diff --git a/jsonschema/schemas/draft3.json b/jsonschema/schemas/draft3.json new file mode 100644 index 0000000..9c9fee8 --- /dev/null +++ b/jsonschema/schemas/draft3.json @@ -0,0 +1 @@ +{"$schema": "http://json-schema.org/draft-03/schema#", "dependencies": {"exclusiveMaximum": "maximum", "exclusiveMinimum": "minimum"}, "type": "object", "id": "http://json-schema.org/draft-03/schema#", "properties": {"maxDecimal": {"minimum": 0, "type": "number"}, "minimum": {"type": "number"}, "maxItems": {"minimum": 0, "type": "integer"}, "$schema": {"type": "string", "format": "uri"}, "exclusiveMinimum": {"default": false, "type": "boolean"}, "id": {"type": "string", "format": "uri"}, "$ref": {"type": "string", "format": "uri"}, "exclusiveMaximum": {"default": false, "type": "boolean"}, "title": {"type": "string"}, "pattern": {"type": "string", "format": "regex"}, "patternProperties": {"additionalProperties": {"$ref": "#"}, "default": {}, "type": "object"}, "extends": {"default": {}, "items": {"$ref": "#"}, "type": [{"$ref": "#"}, "array"]}, "type": {"uniqueItems": true, "items": {"type": ["string", {"$ref": "#"}]}, "default": "any", "type": ["string", "array"]}, "description": {"type": "string"}, "format": {"type": "string"}, "minLength": {"default": 0, "minimum": 0, "type": "integer"}, "enum": {"minItems": 1, "uniqueItems": true, "type": "array"}, "disallow": {"uniqueItems": true, "items": {"type": ["string", {"$ref": "#"}]}, "type": ["string", "array"]}, "divisibleBy": {"default": 1, "exclusiveMinimum": true, "minimum": 0, "type": "number"}, "dependencies": {"additionalProperties": {"items": {"type": "string"}, "type": ["string", "array", {"$ref": "#"}]}, "default": {}, "type": ["string", "array", "object"]}, "maxLength": {"type": "integer"}, "uniqueItems": {"default": false, "type": "boolean"}, "properties": {"additionalProperties": {"type": "object", "$ref": "#"}, "default": {}, "type": "object"}, "additionalItems": {"default": {}, "type": [{"$ref": "#"}, "boolean"]}, "default": {"type": "any"}, "items": {"default": {}, "items": {"$ref": "#"}, "type": [{"$ref": "#"}, "array"]}, "required": {"default": false, "type": "boolean"}, "maximum": {"type": "number"}, "minItems": {"default": 0, "minimum": 0, "type": "integer"}, "additionalProperties": {"default": {}, "type": [{"$ref": "#"}, "boolean"]}}}
\ No newline at end of file diff --git a/jsonschema/schemas/draft4.json b/jsonschema/schemas/draft4.json new file mode 100644 index 0000000..12f583e --- /dev/null +++ b/jsonschema/schemas/draft4.json @@ -0,0 +1 @@ +{"dependencies": {"exclusiveMaximum": ["maximum"], "exclusiveMinimum": ["minimum"]}, "description": "Core schema meta-schema", "default": {}, "definitions": {"simpleTypes": {"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]}, "schemaArray": {"minItems": 1, "items": {"$ref": "#"}, "type": "array"}, "positiveIntegerDefault0": {"allOf": [{"$ref": "#/definitions/positiveInteger"}, {"default": 0}]}, "positiveInteger": {"minimum": 0, "type": "integer"}, "stringArray": {"minItems": 1, "items": {"type": "string"}, "uniqueItems": true, "type": "array"}}, "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "id": "http://json-schema.org/draft-04/schema#", "properties": {"description": {"type": "string"}, "allOf": {"$ref": "#/definitions/schemaArray"}, "minLength": {"$ref": "#/definitions/positiveIntegerDefault0"}, "anyOf": {"$ref": "#/definitions/schemaArray"}, "enum": {"minItems": 1, "uniqueItems": true, "type": "array"}, "additionalItems": {"default": {}, "anyOf": [{"type": "boolean"}, {"$ref": "#"}]}, "maximum": {"type": "number"}, "not": {"$ref": "#"}, "minimum": {"type": "number"}, "maxItems": {"$ref": "#/definitions/positiveInteger"}, "maxLength": {"$ref": "#/definitions/positiveInteger"}, "uniqueItems": {"default": false, "type": "boolean"}, "$schema": {"type": "string", "format": "uri"}, "exclusiveMinimum": {"default": false, "type": "boolean"}, "id": {"type": "string", "format": "uri"}, "exclusiveMaximum": {"default": false, "type": "boolean"}, "title": {"type": "string"}, "default": {}, "pattern": {"type": "string", "format": "regex"}, "required": {"$ref": "#/definitions/stringArray"}, "patternProperties": {"additionalProperties": {"$ref": "#"}, "default": {}, "type": "object"}, "multipleOf": {"exclusiveMinimum": true, "minimum": 0, "type": "number"}, "properties": {"additionalProperties": {"$ref": "#"}, "default": {}, "type": "object"}, "minItems": {"$ref": "#/definitions/positiveIntegerDefault0"}, "minProperties": {"$ref": "#/definitions/positiveIntegerDefault0"}, "dependencies": {"additionalProperties": {"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]}, "type": "object"}, "maxProperties": {"$ref": "#/definitions/positiveInteger"}, "oneOf": {"$ref": "#/definitions/schemaArray"}, "items": {"default": {}, "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}]}, "additionalProperties": {"default": {}, "anyOf": [{"type": "boolean"}, {"$ref": "#"}]}, "definitions": {"additionalProperties": {"$ref": "#"}, "default": {}, "type": "object"}, "type": {"anyOf": [{"$ref": "#/definitions/simpleTypes"}, {"minItems": 1, "items": {"$ref": "#/definitions/simpleTypes"}, "uniqueItems": true, "type": "array"}]}}}
\ No newline at end of file diff --git a/jsonschema/validators.py b/jsonschema/validators.py index 8826dd1..c080ac8 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -484,88 +484,7 @@ class Draft3Validator(ValidatorMixin, _Draft34CommonMixin, object): validate_divisibleBy = _Draft34CommonMixin._validate_multipleOf - META_SCHEMA = { - "$schema" : "http://json-schema.org/draft-03/schema#", - "id" : "http://json-schema.org/draft-03/schema#", - "type" : "object", - - "properties" : { - "type" : { - "type" : ["string", "array"], - "items" : {"type" : ["string", {"$ref" : "#"}]}, - "uniqueItems" : True, - "default" : "any" - }, - "properties" : { - "type" : "object", - "additionalProperties" : {"$ref" : "#", "type": "object"}, - "default" : {} - }, - "patternProperties" : { - "type" : "object", - "additionalProperties" : {"$ref" : "#"}, - "default" : {} - }, - "additionalProperties" : { - "type" : [{"$ref" : "#"}, "boolean"], "default" : {} - }, - "items" : { - "type" : [{"$ref" : "#"}, "array"], - "items" : {"$ref" : "#"}, - "default" : {} - }, - "additionalItems" : { - "type" : [{"$ref" : "#"}, "boolean"], "default" : {} - }, - "required" : {"type" : "boolean", "default" : False}, - "dependencies" : { - "type" : ["string", "array", "object"], - "additionalProperties" : { - "type" : ["string", "array", {"$ref" : "#"}], - "items" : {"type" : "string"} - }, - "default" : {} - }, - "minimum" : {"type" : "number"}, - "maximum" : {"type" : "number"}, - "exclusiveMinimum" : {"type" : "boolean", "default" : False}, - "exclusiveMaximum" : {"type" : "boolean", "default" : False}, - "minItems" : {"type" : "integer", "minimum" : 0, "default" : 0}, - "maxItems" : {"type" : "integer", "minimum" : 0}, - "uniqueItems" : {"type" : "boolean", "default" : False}, - "pattern" : {"type" : "string", "format" : "regex"}, - "minLength" : {"type" : "integer", "minimum" : 0, "default" : 0}, - "maxLength" : {"type" : "integer"}, - "enum" : {"type" : "array", "minItems" : 1, "uniqueItems" : True}, - "default" : {"type" : "any"}, - "title" : {"type" : "string"}, - "description" : {"type" : "string"}, - "format" : {"type" : "string"}, - "maxDecimal" : {"type" : "number", "minimum" : 0}, - "divisibleBy" : { - "type" : "number", - "minimum" : 0, - "exclusiveMinimum" : True, - "default" : 1 - }, - "disallow" : { - "type" : ["string", "array"], - "items" : {"type" : ["string", {"$ref" : "#"}]}, - "uniqueItems" : True - }, - "extends" : { - "type" : [{"$ref" : "#"}, "array"], - "items" : {"$ref" : "#"}, - "default" : {} - }, - "id" : {"type" : "string", "format" : "uri"}, - "$ref" : {"type" : "string", "format" : "uri"}, - "$schema" : {"type" : "string", "format" : "uri"}, - }, - "dependencies" : { - "exclusiveMinimum" : "minimum", "exclusiveMaximum" : "maximum" - }, - } + META_SCHEMA = _utils.load_schema('draft3') @validates("draft4") @@ -661,166 +580,7 @@ class Draft4Validator(ValidatorMixin, _Draft34CommonMixin, object): validate_multipleOf = _Draft34CommonMixin._validate_multipleOf - META_SCHEMA = { - "id": "http://json-schema.org/draft-04/schema#", - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Core schema meta-schema", - "definitions": { - "schemaArray": { - "type": "array", - "minItems": 1, - "items": {"$ref": "#"} - }, - "positiveInteger": { - "type": "integer", - "minimum": 0 - }, - "positiveIntegerDefault0": { - "allOf": [ - {"$ref": "#/definitions/positiveInteger"}, {"default": 0} - ] - }, - "simpleTypes": { - "enum": [ - "array", - "boolean", - "integer", - "null", - "number", - "object", - "string", - ] - }, - "stringArray": { - "type": "array", - "items": {"type": "string"}, - "minItems": 1, - "uniqueItems": True - } - }, - "type": "object", - "properties": { - "id": { - "type": "string", - "format": "uri" - }, - "$schema": { - "type": "string", - "format": "uri" - }, - "title": { - "type": "string" - }, - "description": { - "type": "string" - }, - "default": {}, - "multipleOf": { - "type": "number", - "minimum": 0, - "exclusiveMinimum": True - }, - "maximum": { - "type": "number" - }, - "exclusiveMaximum": { - "type": "boolean", - "default": False - }, - "minimum": { - "type": "number" - }, - "exclusiveMinimum": { - "type": "boolean", - "default": False - }, - "maxLength": {"$ref": "#/definitions/positiveInteger"}, - "minLength": {"$ref": "#/definitions/positiveIntegerDefault0"}, - "pattern": { - "type": "string", - "format": "regex" - }, - "additionalItems": { - "anyOf": [ - {"type": "boolean"}, - {"$ref": "#"} - ], - "default": {} - }, - "items": { - "anyOf": [ - {"$ref": "#"}, - {"$ref": "#/definitions/schemaArray"} - ], - "default": {} - }, - "maxItems": {"$ref": "#/definitions/positiveInteger"}, - "minItems": {"$ref": "#/definitions/positiveIntegerDefault0"}, - "uniqueItems": { - "type": "boolean", - "default": False - }, - "maxProperties": {"$ref": "#/definitions/positiveInteger"}, - "minProperties": {"$ref": "#/definitions/positiveIntegerDefault0"}, - "required": {"$ref": "#/definitions/stringArray"}, - "additionalProperties": { - "anyOf": [ - {"type": "boolean"}, - {"$ref": "#"} - ], - "default": {} - }, - "definitions": { - "type": "object", - "additionalProperties": {"$ref": "#"}, - "default": {} - }, - "properties": { - "type": "object", - "additionalProperties": {"$ref": "#"}, - "default": {} - }, - "patternProperties": { - "type": "object", - "additionalProperties": {"$ref": "#"}, - "default": {} - }, - "dependencies": { - "type": "object", - "additionalProperties": { - "anyOf": [ - {"$ref": "#"}, - {"$ref": "#/definitions/stringArray"} - ] - } - }, - "enum": { - "type": "array", - "minItems": 1, - "uniqueItems": True - }, - "type": { - "anyOf": [ - {"$ref": "#/definitions/simpleTypes"}, - { - "type": "array", - "items": {"$ref": "#/definitions/simpleTypes"}, - "minItems": 1, - "uniqueItems": True - } - ] - }, - "allOf": {"$ref": "#/definitions/schemaArray"}, - "anyOf": {"$ref": "#/definitions/schemaArray"}, - "oneOf": {"$ref": "#/definitions/schemaArray"}, - "not": {"$ref": "#"} - }, - "dependencies": { - "exclusiveMaximum": ["maximum"], - "exclusiveMinimum": ["minimum"] - }, - "default": {} - } + META_SCHEMA = _utils.load_schema('draft4') class RefResolver(object): |