From ef13c4963fc762cc4f30003e4461090b0b0411c8 Mon Sep 17 00:00:00 2001 From: handrews Date: Sat, 3 Dec 2016 15:13:49 -0800 Subject: [PATCH 1/4] Standardize format of meta-schemas. This brings formatting and most of the initial field ordering in line with the Draft 05 meta-schemas proposed in the web site repo. Also ensure that hyper-schema's definition of "schemaArray" cannot get out of sync with schema's, and add the link schema. --- hyper-schema.json | 59 +++++++++++++++++++++++++---------------------- links.json | 42 +++++++++++++++++++++++++++++++++ schema.json | 14 ++++++++--- 3 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 links.json diff --git a/hyper-schema.json b/hyper-schema.json index ec9c1441..158c19b2 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -2,48 +2,46 @@ "$schema": "http://json-schema.org/draft/hyper-schema#", "id": "http://json-schema.org/draft/hyper-schema#", "title": "JSON Hyper-Schema", - "allOf": [ - {"$ref": "http://json-schema.org/draft-04/schema#"} - ], + "allOf": [ { "$ref": "http://json-schema.org/draft/schema#" } ], "properties": { "additionalItems": { "anyOf": [ - {"type": "boolean"}, - {"$ref": "#"} + { "type": "boolean" }, + { "$ref": "#" } ] }, "additionalProperties": { "anyOf": [ - {"type": "boolean"}, - {"$ref": "#"} + { "type": "boolean" }, + { "$ref": "#" } ] }, "dependencies": { "additionalProperties": { "anyOf": [ - {"$ref": "#"}, - {"type": "array"} + { "$ref": "#" }, + { "type": "array" } ] } }, "items": { "anyOf": [ - {"$ref": "#"}, - {"$ref": "#/definitions/schemaArray"} + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } ] }, "definitions": { - "additionalProperties": {"$ref": "#"} + "additionalProperties": { "$ref": "#" } }, "patternProperties": { - "additionalProperties": {"$ref": "#"} + "additionalProperties": { "$ref": "#" } }, "properties": { - "additionalProperties": {"$ref": "#"} + "additionalProperties": { "$ref": "#" } }, - "allOf": {"$ref": "#/definitions/schemaArray"}, - "anyOf": {"$ref": "#/definitions/schemaArray"}, - "oneOf": {"$ref": "#/definitions/schemaArray"}, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, "not": { "$ref": "#" }, "base": { @@ -52,7 +50,7 @@ }, "links": { "type": "array", - "items": {"$ref": "#/definitions/linkDescription"} + "items": { "$ref": "#/definitions/linkDescription" } }, "media": { "type": "object", @@ -66,17 +64,26 @@ "type": "string" } } + }, + "readOnly": { + "description": "If true, indicates that the value of this property is controlled by the server.", + "type": "boolean", + "default": "false" } }, "definitions": { - "schemaArray": { - "type": "array", - "items": {"$ref": "#"} + "schemaArray": [ + "allOf": [ + { "$ref": "http://json-schema.org/drafts/schema" } + { + "items": { "$ref": "#" } + } + ] }, "linkDescription": { "title": "Link Description Object", "type": "object", - "required": ["href"], + "required": [ "href" ], "properties": { "href": { "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", @@ -92,7 +99,7 @@ }, "targetSchema": { "description": "JSON Schema describing the link target", - "$ref": "#" + "allOf": [ { "$ref": "#" } ] }, "mediaType": { "description": "media type (as defined by RFC 2046) describing the link target", @@ -109,7 +116,7 @@ }, "schema": { "description": "Schema describing the data to submit along with the request", - "$ref": "#" + "allOf": [ { "$ref": "#" } ] } } } @@ -118,10 +125,6 @@ { "rel": "self", "href": "{+id}" - }, - { - "rel": "full", - "href": "{+($ref)}" } ] } diff --git a/links.json b/links.json new file mode 100644 index 00000000..3c9cd1c6 --- /dev/null +++ b/links.json @@ -0,0 +1,42 @@ +{ + "$schema": "http://json-schema.org/draft/hyper-schema#", + "id": "http://json-schema.org/draft/links#", + "title": "Link Description Object", + "type": "object", + "required": [ "href" ], + "properties": { + "href": { + "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", + "type": "string" + }, + "rel": { + "description": "relation to the target resource of the link", + "type": "string" + }, + "title": { + "description": "a title for the link", + "type": "string" + }, + "targetSchema": { + "description": "JSON Schema describing the link target", + "allOf": [ { "$ref": "hyper-schema#" } ] + }, + "mediaType": { + "description": "media type (as defined by RFC 2046) describing the link target", + "type": "string" + }, + "method": { + "description": "specifies that the client can construct a templated query (\"get\") or non-idempotent request (\"post\") to a resource.", + "type": "string" + }, + "encType": { + "description": "The media type in which to submit data along with the request", + "type": "string", + "default": "application/json" + }, + "schema": { + "description": "Schema describing the data to submit along with the request", + "allOf": [ { "$ref": "hyper-schema#" } ] + } + } +} diff --git a/schema.json b/schema.json index d44cd480..3b9019c8 100644 --- a/schema.json +++ b/schema.json @@ -1,7 +1,7 @@ { - "id": "http://json-schema.org/draft/schema#", "$schema": "http://json-schema.org/draft/schema#", - "description": "Core schema meta-schema", + "id": "http://json-schema.org/draft/schema#", + "title": "Core schema meta-schema", "definitions": { "schemaArray": { "type": "array", @@ -19,7 +19,15 @@ ] }, "simpleTypes": { - "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ] + "enum": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ] }, "stringArray": { "type": "array", From a8be3fd60cdbfb04ebf6e7a6b4305063d2be4d4b Mon Sep 17 00:00:00 2001 From: handrews Date: Sat, 3 Dec 2016 15:15:16 -0800 Subject: [PATCH 2/4] Move hyper-schema definitions to top. This brings it in line with the core/validation meta-schema and with the standardized format proposed for Draft 05. --- hyper-schema.json | 100 +++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/hyper-schema.json b/hyper-schema.json index 158c19b2..01295b2a 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -2,6 +2,56 @@ "$schema": "http://json-schema.org/draft/hyper-schema#", "id": "http://json-schema.org/draft/hyper-schema#", "title": "JSON Hyper-Schema", + "definitions": { + "schemaArray": [ + "allOf": [ + { "$ref": "http://json-schema.org/drafts/schema" } + { + "items": { "$ref": "#" } + } + ] + }, + "linkDescription": { + "title": "Link Description Object", + "type": "object", + "required": [ "href" ], + "properties": { + "href": { + "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", + "type": "string" + }, + "rel": { + "description": "relation to the target resource of the link", + "type": "string" + }, + "title": { + "description": "a title for the link", + "type": "string" + }, + "targetSchema": { + "description": "JSON Schema describing the link target", + "allOf": [ { "$ref": "#" } ] + }, + "mediaType": { + "description": "media type (as defined by RFC 2046) describing the link target", + "type": "string" + }, + "method": { + "description": "specifies that the client can construct a templated query (\"get\") or non-idempotent request (\"post\") to a resource.", + "type": "string" + }, + "encType": { + "description": "The media type in which to submit data along with the request", + "type": "string", + "default": "application/json" + }, + "schema": { + "description": "Schema describing the data to submit along with the request", + "allOf": [ { "$ref": "#" } ] + } + } + } + }, "allOf": [ { "$ref": "http://json-schema.org/draft/schema#" } ], "properties": { "additionalItems": { @@ -71,56 +121,6 @@ "default": "false" } }, - "definitions": { - "schemaArray": [ - "allOf": [ - { "$ref": "http://json-schema.org/drafts/schema" } - { - "items": { "$ref": "#" } - } - ] - }, - "linkDescription": { - "title": "Link Description Object", - "type": "object", - "required": [ "href" ], - "properties": { - "href": { - "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing", - "type": "string" - }, - "rel": { - "description": "relation to the target resource of the link", - "type": "string" - }, - "title": { - "description": "a title for the link", - "type": "string" - }, - "targetSchema": { - "description": "JSON Schema describing the link target", - "allOf": [ { "$ref": "#" } ] - }, - "mediaType": { - "description": "media type (as defined by RFC 2046) describing the link target", - "type": "string" - }, - "method": { - "description": "specifies that the client can construct a templated query (\"get\") or non-idempotent request (\"post\") to a resource.", - "type": "string" - }, - "encType": { - "description": "The media type in which to submit data along with the request", - "type": "string", - "default": "application/json" - }, - "schema": { - "description": "Schema describing the data to submit along with the request", - "allOf": [ { "$ref": "#" } ] - } - } - } - }, "links": [ { "rel": "self", From 018fe924ffc22c53b5807cb74c44a4ea890f6c79 Mon Sep 17 00:00:00 2001 From: handrews Date: Sat, 3 Dec 2016 15:41:22 -0800 Subject: [PATCH 3/4] Add "$ref" for subschemas. This is the same approach used in the PR for Draft 05 meta-schemas in the web site repo. --- hyper-schema.json | 38 +++++++++++++++++++++++++------------- schema.json | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/hyper-schema.json b/hyper-schema.json index 01295b2a..204def3e 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -3,11 +3,11 @@ "id": "http://json-schema.org/draft/hyper-schema#", "title": "JSON Hyper-Schema", "definitions": { - "schemaArray": [ + "schemaArray": { "allOf": [ - { "$ref": "http://json-schema.org/drafts/schema" } + { "$ref": "http://json-schema.org/drafts/schema" }, { - "items": { "$ref": "#" } + "items": { "$ref": "#/definitions/subSchema" } } ] }, @@ -30,7 +30,7 @@ }, "targetSchema": { "description": "JSON Schema describing the link target", - "allOf": [ { "$ref": "#" } ] + "allOf": [ { "$ref": "#/definitions/subSchema" } ] }, "mediaType": { "description": "media type (as defined by RFC 2046) describing the link target", @@ -47,52 +47,64 @@ }, "schema": { "description": "Schema describing the data to submit along with the request", - "allOf": [ { "$ref": "#" } ] + "allOf": [ { "$ref": "#/definitions/subSchema" } ] } } + }, + "subSchema": { + "oneOf": [ + { + "allOf": [ + { "$ref": "#" }, + { "$ref": "http://json-schema.org/draft/schema#/definitions/notJsonReference" } + ] + }, + { "$ref": "http://json-schema.org/draft/schema#/definitions/jsonReference" } + ] } }, + "allOf": [ { "$ref": "http://json-schema.org/draft/schema#" } ], "properties": { "additionalItems": { "anyOf": [ { "type": "boolean" }, - { "$ref": "#" } + { "$ref": "#/definitions/subSchema" } ] }, "additionalProperties": { "anyOf": [ { "type": "boolean" }, - { "$ref": "#" } + { "$ref": "#/definitions/subSchema" } ] }, "dependencies": { "additionalProperties": { "anyOf": [ - { "$ref": "#" }, + { "$ref": "#/definitions/subSchema" }, { "type": "array" } ] } }, "items": { "anyOf": [ - { "$ref": "#" }, + { "$ref": "#/definitions/subSchema" }, { "$ref": "#/definitions/schemaArray" } ] }, "definitions": { - "additionalProperties": { "$ref": "#" } + "additionalProperties": { "$ref": "#/definitions/subSchema" } }, "patternProperties": { - "additionalProperties": { "$ref": "#" } + "additionalProperties": { "$ref": "#/definitions/subSchema" } }, "properties": { - "additionalProperties": { "$ref": "#" } + "additionalProperties": { "$ref": "#/definitions/subSchema" } }, "allOf": { "$ref": "#/definitions/schemaArray" }, "anyOf": { "$ref": "#/definitions/schemaArray" }, "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" }, + "not": { "$ref": "#/definitions/subSchema" }, "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.", diff --git a/schema.json b/schema.json index 3b9019c8..9d90fc15 100644 --- a/schema.json +++ b/schema.json @@ -3,10 +3,25 @@ "id": "http://json-schema.org/draft/schema#", "title": "Core schema meta-schema", "definitions": { + "jsonReferece": { + "type": "object", + "properties": { + "$ref": { + "type": "string", + "format": "uriref" + } + }, + "required": [ "$ref" ] + }, + "notJsonReference": { + "not": { + "required": [ "$ref" ] + } + }, "schemaArray": { "type": "array", "minItems": 1, - "items": { "$ref": "#" } + "items": { "$ref": "#/definitions/subSchema" } }, "positiveInteger": { "type": "integer", @@ -33,6 +48,17 @@ "type": "array", "items": { "type": "string" }, "uniqueItems": true + }, + "subSchema": { + "oneOf": [ + { + "allOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/notJsonReference" } + ] + }, + { "$ref": "#/definitions/jsonReference" } + ] } }, "type": "object", @@ -80,13 +106,13 @@ "additionalItems": { "anyOf": [ { "type": "boolean" }, - { "$ref": "#" } + { "$ref": "#/definitions/subSchema" } ], "default": {} }, "items": { "anyOf": [ - { "$ref": "#" }, + { "$ref": "#/definitions/subSchema" }, { "$ref": "#/definitions/schemaArray" } ], "default": {} @@ -104,30 +130,30 @@ "additionalProperties": { "anyOf": [ { "type": "boolean" }, - { "$ref": "#" } + { "$ref": "#/definitions/subSchema" } ], "default": {} }, "definitions": { "type": "object", - "additionalProperties": { "$ref": "#" }, + "additionalProperties": { "$ref": "#/definitions/subSchema" }, "default": {} }, "properties": { "type": "object", - "additionalProperties": { "$ref": "#" }, + "additionalProperties": { "$ref": "#/definitions/subSchema" }, "default": {} }, "patternProperties": { "type": "object", - "additionalProperties": { "$ref": "#" }, + "additionalProperties": { "$ref": "#/definitions/subSchema" }, "default": {} }, "dependencies": { "type": "object", "additionalProperties": { "anyOf": [ - { "$ref": "#" }, + { "$ref": "#/definitions/subSchema" }, { "$ref": "#/definitions/stringArray" } ] } @@ -153,7 +179,7 @@ "allOf": { "$ref": "#/definitions/schemaArray" }, "anyOf": { "$ref": "#/definitions/schemaArray" }, "oneOf": { "$ref": "#/definitions/schemaArray" }, - "not": { "$ref": "#" } + "not": { "$ref": "#/definitions/subSchema" } }, "dependencies": { "exclusiveMaximum": [ "maximum" ], From 983e9d30cf1c9e0dedd058869a8a03d39424d36b Mon Sep 17 00:00:00 2001 From: handrews Date: Sat, 3 Dec 2016 15:49:58 -0800 Subject: [PATCH 4/4] Change exclusives in meta-schema, add default. Use the numeric form of exclusiveMinimum in uniqueItems. Update the schema to take either the boolean form (with dependencies and default) or the numeric form for exclusiveMinimum and exclusiveMaximum. Also add empty array as default for string arrays. This brings the meta-schema in line with the specification. --- schema.json | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/schema.json b/schema.json index 9d90fc15..206ed587 100644 --- a/schema.json +++ b/schema.json @@ -20,7 +20,6 @@ }, "schemaArray": { "type": "array", - "minItems": 1, "items": { "$ref": "#/definitions/subSchema" } }, "positiveInteger": { @@ -47,7 +46,8 @@ "stringArray": { "type": "array", "items": { "type": "string" }, - "uniqueItems": true + "uniqueItems": true, + "default": [] }, "subSchema": { "oneOf": [ @@ -80,23 +80,14 @@ "default": {}, "multipleOf": { "type": "number", - "minimum": 0, - "exclusiveMinimum": true + "exclusiveMinimum": 0 }, "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": { @@ -181,9 +172,39 @@ "oneOf": { "$ref": "#/definitions/schemaArray" }, "not": { "$ref": "#/definitions/subSchema" } }, - "dependencies": { - "exclusiveMaximum": [ "maximum" ], - "exclusiveMinimum": [ "minimum" ] - }, + "allOf": [ + { + "oneOf": [ + { + "exclusiveMaximum": { "type": "number" } + }, + { + "exclusiveMaximum": { + "type": "boolean", + "default": false + }, + "dependencies": { + "exclusiveMaximum": [ "maximum" ] + } + } + ] + }, + { + "oneOf": [ + { + "exclusiveMinimum": { "type": "number" } + }, + { + "exclusiveMinimum": { + "type": "boolean", + "default": false + }, + "dependencies": { + "exclusiveMinimum": [ "minimum" ] + } + } + ] + } + ], "default": {} }