Skip to content

Commit 7bf22d2

Browse files
committed
add implicit reference string schemas
1 parent d083fac commit 7bf22d2

10 files changed

+80
-59
lines changed

jsonschema-core.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ always be given the media type `application/schema+json` rather than
189189
defined to offer a superset of the fragment identifier syntax and semantics
190190
provided by `application/schema-instance+json`.
191191

192-
A JSON Schema MUST be an object or a boolean.
192+
A JSON Schema MUST be an object, a boolean, or a string.
193193

194194
#### JSON Schema Objects and Keywords
195195

@@ -239,6 +239,28 @@ While the empty schema object is unambiguous, there are many possible
239239
equivalents to the `false` schema. Using the boolean values ensures that the
240240
intent is clear to both human readers and implementations.
241241

242+
#### String JSON Schemas
243+
244+
A string schema operates as an implicit reference to another schema object.
245+
A string schema is a shorthand for a schema containing only the `$ref` keyword.
246+
247+
For example, the string schema
248+
249+
```json
250+
"https://example.com/schema"
251+
```
252+
253+
is equivalent to
254+
255+
```json
256+
{
257+
"$ref": "https://example.com/schema"
258+
}
259+
```
260+
261+
For a string to operate as a schema, the value MUST conform to the requirements
262+
defined in {{ref}}.
263+
242264
#### Schema Vocabularies
243265

244266
A schema vocabulary, or simply a vocabulary, is a set of keywords, their syntax,
@@ -1188,7 +1210,7 @@ the positive integer constraint is a subschema in `$defs`:
11881210
```jsonschema
11891211
{
11901212
"type": "array",
1191-
"items": { "$ref": "#/$defs/positiveInteger" },
1213+
"items": "#/$defs/positiveInteger",
11921214
"$defs": {
11931215
"positiveInteger": {
11941216
"type": "integer",
@@ -1309,12 +1331,12 @@ For example, consider this schema:
13091331
{
13101332
"$id": "https://example.net/root.json",
13111333
"type": "array",
1312-
"items": { "$ref": "#item" },
1334+
"items": "#item",
13131335
"$defs": {
13141336
"single": {
13151337
"$anchor": "item",
13161338
"type": "object",
1317-
"additionalProperties": { "$ref": "other.json" }
1339+
"additionalProperties": "other.json"
13181340
}
13191341
}
13201342
}
@@ -1386,9 +1408,7 @@ value for `$ref`:
13861408
```jsonschema
13871409
{
13881410
"$id": "https://example.com/foo",
1389-
"items": {
1390-
"$ref": "bar"
1391-
}
1411+
"items": "bar"
13921412
}
13931413
```
13941414

@@ -2263,9 +2283,7 @@ For these examples, the following schema and instances will be used.
22632283
}
22642284
]
22652285
},
2266-
"bar": {
2267-
"$ref": "#/$defs/bar"
2268-
}
2286+
"bar": "#/$defs/bar"
22692287
},
22702288
"$defs": {
22712289
"bar": {
@@ -3164,10 +3182,10 @@ This meta-schema combines several vocabularies for general use.
31643182
"https://example.com/vocab/example-vocab": true
31653183
},
31663184
"allOf": [
3167-
{"$ref": "https://json-schema.org/draft/next/meta/core"},
3168-
{"$ref": "https://json-schema.org/draft/next/meta/applicator"},
3169-
{"$ref": "https://json-schema.org/draft/next/meta/validation"},
3170-
{"$ref": "https://example.com/meta/example-vocab"},
3185+
"https://json-schema.org/draft/next/meta/core",
3186+
"https://json-schema.org/draft/next/meta/applicator",
3187+
"https://json-schema.org/draft/next/meta/validation",
3188+
"https://example.com/meta/example-vocab",
31713189
],
31723190
"patternProperties": {
31733191
"^unevaluated": false
@@ -3244,18 +3262,14 @@ purposes, and is not intended to propose a functional code generation keyword.
32443262
"classRelation": "is-a",
32453263
"$ref": "classes/base.json"
32463264
},
3247-
{
3248-
"$ref": "fields/common.json"
3249-
}
3265+
"fields/common.json"
32503266
],
32513267
"properties": {
32523268
"foo": {
32533269
"classRelation": "has-a",
32543270
"$ref": "classes/foo.json"
32553271
},
3256-
"date": {
3257-
"$ref": "types/dateStruct.json",
3258-
}
3272+
"date": "types/dateStruct.json",
32593273
}
32603274
}
32613275
```
@@ -3291,6 +3305,7 @@ to the document.
32913305
- Use IRIs instead of URIs
32923306
- Remove bookending requirement for `$dynamicRef`
32933307
- Add `propertyDependencies` keyword
3308+
- Add string schemas as implicit references
32943309

32953310
### draft-bhutton-json-schema-01
32963311
- Improve and clarify the `type`, `contains`, `unevaluatedProperties`, and

meta/applicator.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Applicator vocabulary meta-schema",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
12-
"prefixItems": { "$ref": "#/$defs/schemaArray" },
13+
"prefixItems": "#/$defs/schemaArray",
1314
"items": { "$dynamicRef": "#meta" },
14-
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
15+
"maxContains": "#/$defs/nonNegativeInteger",
1516
"minContains": {
1617
"$ref": "#/$defs/nonNegativeInteger",
1718
"default": 1
@@ -47,9 +48,9 @@
4748
"if": { "$dynamicRef": "#meta" },
4849
"then": { "$dynamicRef": "#meta" },
4950
"else": { "$dynamicRef": "#meta" },
50-
"allOf": { "$ref": "#/$defs/schemaArray" },
51-
"anyOf": { "$ref": "#/$defs/schemaArray" },
52-
"oneOf": { "$ref": "#/$defs/schemaArray" },
51+
"allOf": "#/$defs/schemaArray",
52+
"anyOf": "#/$defs/schemaArray",
53+
"oneOf": "#/$defs/schemaArray",
5354
"not": { "$dynamicRef": "#meta" }
5455
},
5556
"$defs": {

meta/content.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
"title": "Content vocabulary meta-schema",
1010

11-
"type": ["object", "boolean"],
11+
"type": ["object", "boolean", "string"],
12+
"format": "iri-reference",
1213
"properties": {
1314
"contentEncoding": { "type": "string" },
1415
"contentMediaType": { "type": "string" },

meta/core.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Core vocabulary meta-schema",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
1213
"$id": {
1314
"$ref": "#/$defs/iriReferenceString",
1415
"$comment": "Fragments not allowed.",
1516
"pattern": "^[^#]*$"
1617
},
17-
"$schema": { "$ref": "#/$defs/iriString" },
18-
"$ref": { "$ref": "#/$defs/iriReferenceString" },
19-
"$anchor": { "$ref": "#/$defs/anchorString" },
20-
"$dynamicRef": { "$ref": "#/$defs/iriReferenceString" },
21-
"$dynamicAnchor": { "$ref": "#/$defs/anchorString" },
18+
"$schema": "#/$defs/iriString",
19+
"$ref": "#/$defs/iriReferenceString",
20+
"$anchor": "#/$defs/anchorString",
21+
"$dynamicRef": "#/$defs/iriReferenceString",
22+
"$dynamicAnchor": "#/$defs/anchorString",
2223
"$vocabulary": {
2324
"type": "object",
24-
"propertyNames": { "$ref": "#/$defs/iriString" },
25+
"propertyNames": "#/$defs/iriString",
2526
"additionalProperties": {
2627
"type": "boolean"
2728
}

meta/format-annotation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Format vocabulary meta-schema for annotation results",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
1213
"format": { "type": "string" }
1314
}

meta/format-assertion.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Format vocabulary meta-schema for assertion results",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
1213
"format": { "type": "string" }
1314
}

meta/meta-data.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
"title": "Meta-data vocabulary meta-schema",
1010

11-
"type": ["object", "boolean"],
11+
"type": ["object", "boolean", "string"],
12+
"format": "iri-reference",
1213
"properties": {
1314
"title": {
1415
"type": "string"

meta/unevaluated.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Unevaluated applicator vocabulary meta-schema",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
1213
"unevaluatedItems": { "$dynamicRef": "#meta" },
1314
"unevaluatedProperties": { "$dynamicRef": "#meta" }

meta/validation.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"$dynamicAnchor": "meta",
88

99
"title": "Validation vocabulary meta-schema",
10-
"type": ["object", "boolean"],
10+
"type": ["object", "boolean", "string"],
11+
"format": "iri-reference",
1112
"properties": {
1213
"type": {
1314
"anyOf": [
14-
{ "$ref": "#/$defs/simpleTypes" },
15+
"#/$defs/simpleTypes",
1516
{
1617
"type": "array",
17-
"items": { "$ref": "#/$defs/simpleTypes" },
18+
"items": "#/$defs/simpleTypes",
1819
"minItems": 1,
1920
"uniqueItems": true
2021
}
@@ -41,26 +42,24 @@
4142
"exclusiveMinimum": {
4243
"type": "number"
4344
},
44-
"maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
45-
"minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
45+
"maxLength": "#/$defs/nonNegativeInteger",
46+
"minLength": "#/$defs/nonNegativeIntegerDefault0",
4647
"pattern": {
4748
"type": "string",
4849
"format": "regex"
4950
},
50-
"maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
51-
"minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
51+
"maxItems": "#/$defs/nonNegativeInteger",
52+
"minItems": "#/$defs/nonNegativeIntegerDefault0",
5253
"uniqueItems": {
5354
"type": "boolean",
5455
"default": false
5556
},
56-
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
57-
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
58-
"required": { "$ref": "#/$defs/stringArray" },
57+
"maxProperties": "#/$defs/nonNegativeInteger",
58+
"minProperties": "#/$defs/nonNegativeIntegerDefault0",
59+
"required": "#/$defs/stringArray",
5960
"dependentRequired": {
6061
"type": "object",
61-
"additionalProperties": {
62-
"$ref": "#/$defs/stringArray"
63-
}
62+
"additionalProperties": "#/$defs/stringArray"
6463
}
6564
},
6665
"$defs": {

schema.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
"title": "Core and Validation specifications meta-schema",
1616
"allOf": [
17-
{"$ref": "meta/core"},
18-
{"$ref": "meta/applicator"},
19-
{"$ref": "meta/unevaluated"},
20-
{"$ref": "meta/validation"},
21-
{"$ref": "meta/meta-data"},
22-
{"$ref": "meta/format-annotation"},
23-
{"$ref": "meta/content"}
17+
"meta/core",
18+
"meta/applicator",
19+
"meta/unevaluated",
20+
"meta/validation",
21+
"meta/meta-data",
22+
"meta/format-annotation",
23+
"meta/content"
2424
],
2525
"type": ["object", "boolean"],
2626
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
@@ -38,7 +38,7 @@
3838
"additionalProperties": {
3939
"anyOf": [
4040
{ "$dynamicRef": "#meta" },
41-
{ "$ref": "meta/validation#/$defs/stringArray" }
41+
"meta/validation#/$defs/stringArray"
4242
]
4343
},
4444
"deprecated": true,

0 commit comments

Comments
 (0)