Skip to content

Commit e4bdee0

Browse files
authored
Merge pull request #570 from handrews/defs
Move "definitions" to core as "$defs", start appendix on moved/renamed keywords
2 parents 4d05da4 + 6e2eb72 commit e4bdee0

7 files changed

+120
-93
lines changed

hyper-schema-output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "array",
55
"items": {
66
"allOf": [
7-
{"$ref": "http://json-schema.org/draft-08/links#/definitions/noRequiredFields" }
7+
{"$ref": "http://json-schema.org/draft-08/links#/$defs/noRequiredFields" }
88
],
99
"type": "object",
1010
"required": [

hyper-schema.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"$schema": "http://json-schema.org/draft-08/hyper-schema#",
33
"$id": "http://json-schema.org/draft-08/hyper-schema#",
44
"title": "JSON Hyper-Schema",
5-
"definitions": {
5+
"$defs": {
66
"schemaArray": {
77
"allOf": [
8-
{ "$ref": "http://json-schema.org/draft-08/schema#/definitions/schemaArray" },
8+
{ "$ref": "http://json-schema.org/draft-08/schema#/$defs/schemaArray" },
99
{
1010
"items": { "$ref": "#" }
1111
}
@@ -27,10 +27,14 @@
2727
"items": {
2828
"anyOf": [
2929
{ "$ref": "#" },
30-
{ "$ref": "#/definitions/schemaArray" }
30+
{ "$ref": "#/$defs/schemaArray" }
3131
]
3232
},
33+
"$defs": {
34+
"additionalProperties": { "$ref": "#" }
35+
},
3336
"definitions": {
37+
"$comment": "Renamed to $defs, but retained here to ensure compatibility",
3438
"additionalProperties": { "$ref": "#" }
3539
},
3640
"patternProperties": {
@@ -42,9 +46,9 @@
4246
"if": {"$ref": "#"},
4347
"then": {"$ref": "#"},
4448
"else": {"$ref": "#"},
45-
"allOf": { "$ref": "#/definitions/schemaArray" },
46-
"anyOf": { "$ref": "#/definitions/schemaArray" },
47-
"oneOf": { "$ref": "#/definitions/schemaArray" },
49+
"allOf": { "$ref": "#/$defs/schemaArray" },
50+
"anyOf": { "$ref": "#/$defs/schemaArray" },
51+
"oneOf": { "$ref": "#/$defs/schemaArray" },
4852
"not": { "$ref": "#" },
4953
"contains": { "$ref": "#" },
5054
"propertyNames": { "$ref": "#" },

jsonschema-core.xml

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,11 @@
629629
<![CDATA[
630630
{
631631
"$id": "http://example.com/root.json",
632-
"definitions": {
632+
"$defs": {
633633
"A": { "$id": "#foo" },
634634
"B": {
635635
"$id": "other.json",
636-
"definitions": {
636+
"$defs": {
637637
"X": { "$id": "#bar" },
638638
"Y": { "$id": "t/inner.json" }
639639
}
@@ -660,39 +660,39 @@
660660
<t>http://example.com/root.json#</t>
661661
</list>
662662
</t>
663-
<t hangText="#/definitions/A">
663+
<t hangText="#/$defs/A">
664664
<list>
665665
<t>http://example.com/root.json#foo</t>
666-
<t>http://example.com/root.json#/definitions/A</t>
666+
<t>http://example.com/root.json#/$defs/A</t>
667667
</list>
668668
</t>
669-
<t hangText="#/definitions/B">
669+
<t hangText="#/$defs/B">
670670
<list>
671671
<t>http://example.com/other.json</t>
672672
<t>http://example.com/other.json#</t>
673-
<t>http://example.com/root.json#/definitions/B</t>
673+
<t>http://example.com/root.json#/$defs/B</t>
674674
</list>
675675
</t>
676-
<t hangText="#/definitions/B/definitions/X">
676+
<t hangText="#/$defs/B/$defs/X">
677677
<list>
678678
<t>http://example.com/other.json#bar</t>
679-
<t>http://example.com/other.json#/definitions/X</t>
680-
<t>http://example.com/root.json#/definitions/B/definitions/X</t>
679+
<t>http://example.com/other.json#/$defs/X</t>
680+
<t>http://example.com/root.json#/$defs/B/$defs/X</t>
681681
</list>
682682
</t>
683-
<t hangText="#/definitions/B/definitions/Y">
683+
<t hangText="#/$defs/B/$defs/Y">
684684
<list>
685685
<t>http://example.com/t/inner.json</t>
686686
<t>http://example.com/t/inner.json#</t>
687-
<t>http://example.com/other.json#/definitions/Y</t>
688-
<t>http://example.com/root.json#/definitions/B/definitions/Y</t>
687+
<t>http://example.com/other.json#/$defs/Y</t>
688+
<t>http://example.com/root.json#/$defs/B/$defs/Y</t>
689689
</list>
690690
</t>
691-
<t hangText="#/definitions/C">
691+
<t hangText="#/$defs/C">
692692
<list>
693693
<t>urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f</t>
694694
<t>urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#</t>
695-
<t>http://example.com/root.json#/definitions/C</t>
695+
<t>http://example.com/root.json#/$defs/C</t>
696696
</list>
697697
</t>
698698
</list>
@@ -776,7 +776,7 @@
776776
"type": "array",
777777
"items": { "$ref": "#item" }
778778
},
779-
"definitions": {
779+
"$defs": {
780780
"single": {
781781
"$id": "#item",
782782
"type": "object",
@@ -788,7 +788,7 @@
788788
</artwork>
789789
</figure>
790790
<t>
791-
When an implementation encounters the &lt;#/definitions/single&gt; schema,
791+
When an implementation encounters the &lt;#/$defs/single&gt; schema,
792792
it resolves the "$id" URI reference against the current base URI to form
793793
&lt;http://example.net/root.json#item&gt;.
794794
</t>
@@ -814,6 +814,40 @@
814814
</t>
815815
</section>
816816
</section>
817+
818+
<section title='Schema Re-Use With "$defs"'>
819+
<t>
820+
The "$defs" keyword provides a standardized location for schema
821+
authors to inline re-usable JSON Schemas into a more general schema.
822+
The keyword does not directly affect the validation result.
823+
</t>
824+
<t>
825+
This keyword's value MUST be an object.
826+
Each member value of this object MUST be a valid JSON Schema.
827+
</t>
828+
<t>
829+
As an example, here is a schema describing an array of positive
830+
integers, where the positive integer constraint is a subschema in
831+
"$defs":
832+
833+
<figure>
834+
<artwork>
835+
<![CDATA[
836+
{
837+
"type": "array",
838+
"items": { "$ref": "#/$defs/positiveInteger" },
839+
"$defs": {
840+
"positiveInteger": {
841+
"type": "integer",
842+
"exclusiveMinimum": 0
843+
}
844+
}
845+
}
846+
]]>
847+
</artwork>
848+
</figure>
849+
</t>
850+
</section>
817851
</section>
818852

819853
<section title='Comments With "$comment"'>
@@ -1172,7 +1206,7 @@ User-Agent: product-name/5.4.1 so-cool-json-schema/1.0.2 curl/7.43.0
11721206
<list style="hanging">
11731207
<t hangText="draft-handrews-json-schema-02">
11741208
<list style="symbols">
1175-
<t></t>
1209+
<t>Moved "definitions" from the Validation specification here as "$defs"</t>
11761210
</list>
11771211
</t>
11781212
<t hangText="draft-handrews-json-schema-01">

jsonschema-hyperschema.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
16281628
"type": "object",
16291629
"required": ["data"],
16301630
"properties": {
1631-
"id": {"$ref": "#/definitions/id"},
1631+
"id": {"$ref": "#/$defs/id"},
16321632
"data": true
16331633
},
16341634
"links": [
@@ -1639,7 +1639,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
16391639
"targetSchema": {"$ref": "#"}
16401640
}
16411641
],
1642-
"definitions": {
1642+
"$defs": {
16431643
"id": {
16441644
"type": "integer",
16451645
"minimum": 1,
@@ -1652,7 +1652,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
16521652
<t>
16531653
Our "thing" has a server-assigned id, which is required in order to
16541654
construct the "self" link. It also has a "data" field which can be
1655-
of any type. The reason for the "definitions" section will be clear
1655+
of any type. The reason for the "$defs" section will be clear
16561656
in the next example.
16571657
</t>
16581658
<t>
@@ -1678,7 +1678,7 @@ Link: <https://schema.example.com/entry> rel=describedBy
16781678
"hrefSchema": {
16791679
"required": ["id"],
16801680
"properties": {
1681-
"id": {"$ref": "thing#/definitions/id"}
1681+
"id": {"$ref": "thing#/$defs/id"}
16821682
}
16831683
},
16841684
"targetSchema": {"$ref": "thing#"}
@@ -1993,7 +1993,7 @@ Link: <https://api.example.com/trees/1/nodes/456> rev=up
19931993
"type": "object",
19941994
"required": ["data"],
19951995
"properties": {
1996-
"id": {"$ref": "#/definitions/id"},
1996+
"id": {"$ref": "#/$defs/id"},
19971997
"data": true
19981998
},
19991999
"links": [
@@ -2009,7 +2009,7 @@ Link: <https://api.example.com/trees/1/nodes/456> rev=up
20092009
"submissionSchema": {"$ref": "#"}
20102010
}
20112011
],
2012-
"definitions": {
2012+
"$defs": {
20132013
"id": {
20142014
"type": "integer",
20152015
"minimum": 1,
@@ -2206,9 +2206,9 @@ Link: <https://api.example.com/trees/1/nodes/456> rev=up
22062206
"meta": {
22072207
"type": "object",
22082208
"properties": {
2209-
"prev": {"$ref": "#/definitions/pagination"},
2210-
"current": {"$ref": "#/definitions/pagination"},
2211-
"next": {"$ref": "#/definitions/pagination"}
2209+
"prev": {"$ref": "#/$defs/pagination"},
2210+
"current": {"$ref": "#/$defs/pagination"},
2211+
"next": {"$ref": "#/$defs/pagination"}
22122212
}
22132213
}
22142214
},
@@ -2242,7 +2242,7 @@ Link: <https://api.example.com/trees/1/nodes/456> rev=up
22422242
"targetSchema": {"$ref": "#"}
22432243
}
22442244
],
2245-
"definitions": {
2245+
"$defs": {
22462246
"pagination": {
22472247
"type": "object",
22482248
"properties": {
@@ -2348,7 +2348,7 @@ Link: <https://api.example.com/trees/1/nodes/456> rev=up
23482348
"rel": "tag:rel.example.com,2017:thing-collection",
23492349
"href": "/things{?offset,limit}",
23502350
"hrefSchema": {
2351-
"$ref": "thing-collection#/definitions/pagination"
2351+
"$ref": "thing-collection#/$defs/pagination"
23522352
},
23532353
"submissionSchema": {
23542354
"$ref": "thing#"

jsonschema-validation.xml

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,40 +1233,6 @@
12331233

12341234
</section>
12351235

1236-
<section title='Schema Re-Use With "definitions"'>
1237-
<t>
1238-
The "definitions" keywords provides a standardized location for schema
1239-
authors to inline re-usable JSON Schemas into a more general schema.
1240-
The keyword does not directly affect the validation result.
1241-
</t>
1242-
<t>
1243-
This keyword's value MUST be an object.
1244-
Each member value of this object MUST be a valid JSON Schema.
1245-
</t>
1246-
<t>
1247-
As an example, here is a schema describing an array of positive
1248-
integers, where the positive integer constraint is a subschema in
1249-
"definitions":
1250-
1251-
<figure>
1252-
<artwork>
1253-
<![CDATA[
1254-
{
1255-
"type": "array",
1256-
"items": { "$ref": "#/definitions/positiveInteger" },
1257-
"definitions": {
1258-
"positiveInteger": {
1259-
"type": "integer",
1260-
"exclusiveMinimum": 0
1261-
}
1262-
}
1263-
}
1264-
]]>
1265-
</artwork>
1266-
</figure>
1267-
</t>
1268-
</section>
1269-
12701236
<section title="Schema Annotations">
12711237
<t>
12721238
Schema validation is a useful mechanism for annotating instance data
@@ -1470,6 +1436,23 @@
14701436
&RFC4329;
14711437
</references>
14721438

1439+
<section title="Keywords Moved from Validation to Core">
1440+
<t>
1441+
Several keywords have been moved from this document into the
1442+
<xref target="json-schema">Core Specification</xref> as of this draft, in some
1443+
cases with re-naming or other changes. This affects the following former
1444+
validation keywords:
1445+
<list style="hanging">
1446+
<t hangText='"definitions"'>
1447+
Renamed to "$defs" to match "$ref" and be shorter to type.
1448+
Schema vocabulary authors SHOULD NOT define a "definitions" keyword
1449+
with different behavior in order to avoid invalidating schemas that
1450+
still use the older name.
1451+
</t>
1452+
</list>
1453+
</t>
1454+
</section>
1455+
14731456
<section title="Acknowledgments">
14741457
<t>
14751458
Thanks to
@@ -1503,7 +1486,7 @@
15031486
<list style="hanging">
15041487
<t hangText="draft-handrews-json-schema-validation-02">
15051488
<list style="symbols">
1506-
<t></t>
1489+
<t>Moved "definitions" to the core spec as "$defs"</t>
15071490
</list>
15081491
</t>
15091492
<t hangText="draft-handrews-json-schema-validation-01">

links.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"title": "Link Description Object",
55
"allOf": [
66
{ "required": [ "rel", "href" ] },
7-
{ "$ref": "#/definitions/noRequiredFields" }
7+
{ "$ref": "#/$defs/noRequiredFields" }
88
],
9-
"definitions": {
9+
"$defs": {
1010
"noRequiredFields": {
1111
"type": "object",
1212
"properties": {

0 commit comments

Comments
 (0)