Skip to content

Commit 74f2579

Browse files
committed
add implicit reference string schemas
1 parent 2cb7c74 commit 74f2579

10 files changed

+79
-56
lines changed

jsonschema-core.md

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

193-
A JSON Schema MUST be an object or a boolean.
193+
A JSON Schema MUST be an object, a boolean, or a string.
194194

195195
#### JSON Schema Objects and Keywords
196196

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

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

245267
A schema vocabulary, or simply a vocabulary, is a set of keywords, their syntax,
@@ -1217,7 +1239,7 @@ the positive integer constraint is a subschema in `$defs`:
12171239
```jsonschema
12181240
{
12191241
"type": "array",
1220-
"items": { "$ref": "#/$defs/positiveInteger" },
1242+
"items": "#/$defs/positiveInteger",
12211243
"$defs": {
12221244
"positiveInteger": {
12231245
"type": "integer",
@@ -1340,12 +1362,12 @@ For example, consider this schema:
13401362
{
13411363
"$id": "https://example.net/root.json",
13421364
"type": "array",
1343-
"items": { "$ref": "#item" },
1365+
"items": "#item",
13441366
"$defs": {
13451367
"single": {
13461368
"$anchor": "item",
13471369
"type": "object",
1348-
"additionalProperties": { "$ref": "other.json" }
1370+
"additionalProperties": "other.json"
13491371
}
13501372
}
13511373
}
@@ -1417,9 +1439,7 @@ value for `$ref`:
14171439
```jsonschema
14181440
{
14191441
"$id": "https://example.com/foo",
1420-
"items": {
1421-
"$ref": "bar"
1422-
}
1442+
"items": "bar"
14231443
}
14241444
```
14251445

@@ -2699,10 +2719,10 @@ This meta-schema combines several vocabularies for general use.
26992719
"https://example.com/vocab/example-vocab": true
27002720
},
27012721
"allOf": [
2702-
{"$ref": "https://json-schema.org/draft/next/meta/core"},
2703-
{"$ref": "https://json-schema.org/draft/next/meta/applicator"},
2704-
{"$ref": "https://json-schema.org/draft/next/meta/validation"},
2705-
{"$ref": "https://example.com/meta/example-vocab"},
2722+
"https://json-schema.org/draft/next/meta/core",
2723+
"https://json-schema.org/draft/next/meta/applicator",
2724+
"https://json-schema.org/draft/next/meta/validation",
2725+
"https://example.com/meta/example-vocab",
27062726
],
27072727
"patternProperties": {
27082728
"^unevaluated": false
@@ -2779,18 +2799,14 @@ purposes, and is not intended to propose a functional code generation keyword.
27792799
"classRelation": "is-a",
27802800
"$ref": "classes/base.json"
27812801
},
2782-
{
2783-
"$ref": "fields/common.json"
2784-
}
2802+
"fields/common.json"
27852803
],
27862804
"properties": {
27872805
"foo": {
27882806
"classRelation": "has-a",
27892807
"$ref": "classes/foo.json"
27902808
},
2791-
"date": {
2792-
"$ref": "types/dateStruct.json",
2793-
}
2809+
"date": "types/dateStruct.json",
27942810
}
27952811
}
27962812
```
@@ -2850,6 +2866,7 @@ to the document.
28502866
- Rename "absoluteKeywordLocation" and "keywordLocation" to "schemaLocation" and "evaluationPath"
28512867
- Output units in new format group by "schemaLocation", "instanceLocation", and "evaluationPath"
28522868
- Add "droppedAnnotations" to output formats
2869+
- Add string schemas as implicit references
28532870

28542871
### draft-bhutton-json-schema-01
28552872
- 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
@@ -4,11 +4,12 @@
44
"$dynamicAnchor": "meta",
55

66
"title": "Applicator vocabulary meta-schema",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
9-
"prefixItems": { "$ref": "#/$defs/schemaArray" },
10+
"prefixItems": "#/$defs/schemaArray",
1011
"items": { "$dynamicRef": "#meta" },
11-
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
12+
"maxContains": "#/$defs/nonNegativeInteger",
1213
"minContains": {
1314
"$ref": "#/$defs/nonNegativeInteger",
1415
"default": 1
@@ -44,9 +45,9 @@
4445
"if": { "$dynamicRef": "#meta" },
4546
"then": { "$dynamicRef": "#meta" },
4647
"else": { "$dynamicRef": "#meta" },
47-
"allOf": { "$ref": "#/$defs/schemaArray" },
48-
"anyOf": { "$ref": "#/$defs/schemaArray" },
49-
"oneOf": { "$ref": "#/$defs/schemaArray" },
48+
"allOf": "#/$defs/schemaArray",
49+
"anyOf": "#/$defs/schemaArray",
50+
"oneOf": "#/$defs/schemaArray",
5051
"not": { "$dynamicRef": "#meta" }
5152
},
5253
"$defs": {

meta/content.json

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

66
"title": "Content vocabulary meta-schema",
77

8-
"type": ["object", "boolean"],
8+
"type": ["object", "boolean", "string"],
9+
"format": "iri-reference",
910
"properties": {
1011
"contentEncoding": { "type": "string" },
1112
"contentMediaType": { "type": "string" },

meta/core.json

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

66
"title": "Core vocabulary meta-schema",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
910
"$id": {
1011
"$ref": "#/$defs/iriReferenceString",
1112
"$comment": "Fragments not allowed.",
1213
"pattern": "^[^#]*$"
1314
},
14-
"$schema": { "$ref": "#/$defs/iriString" },
15-
"$ref": { "$ref": "#/$defs/iriReferenceString" },
16-
"$anchor": { "$ref": "#/$defs/anchorString" },
17-
"$dynamicRef": { "$ref": "#/$defs/iriReferenceString" },
18-
"$dynamicAnchor": { "$ref": "#/$defs/anchorString" },
15+
"$schema": "#/$defs/iriString",
16+
"$ref": "#/$defs/iriReferenceString",
17+
"$anchor": "#/$defs/anchorString",
18+
"$dynamicRef": "#/$defs/iriReferenceString",
19+
"$dynamicAnchor": "#/$defs/anchorString",
1920
"$vocabulary": {
2021
"type": "object",
21-
"propertyNames": { "$ref": "#/$defs/iriString" },
22+
"propertyNames": "#/$defs/iriString",
2223
"additionalProperties": {
2324
"type": "boolean"
2425
}

meta/format-annotation.json

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

66
"title": "Format vocabulary meta-schema for annotation results",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
910
"format": { "type": "string" }
1011
}

meta/format-assertion.json

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

66
"title": "Format vocabulary meta-schema for assertion results",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
910
"format": { "type": "string" }
1011
}

meta/meta-data.json

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

66
"title": "Meta-data vocabulary meta-schema",
77

8-
"type": ["object", "boolean"],
8+
"type": ["object", "boolean", "string"],
9+
"format": "iri-reference",
910
"properties": {
1011
"title": {
1112
"type": "string"

meta/unevaluated.json

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

66
"title": "Unevaluated applicator vocabulary meta-schema",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
910
"unevaluatedItems": { "$dynamicRef": "#meta" },
1011
"unevaluatedProperties": { "$dynamicRef": "#meta" }

meta/validation.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"$dynamicAnchor": "meta",
55

66
"title": "Validation vocabulary meta-schema",
7-
"type": ["object", "boolean"],
7+
"type": ["object", "boolean", "string"],
8+
"format": "iri-reference",
89
"properties": {
910
"type": {
1011
"anyOf": [
11-
{ "$ref": "#/$defs/simpleTypes" },
12+
"#/$defs/simpleTypes",
1213
{
1314
"type": "array",
14-
"items": { "$ref": "#/$defs/simpleTypes" },
15+
"items": "#/$defs/simpleTypes",
1516
"minItems": 1,
1617
"uniqueItems": true
1718
}
@@ -38,26 +39,24 @@
3839
"exclusiveMinimum": {
3940
"type": "number"
4041
},
41-
"maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
42-
"minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
42+
"maxLength": "#/$defs/nonNegativeInteger",
43+
"minLength": "#/$defs/nonNegativeIntegerDefault0",
4344
"pattern": {
4445
"type": "string",
4546
"format": "regex"
4647
},
47-
"maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
48-
"minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
48+
"maxItems": "#/$defs/nonNegativeInteger",
49+
"minItems": "#/$defs/nonNegativeIntegerDefault0",
4950
"uniqueItems": {
5051
"type": "boolean",
5152
"default": false
5253
},
53-
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
54-
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
55-
"required": { "$ref": "#/$defs/stringArray" },
54+
"maxProperties": "#/$defs/nonNegativeInteger",
55+
"minProperties": "#/$defs/nonNegativeIntegerDefault0",
56+
"required": "#/$defs/stringArray",
5657
"dependentRequired": {
5758
"type": "object",
58-
"additionalProperties": {
59-
"$ref": "#/$defs/stringArray"
60-
}
59+
"additionalProperties": "#/$defs/stringArray"
6160
}
6261
},
6362
"$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)