From ed6078413e9dcc9d855706671577c5a9be1f7220 Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Mon, 12 Dec 2016 11:29:17 -0800 Subject: [PATCH 1/2] Allow boolean schemas everywhere (meta-schema). --- schema.json | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/schema.json b/schema.json index 3b9019c8..b2ab5e30 100644 --- a/schema.json +++ b/schema.json @@ -35,7 +35,7 @@ "uniqueItems": true } }, - "type": "object", + "type": ["object", "boolean"], "properties": { "id": { "type": "string", @@ -77,13 +77,7 @@ "type": "string", "format": "regex" }, - "additionalItems": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ], - "default": {} - }, + "additionalItems": { "$ref": "#" }, "items": { "anyOf": [ { "$ref": "#" }, @@ -101,13 +95,7 @@ "maxProperties": { "$ref": "#/definitions/positiveInteger" }, "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" }, "required": { "$ref": "#/definitions/stringArray" }, - "additionalProperties": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ], - "default": {} - }, + "additionalProperties": { "$ref": "#" }, "definitions": { "type": "object", "additionalProperties": { "$ref": "#" }, From d9e3304713d194df91b931e291a8b4019c99c844 Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Tue, 13 Dec 2016 11:26:31 -0800 Subject: [PATCH 2/2] Allow "$ref" in place of any schema. This includes root schemas and subschemas. --- hyper-schema.json | 138 ++++++++++++++------------ schema.json | 244 +++++++++++++++++++++++++--------------------- 2 files changed, 210 insertions(+), 172 deletions(-) diff --git a/hyper-schema.json b/hyper-schema.json index b633bd50..a3512a27 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -50,77 +50,89 @@ "allOf": [ { "$ref": "#" } ] } } - } - }, - "allOf": [ { "$ref": "http://json-schema.org/draft/schema#" } ], - "properties": { - "additionalItems": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ] - }, - "additionalProperties": { - "anyOf": [ - { "type": "boolean" }, - { "$ref": "#" } - ] - }, - "dependencies": { - "additionalProperties": { - "anyOf": [ - { "$ref": "#" }, - { "type": "array" } - ] - } - }, - "items": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } - ] - }, - "definitions": { - "additionalProperties": { "$ref": "#" } - }, - "patternProperties": { - "additionalProperties": { "$ref": "#" } - }, - "properties": { - "additionalProperties": { "$ref": "#" } }, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" }, - - "base": { - "description": "URI Template resolved as for the 'href' keyword in the Link Description Object. The resulting URI Reference is resolved against the current URI base and sets the new URI base for URI references within the instance.", - "type": "string" - }, - "links": { - "type": "array", - "items": { "$ref": "#/definitions/linkDescription" } - }, - "media": { - "type": "object", + "hyperSchema": { + "allOf": [ { "$ref": "http://json-schema.org/draft/schema#/definitions/schema" } ], "properties": { - "type": { - "description": "A media type, as described in RFC 2046", - "type": "string" + "additionalItems": { + "anyOf": [ + { "type": "boolean" }, + { "$ref": "#" } + ] + }, + "additionalProperties": { + "anyOf": [ + { "type": "boolean" }, + { "$ref": "#" } + ] + }, + "dependencies": { + "additionalProperties": { + "anyOf": [ + { "$ref": "#" }, + { "type": "array" } + ] + } + }, + "items": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } + ] }, - "binaryEncoding": { - "description": "A content encoding scheme, as described in RFC 2045", + "definitions": { + "additionalProperties": { "$ref": "#" } + }, + "patternProperties": { + "additionalProperties": { "$ref": "#" } + }, + "properties": { + "additionalProperties": { "$ref": "#" } + }, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" }, + + "base": { + "description": "URI Template resolved as for the 'href' keyword in the Link Description Object. The resulting URI Reference is resolved against the current URI base and sets the new URI base for URI references within the instance.", "type": "string" + }, + "links": { + "type": "array", + "items": { "$ref": "#/definitions/linkDescription" } + }, + "media": { + "type": "object", + "properties": { + "type": { + "description": "A media type, as described in RFC 2046", + "type": "string" + }, + "binaryEncoding": { + "description": "A content encoding scheme, as described in RFC 2045", + "type": "string" + } + } + }, + "readOnly": { + "description": "If true, indicates that the value of this property is controlled by the server.", + "type": "boolean", + "default": "false" } } - }, - "readOnly": { - "description": "If true, indicates that the value of this property is controlled by the server.", - "type": "boolean", - "default": "false" } }, + "oneOf": [ + { + "allOf": [ + { "$ref": "#/definitions/hyperSchema" }, + { "$ref": "http://json-schema.org/drafts/schema#/definitions/notJsonReference" } + ] + }, + { "$ref": "http://json-schema.org/drafts/schema#/definitions/jsonReference" } + ], + "default": {}, "links": [ { "rel": "self", diff --git a/schema.json b/schema.json index 15502e9b..f1fb8b58 100644 --- a/schema.json +++ b/schema.json @@ -3,6 +3,21 @@ "id": "http://json-schema.org/draft/schema#", "title": "Core schema meta-schema", "definitions": { + "jsonReference": { + "type": "object", + "properties": { + "$ref": { + "type": "string", + "format": "uriref" + } + }, + "required": [ "$ref" ] + }, + "notJsonReference": { + "not": { + "required": [ "$ref" ] + } + }, "schemaArray": { "type": "array", "minItems": 1, @@ -33,120 +48,131 @@ "type": "array", "items": { "type": "string" }, "uniqueItems": true - } - }, - "type": ["object", "boolean"], - "properties": { - "id": { - "type": "string", - "format": "uriref" - }, - "$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": { "$ref": "#" }, - "items": { - "anyOf": [ - { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } - ], - "default": {} - }, - "maxItems": { "$ref": "#/definitions/positiveInteger" }, - "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" }, - "uniqueItems": { - "type": "boolean", - "default": false - }, - "contains": { "$ref": "#" }, - "maxProperties": { "$ref": "#/definitions/positiveInteger" }, - "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" }, - "required": { "$ref": "#/definitions/stringArray" }, - "additionalProperties": { "$ref": "#" }, - "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" } - ] - } - }, - "propertyNames": { "$ref": "#" }, - "const": {}, - "enum": { - "type": "array", - "minItems": 1, - "uniqueItems": true }, - "type": { - "anyOf": [ - { "$ref": "#/definitions/simpleTypes" }, - { + "schema": { + "type": ["object", "boolean"], + "properties": { + "id": { + "type": "string", + "format": "uriref" + }, + "$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": { "$ref": "#" }, + "items": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } + ], + "default": {} + }, + "maxItems": { "$ref": "#/definitions/positiveInteger" }, + "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" }, + "uniqueItems": { + "type": "boolean", + "default": false + }, + "contains": { "$ref": "#" }, + "maxProperties": { "$ref": "#/definitions/positiveInteger" }, + "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" }, + "required": { "$ref": "#/definitions/stringArray" }, + "additionalProperties": { "$ref": "#" }, + "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" } + ] + } + }, + "propertyNames": { "$ref": "#" }, + "const": {}, + "enum": { "type": "array", - "items": { "$ref": "#/definitions/simpleTypes" }, "minItems": 1, "uniqueItems": true - } + }, + "type": { + "anyOf": [ + { "$ref": "#/definitions/simpleTypes" }, + { + "type": "array", + "items": { "$ref": "#/definitions/simpleTypes" }, + "minItems": 1, + "uniqueItems": true + } + ] + }, + "format": { "type": "string" }, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" } + }, + "dependencies": { + "exclusiveMaximum": [ "maximum" ], + "exclusiveMinimum": [ "minimum" ] + } + } + }, + "oneOf": [ + { + "allOf": [ + { "$ref": "#/definitions/schema" }, + { "$ref": "#/definitions/notJsonReference" } ] }, - "format": { "type": "string" }, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" } - }, - "dependencies": { - "exclusiveMaximum": [ "maximum" ], - "exclusiveMinimum": [ "minimum" ] - }, + { "$ref": "#/definitions/jsonReference" } + ], "default": {} }