diff --git a/.gitmodules b/.gitmodules index 7760d76c..f975f8f1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -23,3 +23,6 @@ path = _includes/draft-07 url = https://github.com/json-schema-org/json-schema-spec.git branch = draft-07 +[submodule "_includes/draft/2019-09"] + path = _includes/draft/2019-09 + url = https://github.com/json-schema-org/json-schema-spec.git diff --git a/.travis.yml b/.travis.yml index 205d3479..bb139d44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ before_script: - PATH="./node_modules/.bin/:$PATH" script: - bundle exec jekyll build -- ajv test -s schema -d "learn/examples/*.json" --valid +- ajv test -s draft-07/schema -d "learn/examples/*.json" --valid diff --git a/Gemfile.lock b/Gemfile.lock index e808f71d..5802c946 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -199,7 +199,7 @@ GEM rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) mercenary (0.3.6) - mini_portile2 (2.3.0) + mini_portile2 (2.4.0) minima (2.4.1) jekyll (~> 3.5) jekyll-feed (~> 0.9) @@ -207,8 +207,8 @@ GEM minitest (5.11.3) multipart-post (2.0.0) net-dns (0.8.0) - nokogiri (1.8.2) - mini_portile2 (~> 2.3.0) + nokogiri (1.10.5) + mini_portile2 (~> 2.4.0) octokit (4.8.0) sawyer (~> 0.8.0, >= 0.5.3) pathutil (0.16.1) @@ -221,7 +221,7 @@ GEM ruby-enum (0.7.2) i18n ruby_dep (1.5.0) - rubyzip (1.2.1) + rubyzip (2.0.0) safe_yaml (1.0.4) sass (3.5.6) sass-listen (~> 4.0.0) diff --git a/_data/validator-libraries-modern.yml b/_data/validator-libraries-modern.yml index 3cc7f269..22beb2da 100644 --- a/_data/validator-libraries-modern.yml +++ b/_data/validator-libraries-modern.yml @@ -3,16 +3,19 @@ implementations: - name: Json.NET Schema url: https://www.newtonsoft.com/jsonschema + date-draft: draft: [7, 6, 4, 3] license: "AGPL-3.0-only" - name: Manatee.Json url: https://github.com/gregsdennis/Manatee.Json + date-draft: [2019-09] draft: [7, 6, 4] license: MIT - name: C implementations: - name: WJElement url: https://github.com/netmail-open/wjelement + date-draft: draft: [4, 3] license: LGPL-3.0 notes: "Draft-06+ progress: issue [17](https://github.com/netmail-open/wjelement/issues/17#issuecomment-390899432)" @@ -20,46 +23,55 @@ implementations: - name: f5-json-schema url: https://github.com/KayEss/json-schema + date-draft: draft: [7] license: Boost Software License 1.0 - name: JSON schema validator for JSON for Modern C++ url: https://github.com/pboettch/json-schema-validator + date-draft: draft: [7] license: MIT - name: Clojure implementations: - name: jinx url: https://github.com/juxt/jinx + date-draft: draft: [7] license: MIT - name: json-schema url: https://github.com/luposlip/json-schema + date-draft: draft: [7] license: Apache License, Version 2.0 - name: Elixir implementations: - name: Elixir JSON Schema validator url: https://github.com/jonasschmidt/ex_json_schema + date-draft: draft: [4] notes: "Draft-06+ progress: issue [24](https://github.com/jonasschmidt/ex_json_schema/issues/24); branch [multi-draft-support](https://github.com/jonasschmidt/ex_json_schema/tree/multi-draft-support)" license: MIT - name: JsonXema url: https://github.com/hrzndhrn/json_xema + date-draft: draft: [7, 6, 4] license: MIT - name: Go implementations: - name: gojsonschema url: https://github.com/xeipuuv/gojsonschema + date-draft: draft: [7, 6, 4] license: "Apache 2.0" - name: santhosh-tekuri/jsonschema url: https://github.com/santhosh-tekuri/jsonschema notes: + date-draft: draft: [7, 6, 4] license: BSD-3-Clause - name: qri-io/jsonschema url: https://github.com/qri-io/jsonschema + date-draft: draft: [7] license: MIT notes: includes custom validator support, rich error returns @@ -68,11 +80,19 @@ - name: everit-org/json-schema url: https://github.com/everit-org/json-schema notes: + date-draft: draft: [7, 6, 4] license: Apache License 2.0 - name: Justify url: https://github.com/leadpony/justify notes: + date-draft: + draft: [7, 6, 4] + license: Apache License 2.0 + - name: networknt/json-schema-validator + url: https://github.com/networknt/json-schema-validator + notes: Support OpenAPI 3.0 with Jackson parser + date-draft: draft: [7, 6, 4] license: Apache License 2.0 - name: Kotlin @@ -80,6 +100,7 @@ - name: Medeia-validator url: https://github.com/worldturner/medeia-validator notes: streaming validator for Kotlin and Java clients; works with Jackson and Gson + date-draft: draft: [7, 6, 4] license: Apache License 2.0 - name: JavaScript @@ -87,15 +108,18 @@ - name: ajv url: https://github.com/epoberezkin/ajv notes: "for Node.js and browsers - supports [custom keywords](https://github.com/epoberezkin/ajv-keywords) and [$data reference](https://github.com/json-schema-org/json-schema-spec/issues/51)" + date-draft: draft: [7, 6, 4] license: MIT - name: djv url: https://github.com/korzio/djv notes: "for Node.js and browsers" + date-draft: draft: [6, 4] license: MIT - name: vue-vuelidate-jsonschema url: https://github.com/mokkabonna/vue-vuelidate-jsonschema + date-draft: draft: [6] license: MIT - name: PHP @@ -103,11 +127,13 @@ - name: Opis Json Schema url: https://github.com/opis/json-schema notes: + date-draft: draft: [7, 6] license: "Apache License 2.0" - name: Swaggest Json Schema url: https://github.com/swaggest/php-json-schema notes: + date-draft: draft: [7, 6, 4] license: "MIT" - name: Python @@ -115,13 +141,21 @@ - name: jsonschema url: https://github.com/Julian/jsonschema notes: + date-draft: draft: [7, 6, 4, 3] license: "MIT" + - name: fastjsonschema + url: https://github.com/horejsek/python-fastjsonschema + notes: Great performance thanks to code generation. + date-draft: + draft: [7, 6, 4] + license: BSD-3-Clause - name: Ruby implementations: - name: JSONSchemer url: https://github.com/davishmcclurg/json_schemer notes: + date-draft: draft: [7, 6, 4] license: MIT - name: Objective-C @@ -129,27 +163,41 @@ - name: DSJSONSchemaValidation url: https://github.com/dashevo/JSONSchemaValidation notes: + date-draft: + draft: [7, 6, 4] + license: MIT +- name: Lua/LuaJIT + implementations: + - name: lua-resty-jsonschema + url: https://github.com/iresty/lua-resty-jsonschema + notes: + date-draft: draft: [7, 6, 4] license: MIT - name: Web (Online) implementations: - name: JSON Schema Validator url: https://www.jsonschemavalidator.net/ + date-draft: draft: [7, 6, 4, 3] - name: JSON Schema Lint url: http://jsonschemalint.com/ + date-draft: draft: [7, 6, 4, 3, 2, 1] - name: ExtendsClass's JSON Schema Validator url: https://extendsclass.com/json-schema-validator.html + date-draft: draft: [7] - name: Command Line implementations: - name: ajv-cli license: MIT url: 'https://www.npmjs.com/package/ajv-cli' + date-draft: draft: [7, 6, 4] - name: Polyglottal JSON Schema Validator license: MIT url: 'https://www.npmjs.com/package/pajv' + date-draft: draft: [6, 4] notes: can be used with YAML and many other formats besides JSON diff --git a/_data/validator-libraries-obsolete.yml b/_data/validator-libraries-obsolete.yml index 0d19362e..f0bece60 100644 --- a/_data/validator-libraries-obsolete.yml +++ b/_data/validator-libraries-obsolete.yml @@ -73,11 +73,6 @@ url: https://github.com/java-json-tools/json-schema-validator draft: [4] license: LGPLv3 - - name: json-schema-validator - url: https://github.com/networknt/json-schema-validator - notes: - draft: [4] - license: Apache License 2.0 - name: JavaScript implementations: - name: jsonschema diff --git a/_includes/draft/2019-09 b/_includes/draft/2019-09 new file mode 160000 index 00000000..b47f567e --- /dev/null +++ b/_includes/draft/2019-09 @@ -0,0 +1 @@ +Subproject commit b47f567e1ef87ae16b69aeb8c3084729a22c9bce diff --git a/_layouts/redirect.html b/_layouts/redirect.html new file mode 100644 index 00000000..03f78506 --- /dev/null +++ b/_layouts/redirect.html @@ -0,0 +1,20 @@ + + + + Redirecting… + + + +

Redirecting…

+

+ Several redirections on json-schema.org are special cases: +

+ + Click here if you are not redirected. + + diff --git a/draft-06/json-schema-release-notes.md b/draft-06/json-schema-release-notes.md index fa7ecdf6..68984b5c 100644 --- a/draft-06/json-schema-release-notes.md +++ b/draft-06/json-schema-release-notes.md @@ -25,6 +25,7 @@ keyword | change | consequence `"$id"` | replaces `"id"` | behavior is identical, `$` prefix matches the other two core keywords `"$ref"` | only allowed where a schema is expected | it is now possible to describe instance properties named `"$ref"` `"exclusiveMinimum"` and `"exclusiveMaximum"` | changed from a boolean to a number to be consistent with the principle of keyword independence | wherever one of these would be true before, change the value to the corresponding `"minimum"` or `"maximum"` value and remove the `"minimum"`/`"maximum"` keyword +`"type"` | definition of `"integer"` | in draft-04, `"integer"` is listed as a primitive type and defined as "a JSON number without a fraction or exponent part"; in draft-06, `"integer"` is not considered a primitive type and is only defined in the section for keyword `"type"` as "any number with a zero fractional part"; `1.0` is thus not a valid `"integer"` type in draft-04 and earlier, but is a valid `"integer"` type in draft-06 and later; note that both drafts say that integers SHOULD be encoded in JSON without fractional parts #### Additions and backwards-compatible changes diff --git a/draft/2019-09/hyper-schema b/draft/2019-09/hyper-schema new file mode 120000 index 00000000..8a058c65 --- /dev/null +++ b/draft/2019-09/hyper-schema @@ -0,0 +1 @@ +../../_includes/draft/2019-09/hyper-schema.json \ No newline at end of file diff --git a/work-in-progress/WIP-jsonschema-core.html b/draft/2019-09/json-schema-core.html similarity index 71% rename from work-in-progress/WIP-jsonschema-core.html rename to draft/2019-09/json-schema-core.html index d5e562f0..80fb2685 100644 --- a/work-in-progress/WIP-jsonschema-core.html +++ b/draft/2019-09/json-schema-core.html @@ -388,7 +388,7 @@ - + @@ -400,25 +400,26 @@ - - - - - - + + + + + + + + - - - + - - + + + @@ -454,8 +455,17 @@ - - + + + + + + + + + + + @@ -463,8 +473,8 @@ - - + + @@ -488,7 +498,7 @@ H. Andrews, Ed. -Expires: February 17, 2020 +Expires: March 20, 2020 @@ -505,7 +515,7 @@ -August 16, 2019 +September 17, 2019 @@ -513,7 +523,7 @@

JSON Schema: A Media Type for Describing JSON Documents
- draft-handrews-json-schema-WIP

+ draft-handrews-json-schema-02

Abstract

JSON Schema defines the media type "application/schema+json", a JSON-based format for describing the structure of JSON data. JSON Schema asserts what a JSON document must look like, ways to extract information from it, and how to interact with it. The "application/schema-instance+json" media type provides additional feature-rich integration with "application/schema+json" beyond what can be offered for "application/json" documents.

@@ -525,7 +535,7 @@

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

-

This Internet-Draft will expire on February 17, 2020.

+

This Internet-Draft will expire on March 20, 2020.

Copyright Notice

Copyright (c) 2019 IETF Trust and the persons identified as the document authors. All rights reserved.

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

@@ -563,7 +573,7 @@

Table of Contents

  • 4.3.4. Meta-Schemas
  • -
  • 4.3.5. Root Schema and Subschemas +
  • 4.3.5. Root Schema and Subschemas and Resources
  • 5. Fragment Identifiers
  • @@ -587,19 +597,23 @@

    Table of Contents

  • 7.3. Default Behaviors
  • -
  • 7.4. Applicators +
  • 7.4. Identifiers
  • -
  • 7.5. Assertions +
  • 7.6. Annotations +
  • 8. The JSON Schema Core Vocabulary +
  • 7.8. Reserved Locations +
  • +
  • 8. The JSON Schema Core Vocabulary
  • 8.2. Base URI and Dereferencing +
  • 8.2. Base URI, Anchors, and Dereferencing
  • 8.3. Comments With "$comment"
  • @@ -695,9 +707,27 @@

    Table of Contents

  • 14.2. Informative References
  • -
  • Appendix A. Acknowledgments +
  • Appendix A. Schema identification examples +
  • +
  • Appendix B. Manipulating schema documents and references +
  • +
  • Appendix C. Example of recursive schema extension +
  • +
  • Appendix D. Working with vocabularies
  • -
  • Appendix B. ChangeLog +
  • Appendix E. References and generative use cases +
  • +
  • Appendix F. Acknowledgments +
  • +
  • Appendix G. ChangeLog
  • Authors' Addresses
  • @@ -785,15 +815,19 @@

    A JSON Schema MUST be an object or a boolean.

    4.3.1. JSON Schema Objects and Keywords

    -

    Object properties that are applied to the instance are called keywords, or schema keywords. Broadly speaking, keywords fall into one of three categories:

    +

    Object properties that are applied to the instance are called keywords, or schema keywords. Broadly speaking, keywords fall into one of four categories:

    +
    identifiers:
    +
    control schema identification through setting the schema's canonical URI and/or changing how the base URI is determined
    assertions:
    produce a boolean result when applied to an instance
    annotations:
    attach information to an instance for application use
    applicators:
    apply one or more subschemas to a particular location in the instance, and combine or modify their results
    +
    reserved locations:
    +
    do not directly affect results, but reserve a place for a specific purpose to ensure interoperability

    @@ -817,16 +851,17 @@

    4.3.3. Schema Vocabularies

    A schema vocabulary, or simply a vocabulary, is a set of keywords, their syntax, and their semantics. A vocabulary is generally organized around a particular purpose. Different uses of JSON Schema, such as validation, hypermedia, or user interface generation, will involve different sets of vocabularies.

    -

    Vocabularies are the primary unit of re-use in JSON Schema, as schema authors can indicate what vocabularies are required or optional in order to process the schema. Since vocabularies are identified by URIs in the meta-schema, generic implementations can load extensions to support previously unkonw vocabularies. While keywords can be supported outside of any vocabulary, there is no analogous mechanism to indicate individual keyword usage.

    +

    Vocabularies are the primary unit of re-use in JSON Schema, as schema authors can indicate what vocabularies are required or optional in order to process the schema. Since vocabularies are identified by URIs in the meta-schema, generic implementations can load extensions to support previously unknown vocabularies. While keywords can be supported outside of any vocabulary, there is no analogous mechanism to indicate individual keyword usage.

    4.3.4. Meta-Schemas

    A schema that itself describes a schema is called a meta-schema. Meta-schemas are used to validate JSON Schemas and specify which vocabularies they are using.

    Typically, a meta-schema will specify a set of vocabularies, and validate schemas that conform to the syntax of those vocabularies. However, meta-schemas and vocabularies are separate in order to allow meta-schemas to validate schema conformance more strictly or more loosely than the vocabularies' specifications call for. Meta-schemas may also describe and validate additional keywords that are not part of a formal vocabulary.

    -4.3.5. Root Schema and Subschemas +4.3.5. Root Schema and Subschemas and Resources

    -

    The root schema is the schema that comprises the entire JSON document in question.

    -

    Some keywords take schemas themselves, allowing JSON Schemas to be nested:

    +

    A JSON Schema resource is a schema which is canonically identified by an absolute URI.

    +

    The root schema is the schema that comprises the entire JSON document in question. The root schema is always a schema resource, where the URI is determined as described in section 8.2.1.

    +

    Some keywords take schemas themselves, allowing JSON Schemas to be nested:

     
     {
    @@ -837,8 +872,9 @@ 

    }

    -

    In this example document, the schema titled "array item" is a subschema, and the schema titled "root" is the root schema.

    -

    As with the root schema, a subschema is either an object or a boolean.

    +

    In this example document, the schema titled "array item" is a subschema, and the schema titled "root" is the root schema.

    +

    As with the root schema, a subschema is either an object or a boolean.

    +

    As discussed in section 8.2.2, a JSON Schema document can contain multiple JSON Schema resources. When used without qualification, the term "root schema" refers to the document's root schema. In some cases, resource root schemas are discussed. A resource's root schema is its top-level schema object, which would also be a document root schema if the resource were to be extracted to a standalone JSON Schema document.

    5. Fragment Identifiers

    @@ -846,7 +882,7 @@

    Additionally, the "application/schema+json" media type supports two fragment identifier structures: plain names and JSON Pointers. The "application/schema-instance+json" media type supports one fragment identifier structure: JSON Pointers.

    The use of JSON Pointers as URI fragment identifiers is described in RFC 6901. For "application/schema+json", which supports two fragment identifier syntaxes, fragment identifiers matching the JSON Pointer syntax, including the empty string, MUST be interpreted as JSON Pointer fragment identifiers.

    Per the W3C's best practices for fragment identifiers, plain name fragment identifiers in "application/schema+json" are reserved for referencing locally named schemas. All fragment identifiers that do not match the JSON Pointer syntax MUST be interpreted as plain name fragment identifiers.

    -

    Defining and referencing a plain name fragment identifier within an "application/schema+json" document are specified in the "$id" keyword section.

    +

    Defining and referencing a plain name fragment identifier within an "application/schema+json" document are specified in the "$anchor" keyword section.

    6. General Considerations

    @@ -881,7 +917,8 @@

    Finally, implementations MUST NOT take regular expressions to be anchored, neither at the beginning nor at the end. This means, for instance, the pattern "es" matches "expression".

    -6.5. Extending JSON Schema

    +6.5. Extending JSON Schema +

    Additional schema keywords and schema vocabularies MAY be defined by any entity. Save for explicit agreement, schema authors SHALL NOT expect these additional keywords and vocabularies to be supported by implementations that do not explicitly document such support. Implementations SHOULD ignore keywords they do not support.

    Implementations MAY provide the ability to register or load handlers for vocabularies that they do not support directly. The exact mechanism for registering and implementing such handlers is implementation-dependent.

    @@ -891,11 +928,12 @@

    Evaluating an instance against a schema involves processing all of the keywords in the schema against the appropriate locations within the instance. Typically, applicator keywords are processed until a schema object with no applicators (and therefore no subschemas) is reached. The appropriate location in the instance is evaluated against the assertion and annotation keywords in the schema object, and their results are gathered into the parent schema according to the rules of the applicator.

    Evaluation of a parent schema object can complete once all of its subschemas have been evaluated, although in some circumstances evaluation may be short-circuited due to assertion results. When annotations are being collected, some assertion result short-circuiting is not possible due to the need to examine all subschemas for annotation collection, including those that cannot further change the assertion result.

    -7.1. Lexical Scope and Dynamic Scope

    +7.1. Lexical Scope and Dynamic Scope +

    While most JSON Schema keywords can be evaluated on their own, or at most need to take into account the values or results of adjacent keywords in the same schema object, a few have more complex behavior.

    The lexical scope of a keyword is determined by the nested JSON data structure of objects and arrays. The largest such scope is an entire schema document. The smallest scope is a single schema object with no subschemas.

    Keywords MAY be defined with a partial value, such as a URI-reference, which must be resolved against another value, such as another URI-reference or a full URI, which is found through the lexical structure of the JSON document. The "$id" core keyword and the "base" JSON Hyper-Schema keyword are examples of this sort of behavior. Additionally, "$ref" and "$recursiveRef" from this specification resolve their values in this way, although they do not change how further values are resolved.

    -

    Note that some keywords, such as "$schema", apply to the lexical scope of the entire schema document, and therefore MUST only appear in the document's root schema.

    +

    Note that some keywords, such as "$schema", apply to the lexical scope of the entire schema document, and therefore MUST only appear in a schema resource's root schema.

    Other keywords may take into account the dynamic scope that exists during the evaluation of a schema, typically together with an instance document. The outermost dynamic scope is the root schema of the schema document in which processing begins. The path from this root schema to any particular keyword (that includes any "$ref" and "$recursiveRef" keywords that may have been resolved) is considered the keyword's "validation path." [CREF1]Or should this be the schema object at which processing begins, even if it is not a root? This has some implications for the case where "$recursiveAnchor" is only allowed in the root schema but processing begins in a subschema.

    Lexical and dynamic scopes align until a reference keyword is encountered. While following the reference keyword moves processing from one lexical scope into a different one, from the perspective of dynamic scope, following reference is no different from descending into a subschema present as a value. A keyword on the far side of that reference that resolves information through the dynamic scope will consider the originating side of the reference to be their dynamic parent, rather than examining the local lexically enclosing parent.

    The concept of dynamic scope is primarily used with "$recursiveRef" and "$recursiveAnchor", and should be considered an advanced feature and used with caution when defining additional keywords. It also appears when reporting errors and collected annotations, as it may be possible to revisit the same lexical scope repeatedly with different dynamic scopes. In such cases, it is important to inform the user of the dynamic path that produced the error or annotation.

    @@ -908,29 +946,35 @@

    In some cases, the missing keyword assertion behavior of a keyword is identical to that produced by a certain value, and keyword definitions SHOULD note such values where known. However, even if the value which produces the default behavior would produce annotation results if present, the default behavior still MUST NOT result in annotations.

    Because annotation collection can add significant cost in terms of both computation and memory, implementations MAY opt out of this feature. Keywords known to an implementation to have assertion or applicator behavior that depend on annotation results MUST then be treated as errors, unless an alternate implementation producing the same behavior is available. Keywords of this sort SHOULD describe reasonable alternate approaches when appropriate. This approach is demonstrated by the "additionalItems" and "additionalProperties" keywords in this document.

    -7.4. Applicators -

    -

    Applicators allow for building more complex schemas than can be accomplished with a single schema object. Evaluation of an instance against a schema document begins by applying the root schema to the complete instance document. From there, keywords known as applicators are used to determine which additional schemas are applied. Such schemas may be applied in-place to the current location, or to a child location.

    -

    The schemas to be applied may be present as subschemas comprising all or part of the keyword's value. Alternatively, an applicator may refer to a schema elsewhere in the same schema document, or in a different one. The mechanism for identifying such referenced schemas is defined by the keyword.

    -

    Applicator keywords also define how subschema or referenced schema boolean assertion results are modified and/or combined to produce the boolean result of the applicator. Applicators may apply any boolean logic operation to the assertion results of subschemas, but MUST NOT introduce new assertion conditions of their own.

    -

    Annotation results are combined according to the rules specified by each annotation keyword.

    -

    -7.4.1. Referenced and Referencing Schemas +7.4. Identifiers

    -

    As noted in Section 7.4, an applicator keyword may refer to a schema to be applied, rather than including it as a subschema in the applicator's value. In such situations, the schema being applied is known as the referenced schema, while the schema containing the applicator keyword is the referencing schema.

    -

    While root schemas and subschemas are static concepts based on a schema's position within a schema document, referenced and referencing schemas are dynamic. Different pairs of schemas may find themselves in various referenced and referencing arrangements during the evaluation of an instance against a schema.

    -

    For some by-reference applicators, such as "$ref", the referenced schema can be determined by static analysis of the schema document's lexical scope. Others, such as "$recursiveRef" and "$recursiveAnchor", may make use of dynamic scoping, and therefore only be resolvable in the process of evaluating the schema with an instance.

    +

    Identifiers set the canonical URI of a schema, or affect how such URIs are resolved in references, or both. The Core vocabulary defined in this document defines several identifying keywords, most notably "$id".

    +

    Canonical schema URIs MUST NOT change while processing an instance, but keywords that affect URI-reference resolution MAY have behavior that is only fully determined at runtime.

    +

    While custom identifier keywords are possible, vocabulary designers should take care not to disrupt the functioning of core keywords. For example, the "$recursiveAnchor" keyword in this specification limits its URI resolution effects to the matching "$recursiveRef" keyword, leaving "$ref" undisturbed.

    -7.5. Assertions +7.5. Applicators

    -

    JSON Schema can be used to assert constraints on a JSON document, which either passes or fails the assertions. This approach can be used to validate conformance with the constraints, or document what is needed to satisfy them.

    -

    JSON Schema implementations produce a single boolean result when evaluating an instance against schema assertions.

    -

    An instance can only fail an assertion that is present in the schema.

    +

    Applicators allow for building more complex schemas than can be accomplished with a single schema object. Evaluation of an instance against a schema document begins by applying the root schema to the complete instance document. From there, keywords known as applicators are used to determine which additional schemas are applied. Such schemas may be applied in-place to the current location, or to a child location.

    +

    The schemas to be applied may be present as subschemas comprising all or part of the keyword's value. Alternatively, an applicator may refer to a schema elsewhere in the same schema document, or in a different one. The mechanism for identifying such referenced schemas is defined by the keyword.

    +

    Applicator keywords also define how subschema or referenced schema boolean assertion results are modified and/or combined to produce the boolean result of the applicator. Applicators may apply any boolean logic operation to the assertion results of subschemas, but MUST NOT introduce new assertion conditions of their own.

    +

    Annotation results are combined according to the rules specified by each annotation keyword.

    -7.5.1. Assertions and Instance Primitive Types

    -

    Most assertions only constrain values within a certain primitive type. When the type of the instance is not of the type targeted by the keyword, the instance is considered to conform to the assertion.

    -

    For example, the "maxLength" keyword from the companion validation vocabulary: will only restrict certain strings (that are too long) from being valid. If the instance is a number, boolean, null, array, or object, then it is valid against this assertion.

    -

    This behavior allows keywords to be used more easily with instances that can be of multiple primitive types. The companion validation vocabulary also includes a "type" keyword which can independently restrict the instance to one or more primitive types. This allows for a concise expression of use cases such as a function that might return either a string of a certain length or a null value:

    +7.5.1. Referenced and Referencing Schemas + +

    As noted in Section 7.5, an applicator keyword may refer to a schema to be applied, rather than including it as a subschema in the applicator's value. In such situations, the schema being applied is known as the referenced schema, while the schema containing the applicator keyword is the referencing schema.

    +

    While root schemas and subschemas are static concepts based on a schema's position within a schema document, referenced and referencing schemas are dynamic. Different pairs of schemas may find themselves in various referenced and referencing arrangements during the evaluation of an instance against a schema.

    +

    For some by-reference applicators, such as "$ref", the referenced schema can be determined by static analysis of the schema document's lexical scope. Others, such as "$recursiveRef" and "$recursiveAnchor", may make use of dynamic scoping, and therefore only be resolvable in the process of evaluating the schema with an instance.

    +

    +7.6. Assertions +

    +

    JSON Schema can be used to assert constraints on a JSON document, which either passes or fails the assertions. This approach can be used to validate conformance with the constraints, or document what is needed to satisfy them.

    +

    JSON Schema implementations produce a single boolean result when evaluating an instance against schema assertions.

    +

    An instance can only fail an assertion that is present in the schema.

    +

    +7.6.1. Assertions and Instance Primitive Types

    +

    Most assertions only constrain values within a certain primitive type. When the type of the instance is not of the type targeted by the keyword, the instance is considered to conform to the assertion.

    +

    For example, the "maxLength" keyword from the companion validation vocabulary: will only restrict certain strings (that are too long) from being valid. If the instance is a number, boolean, null, array, or object, then it is valid against this assertion.

    +

    This behavior allows keywords to be used more easily with instances that can be of multiple primitive types. The companion validation vocabulary also includes a "type" keyword which can independently restrict the instance to one or more primitive types. This allows for a concise expression of use cases such as a function that might return either a string of a certain length or a null value:

     
     {
    @@ -940,18 +984,18 @@ 

    If "maxLength" also restricted the instance type to be a string, then this would be substantially more cumbersome to express because the example as written would not actually allow null values. Each keyword is evaluated separately unless explicitly specified otherwise, so if "maxLength" restricted the instance to strings, then including "null" in "type" would not have any useful effect.

    -

    -7.6. Annotations +

    +7.7. Annotations

    -

    JSON Schema can annotate an instance with information, whenever the instance validates against the schema object containing the annotation, and all of its parent schema objects. The information can be a simple value, or can be calculated based on the instance contents.

    -

    Annotations are attached to specific locations in an instance. Since many subschemas can be applied to any single location, annotation keywords need to specify any unusual handling of multiple applicable occurrences of the keyword with different values.

    -

    The default behavior is simply to collect all values in a list in indeterminate order. Given the extensibility of keywords, including applicators, it is not possible to define a universally predictable order of processing.

    -

    Unlike assertion results, annotation data can take a wide variety of forms, which are provided to applications to use as they see fit. JSON Schema implementations are not expected to make use of the collected information on behalf of applications.

    -

    While "short-circuit" evaluation is possible for assertions, collecting annotations requires examining all schemas that apply to an instance location, even if they cannot change the overall assertion result.

    -

    -7.6.1. Collecting Annotations

    -

    Annotations are collected by keywords that explicitly define annotation-collecting behavior. Note that boolean schemas cannot produce annotations as they do not make use of keywords.

    -

    A collected annotation MUST include the following information:

    +

    JSON Schema can annotate an instance with information, whenever the instance validates against the schema object containing the annotation, and all of its parent schema objects. The information can be a simple value, or can be calculated based on the instance contents.

    +

    Annotations are attached to specific locations in an instance. Since many subschemas can be applied to any single location, annotation keywords need to specify any unusual handling of multiple applicable occurrences of the keyword with different values.

    +

    Unlike assertion results, annotation data can take a wide variety of forms, which are provided to applications to use as they see fit. JSON Schema implementations are not expected to make use of the collected information on behalf of applications.

    +

    Unless otherwise specified, the value of an annotation keyword's annotation is the keyword's value. However, other behaviors are possible. For example, JSON Hyper-Schema's "links" keyword is a complex annotation that produces a value based in part on the instance data.

    +

    While "short-circuit" evaluation is possible for assertions, collecting annotations requires examining all schemas that apply to an instance location, even if they cannot change the overall assertion result. The only exception is that subschemas of a schema object that has failed validation MAY be skipped, as annotations are not retained for failing schemas.

    +

    +7.7.1. Collecting Annotations

    +

    Annotations are collected by keywords that explicitly define annotation-collecting behavior. Note that boolean schemas cannot produce annotations as they do not make use of keywords.

    +

    A collected annotation MUST include the following information:

    -

    If the same keyword attaches values from multiple schema locations to the same instance location, and the annotation defines a process for combining such values, then the combined value MUST also be associated with the instance location.

    -

    -7.6.1.1. Distinguishing Among Multiple Values

    -

    Applications MAY make decisions on which of multiple annotation values to use based on the schema location that contributed the value. This is intended to allow flexible usage. Collecting the schema location facilitates such usage.

    -

    For example, consider this schema, which uses annotations and assertions from the Validation specification:

    +

    If the same keyword attaches values from multiple schema locations to the same instance location, and the annotation defines a process for combining such values, then the combined value MUST also be associated with the instance location. The output formats described in this specification that include annotation information meet this requirement.

    +

    +7.7.1.1. Distinguishing Among Multiple Values

    +

    Applications MAY make decisions on which of multiple annotation values to use based on the schema location that contributed the value. This is intended to allow flexible usage. Collecting the schema location facilitates such usage.

    +

    For example, consider this schema, which uses annotations and assertions from the Validation specification:

    Note that some lines are wrapped for clarity.

     
     {
         "title": "Feature list",
         "type": "array",
    -        "items": [
    -            {
    -                "title": "Feature A",
    -                "properties": {
    -                    "enabled": {
    -                        "$ref": "#/$defs/enabledToggle",
    -                        "default": true
    -                    }
    +    "items": [
    +        {
    +            "title": "Feature A",
    +            "properties": {
    +                "enabled": {
    +                    "$ref": "#/$defs/enabledToggle",
    +                    "default": true
                     }
    -            },
    -            {
    -                "title": "Feature B",
    -                "properties": {
    -                    "enabled": {
    -                        "description": "If set to null, Feature B
    -                                        inherits the enabled
    -                                        value from Feature A",
    -                        "$ref": "#/$defs/enabledToggle"
    -                    }
    +            }
    +        },
    +        {
    +            "title": "Feature B",
    +            "properties": {
    +                "enabled": {
    +                    "description": "If set to null, Feature B
    +                                    inherits the enabled
    +                                    value from Feature A",
    +                    "$ref": "#/$defs/enabledToggle"
                     }
                 }
    -        ]
    -    },
    +        }
    +    ],
         "$defs": {
             "enabledToggle": {
                 "title": "Enabled",
    @@ -1009,15 +1052,15 @@ 

    }

    -

    In this example, both Feature A and Feature B make use of the re-usable "enabledToggle" schema. That schema uses the "title", "description", and "default" annotations, none of which define special behavior for handling multiple values. Therefore the application has to decide how to handle the additional "default" value for Feature A, and the additional "description" value for Feature B.

    -

    The application programmer and the schema author need to agree on the usage. For this example, let's assume that they agree that the most specific "default" value will be used, and any additional, more generic "default" values will be silently ignored. Let's also assume that they agree that all "description" text is to be used, starting with the most generic, and ending with the most specific. This requires the schema author to write descriptions that work when combined in this way.

    -

    The application can use the schema location path to determine which values are which. The values in the feature's immediate "enabled" property schema are more specific, while the values under the re-usable schema that is referenced to with "$ref" are more generic. The schema location path will show whether each value was found by crossing a "$ref" or not.

    -

    Feature A will therefore use a default value of true, while Feature B will use the generic default value of null. Feature A will only have the generic description from the "enabledToggle" schema, while Feature B will use that description, and also append its locally defined description that explains how to interpret a null value.

    -

    Note that there are other reasonable approaches that a different application might take. For example, an application may consider the presence of two different values for "default" to be an error, regardless of their schema locations.

    -

    -7.6.1.2. Annotations and Assertions

    -

    Schema objects that produce a false assertion result MUST NOT produce any annotation results, whether from their own keywords or from keywords in subschemas.

    -

    Note that the overall schema results may still include annotations collected from other schema locations. Given this schema:

    +

    In this example, both Feature A and Feature B make use of the re-usable "enabledToggle" schema. That schema uses the "title", "description", and "default" annotations, none of which define special behavior for handling multiple values. Therefore the application has to decide how to handle the additional "default" value for Feature A, and the additional "description" value for Feature B.

    +

    The application programmer and the schema author need to agree on the usage. For this example, let's assume that they agree that the most specific "default" value will be used, and any additional, more generic "default" values will be silently ignored. Let's also assume that they agree that all "description" text is to be used, starting with the most generic, and ending with the most specific. This requires the schema author to write descriptions that work when combined in this way.

    +

    The application can use the schema location path to determine which values are which. The values in the feature's immediate "enabled" property schema are more specific, while the values under the re-usable schema that is referenced to with "$ref" are more generic. The schema location path will show whether each value was found by crossing a "$ref" or not.

    +

    Feature A will therefore use a default value of true, while Feature B will use the generic default value of null. Feature A will only have the generic description from the "enabledToggle" schema, while Feature B will use that description, and also append its locally defined description that explains how to interpret a null value.

    +

    Note that there are other reasonable approaches that a different application might take. For example, an application may consider the presence of two different values for "default" to be an error, regardless of their schema locations.

    +

    +7.7.1.2. Annotations and Assertions

    +

    Schema objects that produce a false assertion result MUST NOT produce any annotation results, whether from their own keywords or from keywords in subschemas.

    +

    Note that the overall schema results may still include annotations collected from other schema locations. Given this schema:

     
     {
    @@ -1034,18 +1077,22 @@ 

    }

    -

    And the instance "This is a string", the title annotation "Integer Value" is discarded because the type assertion in that schema object fails. The title annotation "String Value" is kept, as the instance passes the string type assertions.

    -

    -7.6.1.3. Annotations and Applicators

    -

    In addition to possibly defining annotation results of their own, applicator keywords aggregate the annotations collected in their subschema(s) or referenced schema(s). The rules for aggregating annotation values are defined by each annotation keyword, and are not directly affected by the logic used for combining assertion results.

    +

    And the instance "This is a string", the title annotation "Integer Value" is discarded because the type assertion in that schema object fails. The title annotation "String Value" is kept, as the instance passes the string type assertions.

    +

    +7.7.1.3. Annotations and Applicators

    +

    In addition to possibly defining annotation results of their own, applicator keywords aggregate the annotations collected in their subschema(s) or referenced schema(s). The rules for aggregating annotation values are defined by each annotation keyword, and are not directly affected by the logic used for combining assertion results.

    +

    +7.8. Reserved Locations

    +

    A fourth category of keywords simply reserve a location to hold re-usable components or data of interest to schema authors that is not suitable for re-use. These keywords do not affect validation or annotation results. Their purpose in the core vocabulary is to ensure that locations are available for certain purposes and will not be redefined by extension keywords.

    +

    While these keywords do not directly affect results, as explained in section 8.2.4.4 unrecognized extension keywords that reserve locations for re-usable schemas may have undesirable interactions with references in certain circumstances.

    8. The JSON Schema Core Vocabulary

    -

    Keywords declared in in this section, which all begin with "$", make up the JSON Schema Core vocabulary. These keywords are either required in order process any schema or meta-schema, including those split across multiple documents, or exist to reserve keywords for purposes that require guaranteed interoperability.

    +

    Keywords declared in this section, which all begin with "$", make up the JSON Schema Core vocabulary. These keywords are either required in order process any schema or meta-schema, including those split across multiple documents, or exist to reserve keywords for purposes that require guaranteed interoperability.

    The Core vocabulary MUST be considered mandatory at all times, in order to bootstrap the processing of further vocabularies. Meta-schemas that use the "$vocabulary" keyword to declare the vocabularies in use MUST explicitly list the Core vocabulary, which MUST have a value of true indicating that it is required.

    The behavior of a false value for this vocabulary (and only this vocabulary) is undefined, as is the behavior when "$vocabulary" is present but the Core vocabulary is not included. However, it is RECOMMENDED that implementations detect these cases and raise an error when they occur. It is not meaningful to declare that a meta-schema optionally uses Core.

    Meta-schemas that do not use "$vocabulary" MUST be considered to require the Core vocabulary as if its URI were present with a value of true.

    -

    The current URI for the Core vocabulary is: <https://json-schema.org/draft/2019-08/vocab/core>.

    -

    The current URI for the corresponding meta-schema is: <https://json-schema.org/draft/2019-08/meta/core>.

    +

    The current URI for the Core vocabulary is: <https://json-schema.org/draft/2019-09/vocab/core>.

    +

    The current URI for the corresponding meta-schema is: <https://json-schema.org/draft/2019-09/meta/core>.

    While the "$" prefix is not formally reserved for the Core vocabulary, it is RECOMMENDED that extension keywords (in vocabularies or otherwise) begin with a character other than "$" to avoid possible future collisions.

    8.1. Meta-Schemas and Vocabularies @@ -1068,16 +1115,16 @@

    The "$schema" keyword is both used as a JSON Schema feature set identifier and as the identifier of a resource which is itself a JSON Schema, which describes the set of valid schemas written for this particular feature set.

    The value of this keyword MUST be a URI (containing a scheme) and this URI MUST be normalized. The current schema MUST be valid against the meta-schema identified by this URI.

    If this URI identifies a retrievable resource, that resource SHOULD be of media type "application/schema+json".

    -

    The "$schema" keyword SHOULD be used in a root schema. It MUST NOT appear in subschemas. If absent from the root schema, the resulting behavior is implementation-defined.

    -

    [CREF2]Using multiple "$schema" keywords in the same document would imply that the feature set and therefore behavior can change within a document. This would necessitate resolving a number of implementation concerns that have not yet been clearly defined. So, while the pattern of using "$schema" only in root schemas is likely to remain the best practice for schema authoring, implementation behavior is subject to be revised or liberalized in future drafts.

    +

    The "$schema" keyword SHOULD be used in a resource root schema. It MUST NOT appear in resource subschemas. If absent from the root schema, the resulting behavior is implementation-defined.

    +

    If multiple schema resources are present in a single document, then all schema resources SHOULD Have the same value for "$schema". The result of differing values for "$schema" within the same schema document is implementation-defined. [CREF2]Using multiple "$schema" keywords in the same document would imply that the feature set and therefore behavior can change within a document. This would necessitate resolving a number of implementation concerns that have not yet been clearly defined. So, while the pattern of using "$schema" only in root schemas is likely to remain the best practice for schema authoring, implementation behavior is subject to be revised or liberalized in future drafts. [CREF3]The exception made for embedded schema resources is to allow bundling multiple schema resources into a single schema document without needing to change their contents, as described later in this specification.

    Values for this property are defined elsewhere in this and other documents, and by other parties.

    8.1.2. The "$vocabulary" Keyword

    The "$vocabulary" keyword is used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. It is also used to indicate whether each vocabulary is required or optional, in the sense that an implementation MUST understand the required vocabularies in order to successfully process the schema.

    The value of this keyword MUST be an object. The property names in the object MUST be URIs (containing a scheme) and this URI MUST be normalized. Each URI that appears as a property name identifies a specific set of keywords and their semantics.

    -

    The URI MAY be a URL, but the nature of the retrievable resource is currently undefined, and reserved for future use. Vocabulary authors MAY use the URL of the vocabulary specification, in a human-readable media type such as text/html or text/plain, as the vocabulary URI. [CREF3]Vocabulary documents may be added shortly, or in the next draft. For now, identifying the keyword set is deemed sufficient as that, along with meta-schema validation, is how the current "vocabularies" work today. Any future vocabulary document format will be specified as a JSON document, so using text/html or other non-JSON formats in the meantime will not produce any future ambiguity.

    -

    The values of the object properties MUST be booleans. If the value is true, then implementations that do not recognize the vocabulary MUST refuse to process any schemas that declare this meta-schema with "$schema". If the value is false, implementations that do not recognize the vocabulary MAY choose to proceed with processing such schemas.

    -

    When processing a schema that uses unrecognized vocabularies, keywords declared by those vocabularies are treated like any other unrecognized keyword, and ignored.

    +

    The URI MAY be a URL, but the nature of the retrievable resource is currently undefined, and reserved for future use. Vocabulary authors MAY use the URL of the vocabulary specification, in a human-readable media type such as text/html or text/plain, as the vocabulary URI. [CREF4]Vocabulary documents may be added in forthcoming drafts. For now, identifying the keyword set is deemed sufficient as that, along with meta-schema validation, is how the current "vocabularies" work today. Any future vocabulary document format will be specified as a JSON document, so using text/html or other non-JSON formats in the meantime will not produce any future ambiguity.

    +

    The values of the object properties MUST be booleans. If the value is true, then implementations that do not recognize the vocabulary MUST refuse to process any schemas that declare this meta-schema with "$schema". If the value is false, implementations that do not recognize the vocabulary SHOULD proceed with processing such schemas.

    +

    Per 6.5, unrecognized keywords SHOULD be ignored. This remains the case for keywords defined by unrecognized vocabularies. It is not currently possible to distinguish between unrecognized keywords that are defined in vocabularies from those that are not part of any vocabulary.

    The "$vocabulary" keyword SHOULD be used in the root schema of any schema document intended for use as a meta-schema. It MUST NOT appear in subschemas.

    The "$vocabulary" keyword MUST be ignored in schema documents that are not being processed as a meta-schema. This allows validating a meta-schema M against its own meta-schema M' without requiring the validator to understand the vocabularies declared by M.

    @@ -1087,7 +1134,7 @@

    For example, an implementation that is a validator SHOULD assume the use of all vocabularies in this specification and the companion Validation specification.

    8.1.2.2. Non-inheritability of vocabularies

    -

    Note that the processing restrictions on "$vocabulary" mean that meta-schemas that reference other meta-schemas using "$ref" or similar keywords do not automatically inherit the vocabulary declarations of those other meta-schemas. All such declarations must be repeated in the root of each schema document intended for use as a meta-schema. This is demonstrated in the example meta-schema.

    +

    Note that the processing restrictions on "$vocabulary" mean that meta-schemas that reference other meta-schemas using "$ref" or similar keywords do not automatically inherit the vocabulary declarations of those other meta-schemas. All such declarations must be repeated in the root of each schema document intended for use as a meta-schema. This is demonstrated in the example meta-schema. [CREF5]This requirement allows implementations to find all vocabulary requirement information in a single place for each meta-schema. As schema extensibility means that there are endless potential ways to combine more fine-grained meta-schemas by reference, requiring implementations to anticipate all possibilities and search for vocabularies in referenced meta-schemas would be overly burdensome.

    8.1.3. Updates to Meta-Schema and Vocabulary URIs

    Updated vocabulary and meta-schema URIs MAY be published between specification drafts in order to correct errors. Implementations SHOULD consider URIs dated after this specification draft and before the next to indicate the same syntax and semantics as those listed here.

    @@ -1096,303 +1143,131 @@

    Implementations MUST recognize a schema as a meta-schema if it is being examined because it was identified as such by another schema's "$schema" keyword. This means that a single schema document might sometimes be considered a regular schema, and other times be considered a meta-schema.

    In the case of examining a schema which is its own meta-schema, when an implementation begins processing it as a regular schema, it is processed under those rules. However, when loaded a second time as a result of checking its own "$schema" value, it is treated as a meta-schema. So the same document is processed both ways in the course of one session.

    Implementations MAY allow a schema to be explicitly passed as a meta-schema, for implementation-specific purposes, such as pre-loading a commonly used meta-schema and checking its vocabulary support requirements up front. Meta-schema authors MUST NOT expect such features to be interoperable across implementations.

    -

    -8.1.5. Best Practices for Vocabulary and Meta-Schema Authors

    -

    Vocabulary authors SHOULD take care to avoid keyword name collisions if the vocabulary is intended for broad use, and potentially combined with other vocabularies. JSON Schema does not provide any formal namespacing system, but also does not constrain keyword names, allowing for any number of namespacing approaches.

    -

    Vocabularies may build on each other, such as by defining the behavior of their keywords with respect to the behavior of keywords from another vocabulary, or by using a keyword from another vocabulary with a restricted or expanded set of acceptable values. Not all such vocabulary re-use will result in a new vocabulary that is compatible with the vocabulary on which it is built. Vocabulary authors SHOULD clearly document what level of compatibility, if any, is expected.

    -

    Meta-schema authors SHOULD NOT use "$vocabulary" to combine multiple vocabularies that define conflicting syntax or semantics for the same keyword. As semantic conflicts are not generally detectable through schema validation, implementations are not expected to detect such conflicts. If conflicting vocabularies are declared, the resulting behavior is undefined.

    -

    Vocabulary authors SHOULD provide a meta-schema that validates the expected usage of the vocabulary's keywords on their own. Such meta-schemas SHOULD NOT forbid additional keywords, and MUST NOT forbid any keywords from the Core vocabulary.

    -

    It is RECOMMENDED that meta-schema authors reference each vocabulary's meta-schema using the "allOf" keyword, although other mechanisms for constructing the meta-schema may be appropriate for certain use cases.

    -

    The recursive nature of meta-schemas makes the "$recursiveAnchor" and "$recursiveRef" keywords particularly useful for extending existing meta-schemas, as can be seen in the JSON Hyper-Schema meta-schema which extends the Validation meta-schema.

    -

    Meta-schemas MAY impose additional constraints, including describing keywords not present in any vocabulary, beyond what the meta-schemas associated with the declared vocabularies describe. This allows for restricting usage to a subset of a vocabulary, and for validating locally defined keywords not intended for re-use.

    -

    However, meta-schemas SHOULD NOT contradict any vocabularies that they declare, such as by requiring a different JSON type than the vocabulary expects. The resulting behavior is undefined.

    -

    Meta-schemas intended for local use, with no need to test for vocabulary support in arbitrary implementations, can safely omit "$vocabulary" entirely.

    -

    -8.1.6. Example Meta-Schema With Vocabulary Declarations -

    -

    This meta-schema explicitly declares both the Core and Applicator vocabularies, and combines their meta-schemas with an "allOf". It additionally restricts the usage of the Applicator vocabulary by forbidding the keyword prefixed with "unevaluated". It also describes a keyword, "localKeyword", that is not part of either vocabulary. Note that it is its own meta-schema, as it relies on both the Core vocabulary (as all schemas do) and the Applicator vocabulary (for "allOf").

    -
    -
    -{
    -  "$schema": "https://json-schema.org/draft/2019-WIP/core-app-example#",
    -  "$id": "https://json-schema.org/draft/2019-WIP/core-app-example",
    -  "$recursiveAnchor": true,
    -  "$vocabulary": {
    -    "https://json-schema.org/draft/2019-WIP/vocab/core": true,
    -    "https://json-schema.org/draft/2019-WIP/vocab/applicator": true
    -  },
    -  "allOf": [
    -    {"$ref": "https://json-schema.org/draft/2019-WIP/meta/core"},
    -    {"$ref": "https://json-schema.org/draft/2019-WIP/meta/applicator"}
    -  ],
    -  "patternProperties": {
    -    "^unevaluated.*$": false
    -  },
    -  "properties": {
    -    "$comment": "Not in vocabulary, but validated if used",
    -    "localKeyword": {
    -      "type": "string"
    -    }
    -  }
    -}
    -
    -                        
    -

    As shown above, even though each of the referenced standard meta-schemas declares its corresponding vocabulary, this new meta-schema must re-declare them for itself. It would be valid to leave the core vocabulary out of the "$vocabulary" keyword, but it needs to be referenced through the "allOf" keyword in order for its terms to be validated. There is no special case for validation of core keywords.

    -

    The standard meta-schemas that combine all vocabularies defined by the Core and Validation specification, and that combine all vocabularies defined by those specifications as well as the Hyper-Schema specification, demonstrate additional complex combinations. These URIs for these meta-schemas may be found in the Validation and Hyper-Schema specifications, respectively.

    -8.2. Base URI and Dereferencing

    +8.2. Base URI, Anchors, and Dereferencing

    To differentiate between schemas in a vast ecosystem, schemas are identified by URI, and can embed references to other schemas by specifying their URI.

    +

    Several keywords can accept a relative URI-reference, or a value used to construct a relative URI-reference. For these keywords, it is necessary to establish a base URI in order to resolve the reference.

    -8.2.1. Initial Base URI

    +8.2.1. Initial Base URI +

    RFC3986 Section 5.1 defines how to determine the default base URI of a document.

    Informatively, the initial base URI of a schema is the URI at which it was found, whether that was a network location, a local filesystem, or any other situation identifiable by a URI of any known scheme.

    If a schema document defines no explicit base URI with "$id" (embedded in content), the base URI is that determined per RFC 3986 section 5.

    If no source is known, or no URI scheme is known for the source, a suitable implementation-specific default URI MAY be used as described in RFC 3986 Section 5.1.4. It is RECOMMENDED that implementations document any default base URI that they assume.

    +

    Unless the "$id" keyword described in the next section is present in the root schema, this base URI SHOULD be considered the canonical URI of the schema document's root schema resource.

    8.2.2. The "$id" Keyword

    -

    The "$id" keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against. A subschema's "$id" is resolved against the base URI of its parent schema. If no parent schema defines an explicit base URI with "$id", the base URI is that of the entire document, as determined per RFC 3986 section 5.

    -

    If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference. This value SHOULD be normalized, and SHOULD NOT be an empty fragment <#> or an empty string <>.

    +

    The "$id" keyword identifies a schema resource with its canonical URI.

    +

    Note that this URI is an identifier and not necessarily a network locator. In the case of a network-addressable URL, a schema need not be downloadable from its canonical URI.

    +

    If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference. This URI-reference SHOULD be normalized, and MUST resolve to an absolute-URI (without a fragment). Therefore, "$id" MUST NOT contain a non-empty fragment, and SHOULD NOT contain an empty fragment.

    +

    Since an empty fragment in the context of the application/schema+json media type refers to the same resource as the base URI without a fragment, an implementation MAY normalize a URI ending with an empty fragment by removing the fragment. However, schema authors SHOULD NOT rely on this behavior across implementations. [CREF6]This is primarily allowed because older meta-schemas have an empty fragment in their $id (or previously, id). A future draft may outright forbid even empty fragments in "$id".

    +

    This URI also serves as the base URI for relative URI-references in keywords within the schema resource, in accordance with RFC 3986 section 5.1.1 regarding base URIs embedded in content.

    +

    The presence of "$id" in a subschema indicates that the subschema constitutes a distinct schema resource within a single schema document. Furthermore, in accordance with RFC 3986 section 5.1.2 regarding encapsulating entities, if an "$id" in a subschema is a relative URI-reference, the base URI for resolving that reference is the URI of the parent schema resource.

    +

    If no parent schema object explicitly identifies itself as a resource with "$id", the base URI is that of the entire document, as established by the steps given in the previous section.

    8.2.2.1. Identifying the root schema

    -

    The root schema of a JSON Schema document SHOULD contain an "$id" keyword with an absolute-URI (containing a scheme, but no fragment), or this absolute URI but with an empty fragment.

    +

    The root schema of a JSON Schema document SHOULD contain an "$id" keyword with an absolute-URI (containing a scheme, but no fragment).

    -8.2.2.2. Changing the base URI within a schema file

    -

    When an "$id" sets the base URI, the object containing that "$id" and all of its subschemas can be identified by using a JSON Pointer fragment starting from that location. This is true even of subschemas that further change the base URI. Therefore, a single subschema may be accessible by multiple URIs, each consisting of base URI declared in the subschema or a parent, along with a JSON Pointer fragment identifying the path from the schema object that declares the base to the subschema being identified. Examples of this are shown in section 8.2.2.4.

    -

    -8.2.2.3. Location-independent identifiers

    -

    Using JSON Pointer fragments requires knowledge of the structure of the schema. When writing schema documents with the intention to provide re-usable schemas, it may be preferable to use a plain name fragment that is not tied to any particular structural location. This allows a subschema to be relocated without requiring JSON Pointer references to be updated.

    -

    To specify such a subschema identifier, the "$id" keyword is set to a URI reference with a plain name fragment (not a JSON Pointer fragment). This value MUST begin with the number sign that specifies a fragment ("#"), then a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").

    -

    The effect of using a fragment in "$id" that isn't blank or doesn't follow the plain name syntax is undefined. [CREF4]How should an "$id" URI reference containing a fragment with other components be interpreted? There are two cases: when the other components match the current base URI and when they change the base URI.

    -

    -8.2.2.4. Schema identification examples +8.2.2.2. JSON Pointer fragments and embedded schema resources

    -

    Consider the following schema, which shows "$id" being used to identify the root schema, change the base URI for subschemas, and assign plain name fragments to subschemas:

    +

    Since JSON Pointer URI fragments are constructed based on the structure of the schema document, an embedded schema resource and its subschemas can be identified by JSON Pointer fragments relative to either its own canonical URI, or relative to the containing resource's URI.

    +

    Conceptually, a set of linked schema resources should behave identically whether each resource is a separate document connected with schema references, or is structured as a single document with one or more schema resources embedded as subschemas.

    +

    Since URIs involving JSON Pointer fragments relative to the parent schema resource's URI cease to be valid when the embedded schema is moved to a separate document and referenced, applications and schemas SHOULD NOT use such URIs to identify embedded schema resources or locations within them.

    +

    Consider the following schema document that contains another schema resource embedded within it:

     
     {
    -    "$id": "https://example.com/root.json",
    -    "$defs": {
    -        "A": { "$id": "#foo" },
    -        "B": {
    -            "$id": "other.json",
    -            "$defs": {
    -                "X": { "$id": "#bar" },
    -                "Y": { "$id": "t/inner.json" }
    -            }
    -        },
    -        "C": {
    -            "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
    -        }
    -    }
    +  "$id": "https://example.com/foo",
    +  "items": {
    +    "$id": "https://example.com/bar",
    +    "additionalProperties": { }
    +  }
     }
     
                                 
    -

    The schemas at the following URI-encoded JSON Pointers (relative to the root schema) have the following base URIs, and are identifiable by any listed URI in accordance with Section 5 above:

    -

    - -
    -
    # (document root)
    -
    -
    -
    -
    https://example.com/root.json
    -
    -
    https://example.com/root.json#
    -
    -

    -
    -
    #/$defs/A
    -
    -
    -
    -
    https://example.com/root.json#foo
    -
    -
    https://example.com/root.json#/$defs/A
    -
    -

    -
    -
    #/$defs/B
    -
    -
    -
    -
    https://example.com/other.json
    -
    -
    https://example.com/other.json#
    -
    -
    https://example.com/root.json#/$defs/B
    -
    -

    -
    -
    #/$defs/B/$defs/X
    -
    -
    -
    -
    https://example.com/other.json#bar
    -
    -
    https://example.com/other.json#/$defs/X
    -
    -
    https://example.com/root.json#/$defs/B/$defs/X
    -
    -

    -
    -
    #/$defs/B/$defs/Y
    -
    -
    -
    -
    https://example.com/t/inner.json
    -
    -
    https://example.com/t/inner.json#
    -
    -
    https://example.com/other.json#/$defs/Y
    -
    -
    https://example.com/root.json#/$defs/B/$defs/Y
    -
    -

    -
    -
    #/$defs/C
    -
    -
    -
    -
    urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f
    -
    -
    urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#
    -
    -
    https://example.com/root.json#/$defs/C
    -
    -

    -
    -
    - -

    -

    -8.2.3. Schema References

    -

    Several keywords can be used to reference a schema which is to be applied to the current instance location. "$ref" and "$recursiveRef" are applicator keywords, applying the referenced schema to the instance. "$recursiveAnchor" is a helper keyword that controls how the referenced schema of "$recursiveRef" is determined.

    -

    As the value of "$ref" and "$recursiveRef" are URI References, this allows the possibility to externalise or divide a schema across multiple files, and provides the ability to validate recursive structures through self-reference.

    -

    The resolved URI produced by these keywords is not necessarily a network locator, only an identifier. A schema need not be downloadable from the address if it is a network-addressable URL, and implementations SHOULD NOT assume they should perform a network operation when they encounter a network-addressable URI.

    -

    -8.2.3.1. Direct References with "$ref" -

    -

    The "$ref" keyword is used to reference a statically identified schema.

    -

    The value of the "$ref" property MUST be a string which is a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use.

    -

    -8.2.3.2. Recursive References with "$recursiveRef" and "$recursiveAnchor"

    -

    The "$recursiveRef" and "$recursiveAnchor" keywords are used to construct extensible recursive schemas. A recursive schema is one that has a reference to its own root, identified by the empty fragment URI reference ("#").

    -

    Extending a recursive schema with "$ref" alone involves redefining all recursive references in the source schema to point to the root of the extension. This produces the correct recursive behavior in the extension, which is that all recursion should reference the root of the extension.

    -

    Consider the following two schemas. The first schema, identified as "original" as it is the schema to be extended, describes an object with one string property and one recursive reference property, "r". The second schema, identified as "extension", references the first, and describes an additional "things" property, which is an array of recursive references. It also repeats the description of "r" from the original schema.

    +

    The URI "https://example.com/foo#/items/additionalProperties" points to the schema of the "additionalProperties" keyword in the embedded resource. The canonical URI of that schema, however, is "https://example.com/bar#/additionalProperties".

    +

    Now consider the following two schema resources linked by reference using a URI value for "$ref":

     
     {
    -    "$schema": "https://json-schema.org/draft/2019-WIP/schema#",
    -    "$id": "https://example.com/original",
    -
    -    "properties": {
    -        "name": {
    -            "type": "string"
    -        },
    -        "r": {
    -            "$ref": "#"
    -        }
    -    }
    +  "$id": "https://example.com/foo",
    +  "items": {
    +    "$ref": "bar"
    +  }
     }
     
     {
    -    "$schema": "https://json-schema.org/draft/2019-WIP/schema#",
    -    "$id": "https://example.com/extension",
    -
    -    "$ref": "original",
    -    "properties": {
    -        "r": {
    -            "$ref": "#"
    -        },
    -        "things": {
    -            "type": "array"
    -            "items": {
    -                "$ref": "#"
    -            }
    -        }
    -    }
    +  "$id": "https://example.com/bar",
    +  "additionalProperties": { }
     }
     
                                 
    -

    This apparent duplication is important because it resolves to "https://example.com/extension#", meaning that for instance validated against the extension schema, the value of "r" must be valid according to the extension, and not just the original schema as "r" was described there.

    -

    This approach is fine for a single recursive field, but the more complicated the original schema, the more redefinitions are necessary in the extension. This leads to a verbose and error-prone extension, which must be kept synchronized with the original schema if the original changes its recursive fields. This approach can be seen in the meta-schema for JSON Hyper-Schema in all prior drafts.

    -

    -8.2.3.2.1. Enabling Recursion with "$recursiveAnchor"

    -

    The desired behavior is for the recursive reference, "r", in the original schema to resolve to the original schema when that is the only schema being used, but to resolve to the extension schema when using the extension. Then there would be no need to redefine the "r" property, or others like it, in the extension.

    -

    In order to create a recursive reference, we must do three things:

    - - - -

    These three things together ensure that all schema authors are intentionally constructing a recursive extension, which in turn gives all uses of the regular "$ref" keyword confidence that it only behaves as it appears to, using lexical scoping.

    -

    The "$recursiveAnchor" keyword is how schema authors indicate that a schema can be extended recursively, and be a recursive schema. This keyword MAY appear in the root schema of a schema document, and MUST NOT appear in any subschema.

    -

    The value of "$recursiveAnchor" MUST be of type boolean, and MUST be true. The value false is reserved for possible future use.

    -

    -8.2.3.2.2. Dynamically recursive references with "$recursiveRef"

    -

    The "$recursiveRef" keyword behaves identically to "$ref", except that if the referenced schema has "$recursiveAnchor" set to true, then the implementation MUST examine the dynamic scope for the outermost (first seen) schema document with "$recursiveAnchor" set to true. If such a schema document exists, then the target of the "$recursiveRef" MUST be set to that document's URI, in place of the URI produced by the rules for "$ref".

    -

    Note that if the schema referenced by "$recursiveRef" does not contain "$recursiveAnchor" set to true, or if there are no other "$recursiveAnchor" keywords set to true anywhere further back in the dynamic scope, then "$recursiveRef"'s behavior is identical to that of "$ref".

    -

    With this in mind, we can rewrite the previous example:

    -
    -
    -{
    -    "$schema": "https://json-schema.org/draft/2019-WIP/schema#",
    -    "$id": "https://example.com/original",
    -    "$recursiveAnchor": true,
    -
    -    "properties": {
    -        "name": {
    -            "type": "string"
    -        },
    -        "r": {
    -            "$recursiveRef": "#"
    -        }
    -    }
    -}
    -
    -{
    -    "$schema": "https://json-schema.org/draft/2019-WIP/schema#",
    -    "$id": "https://example.com/extension",
    -    "$recursiveAnchor": true,
    -
    -    "$ref": "original",
    -    "properties": {
    -        "things": {
    -            "type": "array"
    -            "items": {
    -                "$recursiveRef": "#"
    -            }
    -        }
    -    }
    -}
    -
    -                                
    -

    Note that the "r" property no longer appears in the extension schema. Instead, all "$ref"s have been changed to "$recursiveRef"s, and both schemas have "$recursiveAnchor" set to true in their root schema.

    -

    When using the original schema on its own, there is no change in behavior. The "$recursiveRef" does lead to a schema where "$recursiveAnchor" is set to true, but since the original schema is the only schema document in the dynamics scope (it references itself, and does not reference any other schema documents), the behavior is effectively the same as "$ref".

    -

    When using the extension schema, the "$recursiveRef" within that schema (for the array items within "things") also effectively behaves like "$ref". The extension schema is the outermost dynamic scope, so the reference target is not changed.

    -

    In contrast, when using the extension schema, the "$recursiveRef" for "r" in the original schema now behaves differently. Its initial target is the root schema of the original schema document, which has "$recursiveAnchor" set to true. In this case, the outermost dynamic scope that also has "$recursiveAnchor" set to true is the extension schema. So when using the extensions schema, "r"'s reference in the original schema will resolve to "https://example.com/extension#", not "https://example.com/original#".

    -

    -8.2.3.3. Guarding Against Infinite Recursion

    -

    A schema MUST NOT be run into an infinite loop against an instance. For example, if two schemas "#alice" and "#bob" both have an "allOf" property that refers to the other, a naive validator might get stuck in an infinite recursive loop trying to validate the instance. Schemas SHOULD NOT make use of infinite recursive nesting like this; the behavior is undefined.

    -

    -8.2.3.4. References to Possible Non-Schemas

    -

    Subschema objects (or booleans) are recognized by their use with known applicator keywords. These keywords may be the standard applicators from this document, or extension keywords from a known vocabulary, or implementation-specific custom keywords.

    -

    Multi-level structures of unknown keywords are capable of introducing nested subschemas, which would be subject to the processing rules for "$id". Therefore, having a reference target in such an unrecognized structure cannot be reliably implemented, and the resulting behavior is undefined. Similarly, a reference target under a known keyword, for which the value is known not to be a schema, results in undefined behavior in order to avoid burdening implementations with the need to detect such targets. [CREF5]These scenarios are analogous to fetching a schema over HTTP but receiving a response with a Content-Type other than application/schema+json. An implementation can certainly try to interpret it as a schema, but the origin server offered no guarantee that it actually is any such thing. Therefore, interpreting it as such has security implications and may produce unpredictable results.

    -

    Note that single-level custom keywords with identical syntax and semantics to "$defs" do not allow for any intervening "$id" keywords, and therefore will behave correctly under implementations that attempt to use any reference target as a schema. However, this behavior is implementation-specific and MUST NOT be relied upon for interoperability.

    -

    -8.2.3.5. Loading a referenced schema

    -

    The use of URIs to identify remote schemas does not necessarily mean anything is downloaded, but instead JSON Schema implementations SHOULD understand ahead of time which schemas they will be using, and the URIs that identify them.

    -

    When schemas are downloaded, for example by a generic user-agent that doesn't know until runtime which schemas to download, see Usage for Hypermedia.

    -

    Implementations SHOULD be able to associate arbitrary URIs with an arbitrary schema and/or automatically associate a schema's "$id"-given URI, depending on the trust that the validator has in the schema. Such URIs and schemas can be supplied to an implementation prior to processing instances, or may be noted within a schema document as it is processed, producing associations as shown in section 8.2.2.4.

    -

    A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema. When multiple schemas try to identify as the same URI, validators SHOULD raise an error condition.

    -

    -8.2.3.6. Dereferencing

    -

    Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id". In all cases, dereferencing a "$ref" reference involves first resolving its value as a URI reference against the current base URI per RFC 3986.

    -

    If the resulting URI identifies a schema within the current document, or within another schema document that has been made available to the implementation, then that schema SHOULD be used automatically.

    -

    For example, consider this schema:

    +

    Here we see that the canonical URI for that "additionalProperties" subschema is still valid, while the non-canonical URI with the fragment beginning with "#/items/$ref" now resolves to nothing.

    +

    Note also that "https://example.com/foo#/items" is valid in both arrangments, but resolves to a different value. This URI ends up functioning similarly to a retrieval URI for a resource. While valid, examining the resolved value and either using the "$id" (if the value is a subschema), or resolving the reference and using the "$id" of the reference target, is preferable.

    +

    An implementation MAY choose not to support addressing schemas by non-canonical URIs. As such, it is RECOMENDED that schema authors only use canonical URIs, as using non-canonical URIs may reduce schema interoperability. [CREF7]This is to avoid requiring implementations to keep track of a whole stack of possible base URIs and JSON Pointer fragments for each, given that all but one will be fragile if the schema resources are reorganized. Some have argued that this is easy so there is no point in forbidding it, while others have argued that it complicates schema identification and should be forbidden. Feedback on this topic is encouraged.

    +

    Further examples of such non-canonical URIs, as well as the appropriate canonical URIs to use instead, are provided in appendix A.

    +

    +8.2.3. Defining location-independent identifiers with "$anchor" +

    +

    Using JSON Pointer fragments requires knowledge of the structure of the schema. When writing schema documents with the intention to provide re-usable schemas, it may be preferable to use a plain name fragment that is not tied to any particular structural location. This allows a subschema to be relocated without requiring JSON Pointer references to be updated.

    +

    The "$anchor" keyword is used to specify such a fragment. It is an identifier keyword that can only be used to create plain name fragments.

    +

    If present, the value of this keyword MUST be a string, which MUST start with a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods ("."). [CREF8]Note that the anchor string does not include the "#" character, as it is not a URI-reference. An "$anchor": "foo" becomes the fragment "#foo" when used in a URI. See below for full examples.

    +

    The base URI to which the resulting fragment is appended is determined by the "$id" keyword as explained in the previous section. Two "$anchor" keywords in the same schema document MAY have the same value if they apply to different base URIs, as the resulting full URIs will be distinct. However, the effect of two "$anchor" keywords with the same value and the same base URI is undefined. Implementations MAY raise an error if such usage is detected.

    +

    +8.2.4. Schema References +

    +

    Several keywords can be used to reference a schema which is to be applied to the current instance location. "$ref" and "$recursiveRef" are applicator keywords, applying the referenced schema to the instance. "$recursiveAnchor" is an identifier keyword that controls how the base URI for resolving the URI-reference value of "$recursiveRef is determined.

    +

    As the values of "$ref" and "$recursiveRef" are URI References, this allows the possibility to externalise or divide a schema across multiple files, and provides the ability to validate recursive structures through self-reference.

    +

    The resolved URI produced by these keywords is not necessarily a network locator, only an identifier. A schema need not be downloadable from the address if it is a network-addressable URL, and implementations SHOULD NOT assume they should perform a network operation when they encounter a network-addressable URI.

    +

    +8.2.4.1. Direct References with "$ref" +

    +

    The "$ref" keyword is an applicator that is used to reference a statically identified schema. Its results are the results of the referenced schema. [CREF9]Note that this definition of how the results are determined means that other keywords can appear alongside of "$ref" in the same schema object.

    +

    The value of the "$ref" property MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI of the schema to apply.

    +

    +8.2.4.2. Recursive References with "$recursiveRef" and "$recursiveAnchor" +

    +

    The "$recursiveRef" and "$recursiveAnchor" keywords are used to construct extensible recursive schemas. A recursive schema is one that has a reference to its own root, identified by the empty fragment URI reference ("#").

    +

    Simply stated, a "$recursiveRef" behaves identically to "$ref", except when its target schema contains "$recursiveAnchor" with a value of true. In that case, the dynamic scope is examined to determine a new base URI, and the URI-reference in "$recursiveRef" is re-evaluated against that base URI. Unlike base URI changes with "$id", changes with "$recursiveAnchor" are calculated each time a "$recursiveRef" is resolved, and do not impact any other keywords.

    +

    For an example using these keyword, see appendix C. [CREF10]The difference between the hyper-schema meta-schema in previous drafts and an this draft dramatically demonstrates the utility of these keywords.

    +

    +8.2.4.2.1. Dynamically recursive references with "$recursiveRef"

    +

    The value of the "$recursiveRef" property MUST be a string which is a URI-reference. It is a by-reference applicator that uses a dynamically calculated base URI to resolve its value.

    +

    The behavior of this keyword is defined only for the value "#". Implementations MAY choose to consider other values to be errors. [CREF11]This restriction may be relaxed in the future, but to date only the value "#" has a clear use case.

    +

    The value of "$recursiveRef" is initially resolved against the current base URI, in the same manner as for "$ref".

    +

    The schema identified by the resulting URI is examined for the presence of "$recursiveAnchor", and a new base URI is calculated as described for that keyword in the following section.

    +

    Finally, the value of "$recursiveRef" is resolved against the new base URI determined according to "$recursiveAnchor" producing the final resolved reference URI.

    +

    Note that in the absence of "$recursiveAnchor" (and in some cases when it is present), "$recursiveRef"'s behavior is identical to that of "$ref".

    +

    As with "$ref", the results of this keyword are the results of the referenced schema.

    +

    +8.2.4.2.2. Enabling Recursion with "$recursiveAnchor"

    +

    The value of the "$recursiveAnchor" property MUST be a boolean.

    +

    "$recursiveAnchor" is used to dynamically identify a base URI at runtime for "$recursiveRef" by marking where such a calculation can start, and where it stops. This keyword MUST NOT affect the base URI of other keywords, unless they are explicitly defined to rely on it.

    +

    If set to true, then when the containing schema object is used as a target of "$recursiveRef", a new base URI is determined by examining the dynamic scope for the outermost schema that also contains "$recursiveAnchor" with a value of true. The base URI of that schema is then used as the dynamic base URI.

    +

    If no such schema exists, then the base URI is unchanged.

    +

    If this keyword is set to false, the base URI is unchanged.

    +

    Omitting this keyword has the same behavior as a value of false.

    +

    +8.2.4.3. Guarding Against Infinite Recursion

    +

    A schema MUST NOT be run into an infinite loop against an instance. For example, if two schemas "#alice" and "#bob" both have an "allOf" property that refers to the other, a naive validator might get stuck in an infinite recursive loop trying to validate the instance. Schemas SHOULD NOT make use of infinite recursive nesting like this; the behavior is undefined.

    +

    +8.2.4.4. References to Possible Non-Schemas +

    +

    Subschema objects (or booleans) are recognized by their use with known applicator keywords or with location-reserving keywords such as "$defs" that take one or more subschemas as a value. These keywords may be "$defs" and the standard applicators from this document, or extension keywords from a known vocabulary, or implementation-specific custom keywords.

    +

    Multi-level structures of unknown keywords are capable of introducing nested subschemas, which would be subject to the processing rules for "$id". Therefore, having a reference target in such an unrecognized structure cannot be reliably implemented, and the resulting behavior is undefined. Similarly, a reference target under a known keyword, for which the value is known not to be a schema, results in undefined behavior in order to avoid burdening implementations with the need to detect such targets. [CREF12]These scenarios are analogous to fetching a schema over HTTP but receiving a response with a Content-Type other than application/schema+json. An implementation can certainly try to interpret it as a schema, but the origin server offered no guarantee that it actually is any such thing. Therefore, interpreting it as such has security implications and may produce unpredictable results.

    +

    Note that single-level custom keywords with identical syntax and semantics to "$defs" do not allow for any intervening "$id" keywords, and therefore will behave correctly under implementations that attempt to use any reference target as a schema. However, this behavior is implementation-specific and MUST NOT be relied upon for interoperability.

    +

    +8.2.4.5. Loading a referenced schema

    +

    The use of URIs to identify remote schemas does not necessarily mean anything is downloaded, but instead JSON Schema implementations SHOULD understand ahead of time which schemas they will be using, and the URIs that identify them.

    +

    When schemas are downloaded, for example by a generic user-agent that doesn't know until runtime which schemas to download, see Usage for Hypermedia.

    +

    Implementations SHOULD be able to associate arbitrary URIs with an arbitrary schema and/or automatically associate a schema's "$id"-given URI, depending on the trust that the validator has in the schema. Such URIs and schemas can be supplied to an implementation prior to processing instances, or may be noted within a schema document as it is processed, producing associations as shown in appendix A.

    +

    A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema. When multiple schemas try to identify as the same URI, validators SHOULD raise an error condition.

    +

    +8.2.4.6. Dereferencing

    +

    Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id". In all cases, dereferencing a "$ref" reference involves first resolving its value as a URI reference against the current base URI per RFC 3986.

    +

    If the resulting URI identifies a schema within the current document, or within another schema document that has been made available to the implementation, then that schema SHOULD be used automatically.

    +

    For example, consider this schema:

     
     {
    @@ -1403,7 +1278,7 @@ 

    }, "$defs": { "single": { - "$id": "#item", + "$anchor": "item", "type": "object", "additionalProperties": { "$ref": "other.json" } } @@ -1411,13 +1286,14 @@

    }

    -

    When an implementation encounters the <#/$defs/single> schema, it resolves the "$id" URI reference against the current base URI to form <https://example.net/root.json#item>.

    -

    When an implementation then looks inside the <#/items> schema, it encounters the <#item> reference, and resolves this to <https://example.net/root.json#item>, which it has seen defined in this same document and can therefore use automatically.

    -

    When an implementation encounters the reference to "other.json", it resolves this to <https://example.net/other.json>, which is not defined in this document. If a schema with that identifier has otherwise been supplied to the implementation, it can also be used automatically. [CREF6]What should implementations do when the referenced schema is not known? Are there circumstances in which automatic network dereferencing is allowed? A same origin policy? A user-configurable option? In the case of an evolving API described by Hyper-Schema, it is expected that new schemas will be added to the system dynamically, so placing an absolute requirement of pre-loading schema documents is not feasible.

    -

    -8.2.4. Schema Re-Use With "$defs"

    -

    The "$defs" keyword provides a standardized location for schema authors to inline re-usable JSON Schemas into a more general schema. The keyword does not directly affect the validation result.

    -

    This keyword's value MUST be an object. Each member value of this object MUST be a valid JSON Schema.

    +

    When an implementation encounters the <#/$defs/single> schema, it resolves the "$id" URI reference against the current base URI to form <https://example.net/root.json#item>.

    +

    When an implementation then looks inside the <#/items> schema, it encounters the <#item> reference, and resolves this to <https://example.net/root.json#item>, which it has seen defined in this same document and can therefore use automatically.

    +

    When an implementation encounters the reference to "other.json", it resolves this to <https://example.net/other.json>, which is not defined in this document. If a schema with that identifier has otherwise been supplied to the implementation, it can also be used automatically. [CREF13]What should implementations do when the referenced schema is not known? Are there circumstances in which automatic network dereferencing is allowed? A same origin policy? A user-configurable option? In the case of an evolving API described by Hyper-Schema, it is expected that new schemas will be added to the system dynamically, so placing an absolute requirement of pre-loading schema documents is not feasible.

    +

    +8.2.5. Schema Re-Use With "$defs" +

    +

    The "$defs" keyword reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema. The keyword does not directly affect the validation result.

    +

    This keyword's value MUST be an object. Each member value of this object MUST be a valid JSON Schema.

     
     {
    @@ -1432,16 +1308,21 @@ 

    }

    -

    As an example, here is a schema describing an array of positive integers, where the positive integer constraint is a subschema in "$defs":

    +

    As an example, here is a schema describing an array of positive integers, where the positive integer constraint is a subschema in "$defs":

    8.3. Comments With "$comment"

    -

    This keyword is reserved for comments from schema authors to readers or maintainers of the schema. The value of this keyword MUST be a string. Implementations MUST NOT present this string to end users. Tools for editing schemas SHOULD support displaying and editing this keyword. The value of this keyword MAY be used in debug or error output which is intended for developers making use of schemas. Schema vocabularies SHOULD allow "$comment" within any object containing vocabulary keywords. Implementations MAY assume "$comment" is allowed unless the vocabulary specifically forbids it. Vocabularies MUST NOT specify any effect of "$comment" beyond what is described in this specification. Tools that translate other media types or programming languages to and from application/schema+json MAY choose to convert that media type or programming language's native comments to or from "$comment" values. The behavior of such translation when both native comments and "$comment" properties are present is implementation-dependent. Implementations SHOULD treat "$comment" identically to an unknown extension keyword. They MAY strip "$comment" values at any point during processing. In particular, this allows for shortening schemas when the size of deployed schemas is a concern. Implementations MUST NOT take any other action based on the presence, absence, or contents of "$comment" properties. In particular, the value of "$comment" MUST NOT be collected as an annotation result.

    +

    This keyword reserves a location for comments from schema authors to readers or maintainers of the schema.

    +

    The value of this keyword MUST be a string. Implementations MUST NOT present this string to end users. Tools for editing schemas SHOULD support displaying and editing this keyword. The value of this keyword MAY be used in debug or error output which is intended for developers making use of schemas.

    +

    Schema vocabularies SHOULD allow "$comment" within any object containing vocabulary keywords. Implementations MAY assume "$comment" is allowed unless the vocabulary specifically forbids it. Vocabularies MUST NOT specify any effect of "$comment" beyond what is described in this specification.

    +

    Tools that translate other media types or programming languages to and from application/schema+json MAY choose to convert that media type or programming language's native comments to or from "$comment" values. The behavior of such translation when both native comments and "$comment" properties are present is implementation-dependent.

    +

    Implementations SHOULD treat "$comment" identically to an unknown extension keyword. They MAY strip "$comment" values at any point during processing. In particular, this allows for shortening schemas when the size of deployed schemas is a concern.

    +

    Implementations MUST NOT take any other action based on the presence, absence, or contents of "$comment" properties. In particular, the value of "$comment" MUST NOT be collected as an annotation result.

    9. A Vocabulary for Applying Subschemas

    This section defines a vocabulary of applicator keywords that are RECOMMENDED for use as the basis of other vocabularies.

    Meta-schemas that do not use "$vocabulary" SHOULD be considered to require this vocabulary as if its URI were present with a value of true.

    -

    The current URI for this vocabulary, known as the Applicator vocabulary, is: <https://json-schema.org/draft/2019-08/vocab/applicator>.

    -

    The current URI for the corresponding meta-schema is: <https://json-schema.org/draft/2019-08/meta/applicator>.

    +

    The current URI for this vocabulary, known as the Applicator vocabulary, is: <https://json-schema.org/draft/2019-09/vocab/applicator>.

    +

    The current URI for the corresponding meta-schema is: <https://json-schema.org/draft/2019-09/meta/applicator>.

    Updated vocabulary and meta-schema URIs MAY be published between specification drafts in order to correct errors. Implementations SHOULD consider URIs dated after this specification draft and before the next to indicate the same syntax and semantics as those listed here.

    9.1. Keyword Independence

    @@ -1616,34 +1497,35 @@

    The relative location of the validating keyword that follows the validation path. The value MUST be expressed as a JSON Pointer, and it MUST include any by-reference applicators such as "$ref" or "$recursiveRef".

     
    -#/properties/minLength/$ref/minimum
    +#/properties/width/$ref/minimum
     
                             
    -

    Note that this pointer may not be resolvable due to the inclusion of these applicator keywords.

    +

    Note that this pointer may not be resolvable by the normal JSON Pointer process due to the inclusion of these by-reference applicator keywords.

    The JSON key for this information is "keywordLocation".

    10.3.2. Keyword Absolute Location

    -

    The absolute, dereferenced location of the validating keyword. The value MUST be expressed as an absolute URI, and it MUST NOT include by-reference applicators such as "$ref" or "$recursiveRef".

    +

    The absolute, dereferenced location of the validating keyword. The value MUST be expressed as an absolute URI using the canonical URI of the relevant schema object, and it MUST NOT include by-reference applicators such as "$ref" or "$recursiveRef" as non-terminal path components. It MAY end in such keywords if the error or annotation is for that keyword, such as an unresolvable reference.

     
    -https://json-schema.org/draft/2019-WIP/schema#/$defs/nonNegativeInteger/minimum
    +https://example.com/schemas/common#/$defs/count/minimum
     
                             

    This information MAY be omitted only if either the relative location contains no references or if the schema does not declare an absolute URI as its "$id".

    The JSON key for this information is "absoluteKeywordLocation".

    10.3.3. Instance Location

    -

    The location of the JSON value within the instance being validated. The value MUST be expressed as a JSON Pointer.

    +

    The location of the JSON value within the instance being validated. The value MUST be expressed as a URI fragment-encoded JSON Pointer.

    The JSON key for this information is "instanceLocation".

    10.3.4. Error or Annotation

    The error or annotation that is produced by the validation.

    For errors, the specific wording for the message is not defined by this specification. Implementations will need to provide this.

    -

    The JSON key for failed validations is "error"; for successful validations it is "annotation".

    +

    For annotations, each keyword that produces an annotation specifies its format. By default, it is the keyword's value.

    +

    The JSON key for failed validations is "error"; for successful validations it is "annotation".

    10.3.5. Nested Results

    For the two hierarchical structures, this property will hold nested errors and annotations.

    -

    The JSON key for nested results in failed validations is "errors"; for successful validations it is "annotations".

    +

    The JSON key for nested results in failed validations is "errors"; for successful validations it is "annotations". Note the plural forms, as a keyword with nested results can also have a local error or annotation.

    10.4. Output Structure

    The output MUST be an object containing a boolean property named "valid". When additional information about the result is required, the output MUST also contain "errors" or "annotations" as described below.

    @@ -1658,8 +1540,8 @@

     
     {
    -  "$id": "https://example.com/polygon#",
    -  "$schema": "https://json-schema.org/draft/2019-WIP/schema#",
    +  "$id": "https://example.com/polygon",
    +  "$schema": "https://json-schema.org/draft/2019-09/schema",
       "$defs": {
         "point": {
           "type": "object",
    @@ -1754,7 +1636,7 @@ 

    10.4.3. Detailed

    -

    The "Detailed" structure is based on the schema and can be more readable for both humans and machines. Having the structure organized this way makes associations between the errors more apparent. For example, the fact that the missing "y" property and the extra "z" property both stem from the same location in the instance is not immediately obvious in the "Basic" structure. In a hierarchy, the correllation is more easily identified.

    +

    The "Detailed" structure is based on the schema and can be more readable for both humans and machines. Having the structure organized this way makes associations between the errors more apparent. For example, the fact that the missing "y" property and the extra "z" property both stem from the same location in the instance is not immediately obvious in the "Basic" structure. In a hierarchy, the correlation is more easily identified.

    The following rules govern the construction of the results object: