Skip to content

Instantly share code, notes, and snippets.

@jdesrosiers
Last active March 12, 2023 16:45
Show Gist options
  • Save jdesrosiers/2c7fc711854b1bb3ab8c7c6f19438d7a to your computer and use it in GitHub Desktop.
Save jdesrosiers/2c7fc711854b1bb3ab8c7c6f19438d7a to your computer and use it in GitHub Desktop.
{
"$id": "https://json-schema.org/draft/2020-12/schema",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Core and Validation specifications meta-schema",
"$dynamicAnchor": "meta",
"allOf": [
{
"$ref": "meta/core"
},
{
"$ref": "meta/applicator"
},
{
"$ref": "meta/unevaluated"
},
{
"$ref": "meta/validation"
},
{
"$ref": "meta/meta-data"
},
{
"$ref": "meta/format-annotation"
},
{
"$ref": "meta/content"
}
],
"type": [
"object",
"boolean"
],
"properties": {
"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": {
"$dynamicRef": "#meta"
},
"default": {}
},
"dependencies": {
"$comment": "\"dependencies\" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to \"dependentSchemas\" and \"dependentRequired\"",
"type": "object",
"additionalProperties": {
"anyOf": [
{
"$dynamicRef": "#meta"
},
{
"$ref": "meta/validation#/$defs/stringArray"
}
]
}
}
},
"$defs": {
"https://json-schema.org/draft/2020-12/meta/core": {
"$id": "https://json-schema.org/draft/2020-12/meta/core",
"title": "Core vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"$id": {
"type": "string",
"format": "uri-reference",
"$comment": "Non-empty fragments not allowed.",
"pattern": "^[^#]*#?$"
},
"$schema": {
"type": "string",
"format": "uri"
},
"$anchor": {
"type": "string",
"pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
},
"$ref": {
"type": "string",
"format": "uri-reference"
},
"$dynamicRef": {
"type": "string",
"format": "uri-reference"
},
"$dynamicAnchor": {
"type": "string",
"pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
},
"$vocabulary": {
"type": "object",
"propertyNames": {
"type": "string",
"format": "uri"
},
"additionalProperties": {
"type": "boolean"
}
},
"$comment": {
"type": "string"
},
"$defs": {
"type": "object",
"additionalProperties": {
"$dynamicRef": "#meta"
},
"default": {}
}
}
},
"https://json-schema.org/draft/2020-12/meta/applicator": {
"$id": "https://json-schema.org/draft/2020-12/meta/applicator",
"title": "Applicator vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"prefixItems": {
"$ref": "#/$defs/schemaArray"
},
"items": {
"$dynamicRef": "#meta"
},
"contains": {
"$dynamicRef": "#meta"
},
"additionalProperties": {
"$dynamicRef": "#meta"
},
"properties": {
"type": "object",
"additionalProperties": {
"$dynamicRef": "#meta"
},
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": {
"$dynamicRef": "#meta"
},
"propertyNames": {
"format": "regex"
},
"default": {}
},
"dependentSchemas": {
"type": "object",
"additionalProperties": {
"$dynamicRef": "#meta"
}
},
"propertyNames": {
"$dynamicRef": "#meta"
},
"if": {
"$dynamicRef": "#meta"
},
"then": {
"$dynamicRef": "#meta"
},
"else": {
"$dynamicRef": "#meta"
},
"allOf": {
"$ref": "#/$defs/schemaArray"
},
"anyOf": {
"$ref": "#/$defs/schemaArray"
},
"oneOf": {
"$ref": "#/$defs/schemaArray"
},
"not": {
"$dynamicRef": "#meta"
}
},
"$defs": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {
"$dynamicRef": "#meta"
}
}
}
},
"https://json-schema.org/draft/2020-12/meta/unevaluated": {
"$id": "https://json-schema.org/draft/2020-12/meta/unevaluated",
"title": "Unevaluated applicator vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"unevaluatedItems": {
"$dynamicRef": "#meta"
},
"unevaluatedProperties": {
"$dynamicRef": "#meta"
}
}
},
"https://json-schema.org/draft/2020-12/meta/validation": {
"$id": "https://json-schema.org/draft/2020-12/meta/validation",
"title": "Validation vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"multipleOf": {
"type": "number",
"exclusiveMinimum": 0
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "number"
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "number"
},
"maxLength": {
"$ref": "#/$defs/nonNegativeInteger"
},
"minLength": {
"$ref": "#/$defs/nonNegativeIntegerDefault0"
},
"pattern": {
"type": "string",
"format": "regex"
},
"maxItems": {
"$ref": "#/$defs/nonNegativeInteger"
},
"minItems": {
"$ref": "#/$defs/nonNegativeIntegerDefault0"
},
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxContains": {
"$ref": "#/$defs/nonNegativeInteger"
},
"minContains": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 1
},
"maxProperties": {
"$ref": "#/$defs/nonNegativeInteger"
},
"minProperties": {
"$ref": "#/$defs/nonNegativeIntegerDefault0"
},
"required": {
"$ref": "#/$defs/stringArray"
},
"dependentRequired": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/stringArray"
}
},
"const": true,
"enum": {
"type": "array",
"items": true
},
"type": {
"anyOf": [
{
"$ref": "#/$defs/simpleTypes"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/simpleTypes"
},
"minItems": 1,
"uniqueItems": true
}
]
}
},
"$defs": {
"nonNegativeInteger": {
"type": "integer",
"minimum": 0
},
"nonNegativeIntegerDefault0": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 0
},
"simpleTypes": {
"enum": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
},
"stringArray": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
}
},
"https://json-schema.org/draft/2020-12/meta/meta-data": {
"$id": "https://json-schema.org/draft/2020-12/meta/meta-data",
"title": "Meta-data vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": true,
"deprecated": {
"type": "boolean",
"default": false
},
"readOnly": {
"type": "boolean",
"default": false
},
"writeOnly": {
"type": "boolean",
"default": false
},
"examples": {
"type": "array",
"items": true
}
}
},
"https://json-schema.org/draft/2020-12/meta/format-annotation": {
"$id": "https://json-schema.org/draft/2020-12/meta/format-annotation",
"title": "Format vocabulary meta-schema for annotation results",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"format": {
"type": "string"
}
}
},
"https://json-schema.org/draft/2020-12/meta/content": {
"$id": "https://json-schema.org/draft/2020-12/meta/content",
"title": "Content vocabulary meta-schema",
"$dynamicAnchor": "meta",
"type": [
"object",
"boolean"
],
"properties": {
"contentMediaType": {
"type": "string"
},
"contentEncoding": {
"type": "string"
},
"contentSchema": {
"$dynamicRef": "#meta"
}
}
}
}
}
@jdesrosiers
Copy link
Author

Generated with the following script.

const Bundler = require("@hyperjump/json-schema-bundle");


(async function () {
  const metaSchema = await Bundler.get(`https://json-schema.org/draft/2020-12/schema`);
  const bundle = await Bundler.bundle(metaSchema);
  console.log(JSON.stringify(bundle, null, "  "));
}());

@rpgoldman
Copy link

When I tried to use that schema with jsonschema, I got the following error:

jsonschema.exceptions.RefResolutionError: Unresolvable JSON pointer: 'meta'

I think adding

  "$dynamicAnchor": "meta",

to the top level of your schema file solves the problem.

@jdesrosiers
Copy link
Author

Yep. Looks like a bug in the bundler. $dynamicAnchor": "meta" should appear in every schema with a keyword like, "$id": "https://json-schema.org/draft/2020-12...

@rpgoldman
Copy link

Well, with that insertion, this works fine for me with jsonschema. Thank you so much for providing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment