diff --git a/hyper-schema-output.json b/hyper-schema-output.json index 32bba5df..5c2a9786 100644 --- a/hyper-schema-output.json +++ b/hyper-schema-output.json @@ -4,7 +4,7 @@ "type": "array", "items": { "allOf": [ - {"$ref": "http://json-schema.org/draft-08/links#/definitions/noRequiredFields" } + {"$ref": "http://json-schema.org/draft-08/links#/$defs/noRequiredFields" } ], "type": "object", "required": [ diff --git a/hyper-schema.json b/hyper-schema.json index 4841cd55..82cf32fa 100644 --- a/hyper-schema.json +++ b/hyper-schema.json @@ -2,10 +2,10 @@ "$schema": "http://json-schema.org/draft-08/hyper-schema#", "$id": "http://json-schema.org/draft-08/hyper-schema#", "title": "JSON Hyper-Schema", - "definitions": { + "$defs": { "schemaArray": { "allOf": [ - { "$ref": "http://json-schema.org/draft-08/schema#/definitions/schemaArray" }, + { "$ref": "http://json-schema.org/draft-08/schema#/$defs/schemaArray" }, { "items": { "$ref": "#" } } @@ -27,10 +27,14 @@ "items": { "anyOf": [ { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } + { "$ref": "#/$defs/schemaArray" } ] }, + "$defs": { + "additionalProperties": { "$ref": "#" } + }, "definitions": { + "$comment": "Renamed to $defs, but retained here to ensure compatibility", "additionalProperties": { "$ref": "#" } }, "patternProperties": { @@ -42,9 +46,9 @@ "if": {"$ref": "#"}, "then": {"$ref": "#"}, "else": {"$ref": "#"}, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, + "allOf": { "$ref": "#/$defs/schemaArray" }, + "anyOf": { "$ref": "#/$defs/schemaArray" }, + "oneOf": { "$ref": "#/$defs/schemaArray" }, "not": { "$ref": "#" }, "contains": { "$ref": "#" }, "propertyNames": { "$ref": "#" }, diff --git a/jsonschema-core.xml b/jsonschema-core.xml index 4d04ab69..c3b63621 100644 --- a/jsonschema-core.xml +++ b/jsonschema-core.xml @@ -629,11 +629,11 @@ http://example.com/root.json# - + http://example.com/root.json#foo - http://example.com/root.json#/definitions/A + http://example.com/root.json#/$defs/A - + http://example.com/other.json http://example.com/other.json# - http://example.com/root.json#/definitions/B + http://example.com/root.json#/$defs/B - + http://example.com/other.json#bar - http://example.com/other.json#/definitions/X - http://example.com/root.json#/definitions/B/definitions/X + http://example.com/other.json#/$defs/X + http://example.com/root.json#/$defs/B/$defs/X - + http://example.com/t/inner.json http://example.com/t/inner.json# - http://example.com/other.json#/definitions/Y - http://example.com/root.json#/definitions/B/definitions/Y + http://example.com/other.json#/$defs/Y + http://example.com/root.json#/$defs/B/$defs/Y - + urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f# - http://example.com/root.json#/definitions/C + http://example.com/root.json#/$defs/C @@ -776,7 +776,7 @@ "type": "array", "items": { "$ref": "#item" } }, - "definitions": { + "$defs": { "single": { "$id": "#item", "type": "object", @@ -788,7 +788,7 @@ - When an implementation encounters the <#/definitions/single> schema, + When an implementation encounters the <#/$defs/single> schema, it resolves the "$id" URI reference against the current base URI to form <http://example.net/root.json#item>. @@ -814,6 +814,40 @@ + +
+ + The "$defs" keyword provides a standardized location for schema + authors to inline re-usable JSON Schemas into a more general schema. + The keyword does not directly affect the validation result. + + + This keyword's value MUST be an object. + Each member value of this object MUST be a valid JSON Schema. + + + As an example, here is a schema describing an array of positive + integers, where the positive integer constraint is a subschema in + "$defs": + +
+ + + +
+
+
@@ -1172,7 +1206,7 @@ User-Agent: product-name/5.4.1 so-cool-json-schema/1.0.2 curl/7.43.0 - + Moved "definitions" from the Validation specification here as "$defs" diff --git a/jsonschema-hyperschema.xml b/jsonschema-hyperschema.xml index 3bfbd98d..5631b0da 100644 --- a/jsonschema-hyperschema.xml +++ b/jsonschema-hyperschema.xml @@ -1628,7 +1628,7 @@ Link: rel=describedBy "type": "object", "required": ["data"], "properties": { - "id": {"$ref": "#/definitions/id"}, + "id": {"$ref": "#/$defs/id"}, "data": true }, "links": [ @@ -1639,7 +1639,7 @@ Link: rel=describedBy "targetSchema": {"$ref": "#"} } ], - "definitions": { + "$defs": { "id": { "type": "integer", "minimum": 1, @@ -1652,7 +1652,7 @@ Link: rel=describedBy Our "thing" has a server-assigned id, which is required in order to construct the "self" link. It also has a "data" field which can be - of any type. The reason for the "definitions" section will be clear + of any type. The reason for the "$defs" section will be clear in the next example. @@ -1678,7 +1678,7 @@ Link: rel=describedBy "hrefSchema": { "required": ["id"], "properties": { - "id": {"$ref": "thing#/definitions/id"} + "id": {"$ref": "thing#/$defs/id"} } }, "targetSchema": {"$ref": "thing#"} @@ -1993,7 +1993,7 @@ Link: rev=up "type": "object", "required": ["data"], "properties": { - "id": {"$ref": "#/definitions/id"}, + "id": {"$ref": "#/$defs/id"}, "data": true }, "links": [ @@ -2009,7 +2009,7 @@ Link: rev=up "submissionSchema": {"$ref": "#"} } ], - "definitions": { + "$defs": { "id": { "type": "integer", "minimum": 1, @@ -2206,9 +2206,9 @@ Link: rev=up "meta": { "type": "object", "properties": { - "prev": {"$ref": "#/definitions/pagination"}, - "current": {"$ref": "#/definitions/pagination"}, - "next": {"$ref": "#/definitions/pagination"} + "prev": {"$ref": "#/$defs/pagination"}, + "current": {"$ref": "#/$defs/pagination"}, + "next": {"$ref": "#/$defs/pagination"} } } }, @@ -2242,7 +2242,7 @@ Link: rev=up "targetSchema": {"$ref": "#"} } ], - "definitions": { + "$defs": { "pagination": { "type": "object", "properties": { @@ -2348,7 +2348,7 @@ Link: rev=up "rel": "tag:rel.example.com,2017:thing-collection", "href": "/things{?offset,limit}", "hrefSchema": { - "$ref": "thing-collection#/definitions/pagination" + "$ref": "thing-collection#/$defs/pagination" }, "submissionSchema": { "$ref": "thing#" diff --git a/jsonschema-validation.xml b/jsonschema-validation.xml index a2c751af..1d1d6ed9 100644 --- a/jsonschema-validation.xml +++ b/jsonschema-validation.xml @@ -1233,40 +1233,6 @@
-
- - The "definitions" keywords provides a standardized location for schema - authors to inline re-usable JSON Schemas into a more general schema. - The keyword does not directly affect the validation result. - - - This keyword's value MUST be an object. - Each member value of this object MUST be a valid JSON Schema. - - - As an example, here is a schema describing an array of positive - integers, where the positive integer constraint is a subschema in - "definitions": - -
- - - -
-
-
-
Schema validation is a useful mechanism for annotating instance data @@ -1470,6 +1436,23 @@ &RFC4329; +
+ + Several keywords have been moved from this document into the + Core Specification as of this draft, in some + cases with re-naming or other changes. This affects the following former + validation keywords: + + + Renamed to "$defs" to match "$ref" and be shorter to type. + Schema vocabulary authors SHOULD NOT define a "definitions" keyword + with different behavior in order to avoid invalidating schemas that + still use the older name. + + + +
+
Thanks to @@ -1503,7 +1486,7 @@ - + Moved "definitions" to the core spec as "$defs" diff --git a/links.json b/links.json index c95b7bd3..addd1f06 100644 --- a/links.json +++ b/links.json @@ -4,9 +4,9 @@ "title": "Link Description Object", "allOf": [ { "required": [ "rel", "href" ] }, - { "$ref": "#/definitions/noRequiredFields" } + { "$ref": "#/$defs/noRequiredFields" } ], - "definitions": { + "$defs": { "noRequiredFields": { "type": "object", "properties": { diff --git a/schema.json b/schema.json index 8632f19f..182eefb0 100644 --- a/schema.json +++ b/schema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-08/schema#", "$id": "http://json-schema.org/draft-08/schema#", "title": "Core schema meta-schema", - "definitions": { + "$defs": { "schemaArray": { "type": "array", "minItems": 1, @@ -14,7 +14,7 @@ }, "nonNegativeIntegerDefault0": { "allOf": [ - { "$ref": "#/definitions/nonNegativeInteger" }, + { "$ref": "#/$defs/nonNegativeInteger" }, { "default": 0 } ] }, @@ -53,6 +53,17 @@ "$comment": { "type": "string" }, + "$defs": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, + "definitions": { + "$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.", + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, "title": { "type": "string" }, @@ -84,8 +95,8 @@ "exclusiveMinimum": { "type": "number" }, - "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, - "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "maxLength": { "$ref": "#/$defs/nonNegativeInteger" }, + "minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, "pattern": { "type": "string", "format": "regex" @@ -94,26 +105,21 @@ "items": { "anyOf": [ { "$ref": "#" }, - { "$ref": "#/definitions/schemaArray" } + { "$ref": "#/$defs/schemaArray" } ], "default": true }, - "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, - "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "maxItems": { "$ref": "#/$defs/nonNegativeInteger" }, + "minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, "uniqueItems": { "type": "boolean", "default": false }, "contains": { "$ref": "#" }, - "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, - "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, - "required": { "$ref": "#/definitions/stringArray" }, + "maxProperties": { "$ref": "#/$defs/nonNegativeInteger" }, + "minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, + "required": { "$ref": "#/$defs/stringArray" }, "additionalProperties": { "$ref": "#" }, - "definitions": { - "type": "object", - "additionalProperties": { "$ref": "#" }, - "default": {} - }, "properties": { "type": "object", "additionalProperties": { "$ref": "#" }, @@ -130,7 +136,7 @@ "additionalProperties": { "anyOf": [ { "$ref": "#" }, - { "$ref": "#/definitions/stringArray" } + { "$ref": "#/$defs/stringArray" } ] } }, @@ -144,10 +150,10 @@ }, "type": { "anyOf": [ - { "$ref": "#/definitions/simpleTypes" }, + { "$ref": "#/$defs/simpleTypes" }, { "type": "array", - "items": { "$ref": "#/definitions/simpleTypes" }, + "items": { "$ref": "#/$defs/simpleTypes" }, "minItems": 1, "uniqueItems": true } @@ -159,9 +165,9 @@ "if": {"$ref": "#"}, "then": {"$ref": "#"}, "else": {"$ref": "#"}, - "allOf": { "$ref": "#/definitions/schemaArray" }, - "anyOf": { "$ref": "#/definitions/schemaArray" }, - "oneOf": { "$ref": "#/definitions/schemaArray" }, + "allOf": { "$ref": "#/$defs/schemaArray" }, + "anyOf": { "$ref": "#/$defs/schemaArray" }, + "oneOf": { "$ref": "#/$defs/schemaArray" }, "not": { "$ref": "#" } }, "default": true