Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add implicit reference string schemas #1432

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions jsonschema-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ always be given the media type `application/schema+json` rather than
defined to offer a superset of the fragment identifier syntax and semantics
provided by `application/schema-instance+json`.

A JSON Schema MUST be an object or a boolean.
A JSON Schema MUST be an object, a boolean, or a string.

#### JSON Schema Objects and Keywords

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

#### String JSON Schemas

A string schema operates as an implicit reference to another schema resource. A
string schema is a shorthand for a schema object containing only the `$ref`
keyword.

For example, the schema

```json
{
"type": "object",
"properties": {
"foo": "https://example.com/schema"
}
}
```

is equivalent to

```json
{
"type": "object",
"properties": {
"foo": {
"$ref": "https://example.com/schema"
}
}
}
```

For a string to operate as a schema, the value MUST conform to the requirements
defined in {{ref}}.

#### Schema Vocabularies

A schema vocabulary, or simply a vocabulary, is a set of keywords, their syntax,
Expand Down Expand Up @@ -1217,7 +1250,7 @@ the positive integer constraint is a subschema in `$defs`:
```jsonschema
{
"type": "array",
"items": { "$ref": "#/$defs/positiveInteger" },
"items": "#/$defs/positiveInteger",
"$defs": {
"positiveInteger": {
"type": "integer",
Expand Down Expand Up @@ -1340,12 +1373,12 @@ For example, consider this schema:
{
"$id": "https://example.net/root.json",
"type": "array",
"items": { "$ref": "#item" },
"items": "#item",
"$defs": {
"single": {
"$anchor": "item",
"type": "object",
"additionalProperties": { "$ref": "other.json" }
"additionalProperties": "other.json"
}
}
}
Expand Down Expand Up @@ -1417,9 +1450,7 @@ value for `$ref`:
```jsonschema
{
"$id": "https://example.com/foo",
"items": {
"$ref": "bar"
}
"items": "bar"
}
```

Expand Down Expand Up @@ -2699,10 +2730,10 @@ This meta-schema combines several vocabularies for general use.
"https://example.com/vocab/example-vocab": true
},
"allOf": [
{"$ref": "https://json-schema.org/draft/next/meta/core"},
{"$ref": "https://json-schema.org/draft/next/meta/applicator"},
{"$ref": "https://json-schema.org/draft/next/meta/validation"},
{"$ref": "https://example.com/meta/example-vocab"},
"https://json-schema.org/draft/next/meta/core",
"https://json-schema.org/draft/next/meta/applicator",
"https://json-schema.org/draft/next/meta/validation",
"https://example.com/meta/example-vocab",
],
"patternProperties": {
"^unevaluated": false
Expand Down Expand Up @@ -2779,18 +2810,14 @@ purposes, and is not intended to propose a functional code generation keyword.
"classRelation": "is-a",
"$ref": "classes/base.json"
},
{
"$ref": "fields/common.json"
}
"fields/common.json"
],
"properties": {
"foo": {
"classRelation": "has-a",
"$ref": "classes/foo.json"
},
"date": {
"$ref": "types/dateStruct.json",
}
"date": "types/dateStruct.json",
}
}
```
Expand Down Expand Up @@ -2850,6 +2877,7 @@ to the document.
- Rename "absoluteKeywordLocation" and "keywordLocation" to "schemaLocation" and "evaluationPath"
- Output units in new format group by "schemaLocation", "instanceLocation", and "evaluationPath"
- Add "droppedAnnotations" to output formats
- Add string schemas as implicit references

### draft-bhutton-json-schema-01
- Improve and clarify the `type`, `contains`, `unevaluatedProperties`, and
Expand Down
13 changes: 7 additions & 6 deletions meta/applicator.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"$dynamicAnchor": "meta",

"title": "Applicator vocabulary meta-schema",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"prefixItems": { "$ref": "#/$defs/schemaArray" },
"prefixItems": "#/$defs/schemaArray",
"items": { "$dynamicRef": "#meta" },
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
"maxContains": "#/$defs/nonNegativeInteger",
"minContains": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 1
Expand Down Expand Up @@ -44,9 +45,9 @@
"if": { "$dynamicRef": "#meta" },
"then": { "$dynamicRef": "#meta" },
"else": { "$dynamicRef": "#meta" },
"allOf": { "$ref": "#/$defs/schemaArray" },
"anyOf": { "$ref": "#/$defs/schemaArray" },
"oneOf": { "$ref": "#/$defs/schemaArray" },
"allOf": "#/$defs/schemaArray",
"anyOf": "#/$defs/schemaArray",
"oneOf": "#/$defs/schemaArray",
"not": { "$dynamicRef": "#meta" }
},
"$defs": {
Expand Down
3 changes: 2 additions & 1 deletion meta/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

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

"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"contentEncoding": { "type": "string" },
"contentMediaType": { "type": "string" },
Expand Down
15 changes: 8 additions & 7 deletions meta/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
"$dynamicAnchor": "meta",

"title": "Core vocabulary meta-schema",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"$id": {
"$ref": "#/$defs/iriReferenceString",
"$comment": "Fragments not allowed.",
"pattern": "^[^#]*$"
},
"$schema": { "$ref": "#/$defs/iriString" },
"$ref": { "$ref": "#/$defs/iriReferenceString" },
"$anchor": { "$ref": "#/$defs/anchorString" },
"$dynamicRef": { "$ref": "#/$defs/iriReferenceString" },
"$dynamicAnchor": { "$ref": "#/$defs/anchorString" },
"$schema": "#/$defs/iriString",
"$ref": "#/$defs/iriReferenceString",
"$anchor": "#/$defs/anchorString",
"$dynamicRef": "#/$defs/iriReferenceString",
"$dynamicAnchor": "#/$defs/anchorString",
"$vocabulary": {
"type": "object",
"propertyNames": { "$ref": "#/$defs/iriString" },
"propertyNames": "#/$defs/iriString",
"additionalProperties": {
"type": "boolean"
}
Expand Down
3 changes: 2 additions & 1 deletion meta/format-annotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"$dynamicAnchor": "meta",

"title": "Format vocabulary meta-schema for annotation results",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"format": { "type": "string" }
}
Expand Down
3 changes: 2 additions & 1 deletion meta/format-assertion.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"$dynamicAnchor": "meta",

"title": "Format vocabulary meta-schema for assertion results",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"format": { "type": "string" }
}
Expand Down
3 changes: 2 additions & 1 deletion meta/meta-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

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

"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"title": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion meta/unevaluated.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"$dynamicAnchor": "meta",

"title": "Unevaluated applicator vocabulary meta-schema",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"unevaluatedItems": { "$dynamicRef": "#meta" },
"unevaluatedProperties": { "$dynamicRef": "#meta" }
Expand Down
25 changes: 12 additions & 13 deletions meta/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"$dynamicAnchor": "meta",

"title": "Validation vocabulary meta-schema",
"type": ["object", "boolean"],
"type": ["object", "boolean", "string"],
"format": "iri-reference",
"properties": {
"type": {
"anyOf": [
{ "$ref": "#/$defs/simpleTypes" },
"#/$defs/simpleTypes",
{
"type": "array",
"items": { "$ref": "#/$defs/simpleTypes" },
"items": "#/$defs/simpleTypes",
"minItems": 1,
"uniqueItems": true
}
Expand All @@ -38,26 +39,24 @@
"exclusiveMinimum": {
"type": "number"
},
"maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
"minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"maxLength": "#/$defs/nonNegativeInteger",
"minLength": "#/$defs/nonNegativeIntegerDefault0",
"pattern": {
"type": "string",
"format": "regex"
},
"maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
"minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"maxItems": "#/$defs/nonNegativeInteger",
"minItems": "#/$defs/nonNegativeIntegerDefault0",
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"required": { "$ref": "#/$defs/stringArray" },
"maxProperties": "#/$defs/nonNegativeInteger",
"minProperties": "#/$defs/nonNegativeIntegerDefault0",
"required": "#/$defs/stringArray",
"dependentRequired": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/stringArray"
}
"additionalProperties": "#/$defs/stringArray"
}
},
"$defs": {
Expand Down
16 changes: 8 additions & 8 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

"title": "Core and Validation specifications meta-schema",
"allOf": [
{"$ref": "meta/core"},
{"$ref": "meta/applicator"},
{"$ref": "meta/unevaluated"},
{"$ref": "meta/validation"},
{"$ref": "meta/meta-data"},
{"$ref": "meta/format-annotation"},
{"$ref": "meta/content"}
"meta/core",
"meta/applicator",
"meta/unevaluated",
"meta/validation",
"meta/meta-data",
"meta/format-annotation",
"meta/content"
],
"type": ["object", "boolean"],
"$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.",
Expand All @@ -38,7 +38,7 @@
"additionalProperties": {
"anyOf": [
{ "$dynamicRef": "#meta" },
{ "$ref": "meta/validation#/$defs/stringArray" }
"meta/validation#/$defs/stringArray"
]
},
"deprecated": true,
Expand Down
Loading