From 095a009acc1938caf9596085d5581e7196021f66 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 25 Jun 2022 01:14:24 -0400 Subject: [PATCH] Squashed 'json/' changes from cf78d97d0..f0f619d19 f0f619d19 Merge pull request #560 from json-schema-org/ether/fix-383 fa791ada9 remove tests that are not valid for draft7 0f341dca0 Merge pull request #429 from notEthan/decimal_minItems 32ec6305c test validation of keywords which expect integers when their value has a decimal 547330dd6 Tweak the markdown table syntax in the README. 28ed3022c Restructure the README further. 45d6e5e7f README: Add new content and update the structure 4de0966a7 Merge pull request #558 from yakimun/replace-definitions-with-defs aad0f350a Replace definitions with for 2019 and later drafts 0b777ffa2 Merge branch 'ether/more-anchor-and-id-tests' d593591d7 Forward port the just-added tests to 2020 and next. e157bc0b7 squash: use a unique $id to prevent namespace collisions across tests 1d5583de6 some tests of the interactions between $id, $anchor and $ref 07c45c0d7 Restore the dependencies tests as optional for 2019, 2020, and next git-subtree-dir: json git-subtree-split: f0f619d19696a81f7683116f707a51c34150d28f --- README.md | 196 +++++++++---- remotes/locationIndependentIdentifier.json | 2 +- tests/draft-next/anchor.json | 31 ++ tests/draft-next/id.json | 31 ++ tests/draft-next/maxContains.json | 19 ++ tests/draft-next/maxItems.json | 16 ++ tests/draft-next/maxLength.json | 16 ++ tests/draft-next/maxProperties.json | 16 ++ tests/draft-next/minContains.json | 19 ++ tests/draft-next/minItems.json | 16 ++ tests/draft-next/minLength.json | 16 ++ tests/draft-next/minProperties.json | 16 ++ .../optional/dependencies-compatibility.json | 269 ++++++++++++++++++ tests/draft-next/ref.json | 65 +++++ tests/draft-next/refRemote.json | 2 +- tests/draft2019-09/anchor.json | 31 ++ tests/draft2019-09/id.json | 35 ++- tests/draft2019-09/maxContains.json | 19 ++ tests/draft2019-09/maxItems.json | 16 ++ tests/draft2019-09/maxLength.json | 16 ++ tests/draft2019-09/maxProperties.json | 16 ++ tests/draft2019-09/minContains.json | 19 ++ tests/draft2019-09/minItems.json | 16 ++ tests/draft2019-09/minLength.json | 16 ++ tests/draft2019-09/minProperties.json | 16 ++ .../optional/dependencies-compatibility.json | 269 ++++++++++++++++++ tests/draft2019-09/ref.json | 73 ++++- tests/draft2019-09/refRemote.json | 2 +- tests/draft2020-12/anchor.json | 31 ++ tests/draft2020-12/id.json | 31 ++ tests/draft2020-12/maxContains.json | 19 ++ tests/draft2020-12/maxItems.json | 16 ++ tests/draft2020-12/maxLength.json | 16 ++ tests/draft2020-12/maxProperties.json | 16 ++ tests/draft2020-12/minContains.json | 19 ++ tests/draft2020-12/minItems.json | 16 ++ tests/draft2020-12/minLength.json | 16 ++ tests/draft2020-12/minProperties.json | 16 ++ .../optional/dependencies-compatibility.json | 269 ++++++++++++++++++ tests/draft2020-12/ref.json | 65 +++++ tests/draft2020-12/refRemote.json | 2 +- tests/draft6/id.json | 63 +++- tests/draft6/maxItems.json | 16 ++ tests/draft6/maxLength.json | 16 ++ tests/draft6/maxProperties.json | 16 ++ tests/draft6/minItems.json | 16 ++ tests/draft6/minLength.json | 16 ++ tests/draft6/minProperties.json | 16 ++ tests/draft7/id.json | 63 +++- tests/draft7/maxItems.json | 16 ++ tests/draft7/maxLength.json | 16 ++ tests/draft7/maxProperties.json | 16 ++ tests/draft7/minItems.json | 16 ++ tests/draft7/minLength.json | 16 ++ tests/draft7/minProperties.json | 16 ++ 55 files changed, 2065 insertions(+), 59 deletions(-) create mode 100644 tests/draft-next/optional/dependencies-compatibility.json create mode 100644 tests/draft2019-09/optional/dependencies-compatibility.json create mode 100644 tests/draft2020-12/optional/dependencies-compatibility.json diff --git a/README.md b/README.md index b5cd6d557..250bbb1a4 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,71 @@ -# JSON Schema Test Suite +# JSON Schema Test Suite + [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![Financial Contributors on Open Collective](https://opencollective.com/json-schema/all/badge.svg?label=financial+contributors)](https://opencollective.com/json-schema) [![Build Status](https://github.com/json-schema-org/JSON-Schema-Test-Suite/workflows/Test%20Suite%20Sanity%20Checking/badge.svg)](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22) -This repository contains a set of JSON objects that implementors of JSON Schema -validation libraries can use to test their validators. +This repository contains a set of JSON objects that implementers of JSON Schema validation libraries can use to test their validators. It is meant to be language agnostic and should require only a JSON parser. +The conversion of the JSON objects into tests within a specific language and test framework of choice is left to be done by the validator implementer. + +## Coverage + +All JSON Schema specification releases should be well covered by this suite, including drafts 2020-12, 2019-09, 07, 06, 04 and 03. +Drafts 04 and 03 are considered "frozen" in that less effort is put in to backport new tests to these versions. + +Additional coverage is always welcome, particularly for bugs encountered in real-world implementations. +If you see anything missing or incorrect, please feel free to [file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues) or [submit a PR](https://github.com/json-schema-org/JSON-Schema-Test-Suite). + +## Introduction to the Test Suite Structure + +The tests in this suite are contained in the `tests` directory at the root of this repository. +Inside that directory is a subdirectory for each released version of the specification. + +The structure and contents of each file in these directories is described below. + +In addition to the version-specific subdirectories, two additional directories are present: -The conversion of the JSON objects into tests within your test framework of -choice is still the job of the validator implementor. +1. `draft-next/`: containing tests for the next version of the specification whilst it is in development +2. `latest/`: a symbolic link which points to the directory which is the most recent release (which may be useful for implementations providing specific entry points for validating against the latest version of the specification) -## Structure of a Test +Inside each version directory there are a number of `.json` files each containing a collection of related tests. +Often the grouping is by property under test, but not always. +In addition to the `.json` files, each version directory contains one or more special subdirectories whose purpose is [described below](#subdirectories-within-each-draft), and which contain additional `.json` files. -The tests in this suite are contained in the `tests` directory at the root of -this repository. Inside that directory is a subdirectory for each draft or -version of the specification. +Each `.json` file consists of a single JSON array of test cases. -Inside each draft directory, there are a number of `.json` files and one or more -special subdirectories. The subdirectories contain `.json` files meant for a -specific testing purpose, and each `.json` file logically groups a set of test -cases together. Often the grouping is by property under test, but not always. +### Terminology -The subdirectories are described in the next section. +For clarity, we first define this document's usage of some testing terminology: -Inside each `.json` file is a single array containing objects. It's easiest to -illustrate the structure of these with an example: +| term | definition | +|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **test suite** | the entirety of the contents of this repository, containing tests for multiple different releases of the JSON Schema specification | +| **test case** | a single schema, along with a description and an array of *test*s | +| **test** | within a *test case*, a single test example, containing a description, instance and a boolean indicating whether the instance is valid under the test case schema | +| **test runner** | a program, external to this repository and authored by a user of this suite, which is executing each of the tests in the suite | + +An example illustrating this structure is immediately below, and a JSON Schema containing a formal definition of the contents of test cases can be found [alongside this README](./test-schema.json). + +### Sample Test Case + +Here is a single *test case*, containing one or more tests: ```json { - "description": "The description of the test case", - "schema": { - "description": "The schema against which the data in each test is validated", - "type": "string" - }, + "description": "The test case description", + "schema": { "type": "string" }, "tests": [ { - "description": "Test for a valid instance", - "data": "the instance to validate", + "description": "a test with a valid instance", + "data": "a string", "valid": true }, { - "description": "Test for an invalid instance", + "description": "a test with an invalid instance", "data": 15, "valid": false } @@ -51,35 +73,114 @@ illustrate the structure of these with an example: } ``` -In short: a description, a schema under test, and some tests, where each test -in the `tests` array is an objects with a description of the case itself, the -instance under test, and a boolean indicating whether it should be valid -or invalid. +### Subdirectories Within Each Draft -## Test Subdirectories +There is currently only one additional subdirectory that may exist within each draft test directory. -There is currently only one subdirectory that may exist within each draft -directory. This is: +This is: 1. `optional/`: Contains tests that are considered optional. -## Coverage +Note, the `optional/` subdirectory today conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in +which case they are not truly optional in such a language). +In the future this directory structure will be made richer to reflect these differences more clearly. + +## Using the Suite to Test a Validator Implementation + +The test suite structure was described [above](#introduction-to-the-test-suite-structure). + +If you are authoring a new validator implementation, or adding support for an additional version of the specification, this section describes: + +1. How to implement a test runner which passes tests to your validator +2. Assumptions the suite makes about how the test runner will configure your validator +3. Invariants the test suite claims to hold for its tests -All JSON Schema specification releases should be well covered by this suite, -including drafts 2020-12, 2019-09, 07, 06, 04 and 03. Additional coverage is -always welcome, particularly for bugs encountered in real-world -implementations. +### How to Implement a Test Runner -Drafts 04 and 03 are considered "frozen" in that less effort is put in to -backport new tests to these versions. +Presented here is a possible implementation of a test runner. +The precise steps described do not need to be followed exactly, but the results of your own procedure should produce the same effects. -Contributions are very welcome, especially from implementers as they add support -to their own implementations. +To test a specific version: -If you see anything missing from the current supported drafts, or incorrect on -any draft still accepting bug fixes, please -[file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues) -or [submit a PR](https://github.com/json-schema-org/JSON-Schema-Test-Suite). +* Load any remote references [described below](additional-assumptions) and configure your implementation to retrieve them via their URIs +* Walk the filesystem tree for that version's subdirectory and for each `.json` file found: + + * if the file is located in the root of the version directory: + + * for each test case present in the file: + + * load the schema from the `"schema"` property + * load (or log) the test case description from the `"description"` property for debugging or outputting + * for each test in the `"tests"` property: + + * load the instance to be tested from the `"data"` property + * load (or log) the individual test description from the `"description"` property for debugging or outputting + + * use the schema loaded above to validate whether the instance is considered valid under your implementation + + * if the result from your implementation matches the value found in the `"valid"` property, your implementation correctly implements the specific example + * if the result does not match, or your implementation errors or crashes, your implementation does not correctly implement the specific example + + * otherwise it is located in a special subdirectory as described above. + Follow the additional assumptions and restrictions for the containing subdirectory, then run the test case as above. + +If your implementation supports multiple versions, run the above procedure for each version supported, configuring your implementation as appropriate to call each version individually. + +### Additional Assumptions + +1. The suite, notably in its `refRemote.json` file in each draft, expects a number of remote references to be configured. + These are JSON documents, identified by URI, which are used by the suite to test the behavior of the `$ref` keyword (and related keywords). + Depending on your implementation, you may configure how to "register" these either by retrieving them from the `remotes/` directory at the root of the repository, *or* you may execute `bin/jsonschema_suite remotes` using the executable in the `bin/` directory, which will output a JSON object containing all of the remotes combined. + +2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run. + In particular, tests within the `optional/format` subdirectory may require implementations to change the way they treat the `"format"`keyword (particularly on older drafts which did not have a notion of vocabularies). + +### Invariants & Guarantees + +The test suite guarantees a number of things about tests it defines. +Any deviation from the below is generally considered a bug. +If you suspect one, please [file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/new): + +1. All files containing test cases are valid JSON. +2. The contents of the `"schema"` property in a test case are always valid + JSON Schemas under the corresponding specification. + + The rationale behind this is that we are testing instances in a test's `"data"` element, and not the schema itself. + A number of tests *do* test the validity of a schema itself, but do so by representing the schema as an instance inside a test, with the associated meta-schema in the `"schema"` property (via the `"$ref"` keyword): + + ```json + { + "description": "Test the \"type\" schema keyword", + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Valid: string", + "data": { + "type": "string" + }, + "valid": true + }, + { + "description": "Invalid: null", + "data": { + "type": null + }, + "valid": false + } + ] + } + ``` + See below for some [known limitations](#known-limitations). + +## Known Limitations + +This suite expresses its assertions about the behavior of an implementation *within* JSON Schema itself. +Each test is the application of a schema to a particular instance. +This means that the suite of tests can test against any behavior a schema can describe, and conversely cannot test against any behavior which a schema is incapable of representing, even if the behavior is mandated by the specification. + +For example, a schema can require that a string is a _URI-reference_ and even that it matches a certain pattern, but even though the specification contains [recommendations about URIs being normalized](https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-id-keyword), a JSON schema cannot today represent this assertion within the core vocabularies of the specifications, so no test covers this behavior. ## Who Uses the Test Suite @@ -153,12 +254,9 @@ This suite is being used by: ### Node.js -For node.js developers, the suite is also available as an -[npm](https://www.npmjs.com/package/@json-schema-org/tests) package. +For node.js developers, the suite is also available as an [npm](https://www.npmjs.com/package/@json-schema-org/tests) package. -Node-specific support is maintained in a [separate -repository](https://github.com/json-schema-org/json-schema-test-suite-npm) -which also welcomes your contributions! +Node-specific support is maintained in a [separate repository](https://github.com/json-schema-org/json-schema-test-suite-npm) which also welcomes your contributions! ### .NET diff --git a/remotes/locationIndependentIdentifier.json b/remotes/locationIndependentIdentifier.json index 8795c013b..96b17c3f1 100644 --- a/remotes/locationIndependentIdentifier.json +++ b/remotes/locationIndependentIdentifier.json @@ -1,5 +1,5 @@ { - "definitions": { + "$defs": { "refToInteger": { "$ref": "#foo" }, diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index 416c22496..4e8987e03 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft-next/id.json b/tests/draft-next/id.json index c5eab10db..db7afaf25 100644 --- a/tests/draft-next/id.json +++ b/tests/draft-next/id.json @@ -254,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft-next/maxContains.json b/tests/draft-next/maxContains.json index e95bb9f8b..7ed1dcf8f 100644 --- a/tests/draft-next/maxContains.json +++ b/tests/draft-next/maxContains.json @@ -86,6 +86,25 @@ } ] }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, { "description": "minContains < maxContains", "schema": { diff --git a/tests/draft-next/maxItems.json b/tests/draft-next/maxItems.json index 3b53a6b37..f0c36ab28 100644 --- a/tests/draft-next/maxItems.json +++ b/tests/draft-next/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft-next/maxLength.json b/tests/draft-next/maxLength.json index 811d35b25..748b4daaf 100644 --- a/tests/draft-next/maxLength.json +++ b/tests/draft-next/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft-next/maxProperties.json b/tests/draft-next/maxProperties.json index aa7209f53..acec14209 100644 --- a/tests/draft-next/maxProperties.json +++ b/tests/draft-next/maxProperties.json @@ -35,6 +35,22 @@ } ] }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, diff --git a/tests/draft-next/minContains.json b/tests/draft-next/minContains.json index 287cfcaef..b83d1bddf 100644 --- a/tests/draft-next/minContains.json +++ b/tests/draft-next/minContains.json @@ -90,6 +90,25 @@ } ] }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, { "description": "maxContains = minContains", "schema": { diff --git a/tests/draft-next/minItems.json b/tests/draft-next/minItems.json index ed5118815..d3b18720d 100644 --- a/tests/draft-next/minItems.json +++ b/tests/draft-next/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft-next/minLength.json b/tests/draft-next/minLength.json index 3f09158de..64db94805 100644 --- a/tests/draft-next/minLength.json +++ b/tests/draft-next/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft-next/minProperties.json b/tests/draft-next/minProperties.json index 49a0726e0..9f74f7891 100644 --- a/tests/draft-next/minProperties.json +++ b/tests/draft-next/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft-next/optional/dependencies-compatibility.json b/tests/draft-next/optional/dependencies-compatibility.json new file mode 100644 index 000000000..6eafaf052 --- /dev/null +++ b/tests/draft-next/optional/dependencies-compatibility.json @@ -0,0 +1,269 @@ +[ + { + "description": "single dependency", + "schema": {"dependencies": {"bar": ["foo"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": {"dependencies": {"bar": []}}, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": {"dependencies": {"quux": ["foo", "bar"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json index bc87c9e41..421b5f85a 100644 --- a/tests/draft-next/ref.json +++ b/tests/draft-next/ref.json @@ -577,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft-next/refRemote.json b/tests/draft-next/refRemote.json index f12286448..0a5e48499 100644 --- a/tests/draft-next/refRemote.json +++ b/tests/draft-next/refRemote.json @@ -190,7 +190,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/$defs/refToInteger" }, "tests": [ { diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index 416c22496..4e8987e03 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json index e225aad55..0d825ea49 100644 --- a/tests/draft2019-09/id.json +++ b/tests/draft2019-09/id.json @@ -1,7 +1,9 @@ [ { "description": "Invalid use of fragments in location-independent $id", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "Identifier name", @@ -252,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maxContains.json b/tests/draft2019-09/maxContains.json index 3c42fb31b..61c967de2 100644 --- a/tests/draft2019-09/maxContains.json +++ b/tests/draft2019-09/maxContains.json @@ -51,6 +51,25 @@ } ] }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, { "description": "minContains < maxContains", "schema": { diff --git a/tests/draft2019-09/maxItems.json b/tests/draft2019-09/maxItems.json index 3b53a6b37..f0c36ab28 100644 --- a/tests/draft2019-09/maxItems.json +++ b/tests/draft2019-09/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maxLength.json b/tests/draft2019-09/maxLength.json index 811d35b25..748b4daaf 100644 --- a/tests/draft2019-09/maxLength.json +++ b/tests/draft2019-09/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maxProperties.json b/tests/draft2019-09/maxProperties.json index aa7209f53..acec14209 100644 --- a/tests/draft2019-09/maxProperties.json +++ b/tests/draft2019-09/maxProperties.json @@ -35,6 +35,22 @@ } ] }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, diff --git a/tests/draft2019-09/minContains.json b/tests/draft2019-09/minContains.json index 163247f9b..1d3b5a5cb 100644 --- a/tests/draft2019-09/minContains.json +++ b/tests/draft2019-09/minContains.json @@ -90,6 +90,25 @@ } ] }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, { "description": "maxContains = minContains", "schema": { diff --git a/tests/draft2019-09/minItems.json b/tests/draft2019-09/minItems.json index ed5118815..d3b18720d 100644 --- a/tests/draft2019-09/minItems.json +++ b/tests/draft2019-09/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minLength.json b/tests/draft2019-09/minLength.json index 3f09158de..64db94805 100644 --- a/tests/draft2019-09/minLength.json +++ b/tests/draft2019-09/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minProperties.json b/tests/draft2019-09/minProperties.json index 49a0726e0..9f74f7891 100644 --- a/tests/draft2019-09/minProperties.json +++ b/tests/draft2019-09/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/optional/dependencies-compatibility.json b/tests/draft2019-09/optional/dependencies-compatibility.json new file mode 100644 index 000000000..6eafaf052 --- /dev/null +++ b/tests/draft2019-09/optional/dependencies-compatibility.json @@ -0,0 +1,269 @@ +[ + { + "description": "single dependency", + "schema": {"dependencies": {"bar": ["foo"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": {"dependencies": {"bar": []}}, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": {"dependencies": {"quux": ["foo", "bar"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index fd8a3b21c..55a447c43 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -177,7 +177,9 @@ }, { "description": "remote ref, containing refs itself", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "remote ref valid", @@ -298,7 +300,7 @@ "tests": [ { "description": "valid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -327,7 +329,7 @@ }, { "description": "invalid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -575,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index f12286448..0a5e48499 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -190,7 +190,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/$defs/refToInteger" }, "tests": [ { diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 416c22496..4e8987e03 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -169,5 +169,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$anchor": "not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/id.json b/tests/draft2020-12/id.json index 14a0e9c7d..37fb42978 100644 --- a/tests/draft2020-12/id.json +++ b/tests/draft2020-12/id.json @@ -254,5 +254,36 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/maxContains.json b/tests/draft2020-12/maxContains.json index 3c42fb31b..61c967de2 100644 --- a/tests/draft2020-12/maxContains.json +++ b/tests/draft2020-12/maxContains.json @@ -51,6 +51,25 @@ } ] }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, { "description": "minContains < maxContains", "schema": { diff --git a/tests/draft2020-12/maxItems.json b/tests/draft2020-12/maxItems.json index 3b53a6b37..f0c36ab28 100644 --- a/tests/draft2020-12/maxItems.json +++ b/tests/draft2020-12/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/maxLength.json b/tests/draft2020-12/maxLength.json index 811d35b25..748b4daaf 100644 --- a/tests/draft2020-12/maxLength.json +++ b/tests/draft2020-12/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/maxProperties.json b/tests/draft2020-12/maxProperties.json index aa7209f53..acec14209 100644 --- a/tests/draft2020-12/maxProperties.json +++ b/tests/draft2020-12/maxProperties.json @@ -35,6 +35,22 @@ } ] }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, diff --git a/tests/draft2020-12/minContains.json b/tests/draft2020-12/minContains.json index baf5b1ecf..851e262da 100644 --- a/tests/draft2020-12/minContains.json +++ b/tests/draft2020-12/minContains.json @@ -90,6 +90,25 @@ } ] }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, { "description": "maxContains = minContains", "schema": { diff --git a/tests/draft2020-12/minItems.json b/tests/draft2020-12/minItems.json index ed5118815..d3b18720d 100644 --- a/tests/draft2020-12/minItems.json +++ b/tests/draft2020-12/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/minLength.json b/tests/draft2020-12/minLength.json index 3f09158de..64db94805 100644 --- a/tests/draft2020-12/minLength.json +++ b/tests/draft2020-12/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/minProperties.json b/tests/draft2020-12/minProperties.json index 49a0726e0..9f74f7891 100644 --- a/tests/draft2020-12/minProperties.json +++ b/tests/draft2020-12/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/optional/dependencies-compatibility.json b/tests/draft2020-12/optional/dependencies-compatibility.json new file mode 100644 index 000000000..6eafaf052 --- /dev/null +++ b/tests/draft2020-12/optional/dependencies-compatibility.json @@ -0,0 +1,269 @@ +[ + { + "description": "single dependency", + "schema": {"dependencies": {"bar": ["foo"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": {"dependencies": {"bar": []}}, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": {"dependencies": {"quux": ["foo", "bar"]}}, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/ref.json b/tests/draft2020-12/ref.json index 8a65e51e3..122ff750c 100644 --- a/tests/draft2020-12/ref.json +++ b/tests/draft2020-12/ref.json @@ -577,5 +577,70 @@ "valid": false } ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id1-int.json", + "$id": "/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint", + "$id": "/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/refRemote.json b/tests/draft2020-12/refRemote.json index f12286448..0a5e48499 100644 --- a/tests/draft2020-12/refRemote.json +++ b/tests/draft2020-12/refRemote.json @@ -190,7 +190,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifier.json#/$defs/refToInteger" }, "tests": [ { diff --git a/tests/draft6/id.json b/tests/draft6/id.json index b58e0d007..b03248b24 100644 --- a/tests/draft6/id.json +++ b/tests/draft6/id.json @@ -48,6 +48,67 @@ "valid": false } ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } - ] diff --git a/tests/draft6/maxItems.json b/tests/draft6/maxItems.json index 3b53a6b37..f0c36ab28 100644 --- a/tests/draft6/maxItems.json +++ b/tests/draft6/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft6/maxLength.json b/tests/draft6/maxLength.json index 811d35b25..748b4daaf 100644 --- a/tests/draft6/maxLength.json +++ b/tests/draft6/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft6/maxProperties.json b/tests/draft6/maxProperties.json index aa7209f53..acec14209 100644 --- a/tests/draft6/maxProperties.json +++ b/tests/draft6/maxProperties.json @@ -35,6 +35,22 @@ } ] }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, diff --git a/tests/draft6/minItems.json b/tests/draft6/minItems.json index ed5118815..d3b18720d 100644 --- a/tests/draft6/minItems.json +++ b/tests/draft6/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft6/minLength.json b/tests/draft6/minLength.json index 3f09158de..64db94805 100644 --- a/tests/draft6/minLength.json +++ b/tests/draft6/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft6/minProperties.json b/tests/draft6/minProperties.json index 49a0726e0..9f74f7891 100644 --- a/tests/draft6/minProperties.json +++ b/tests/draft6/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft7/id.json b/tests/draft7/id.json index b58e0d007..b03248b24 100644 --- a/tests/draft7/id.json +++ b/tests/draft7/id.json @@ -48,6 +48,67 @@ "valid": false } ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "$defs": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$defs": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/$defs/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] } - ] diff --git a/tests/draft7/maxItems.json b/tests/draft7/maxItems.json index 3b53a6b37..f0c36ab28 100644 --- a/tests/draft7/maxItems.json +++ b/tests/draft7/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft7/maxLength.json b/tests/draft7/maxLength.json index 811d35b25..748b4daaf 100644 --- a/tests/draft7/maxLength.json +++ b/tests/draft7/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft7/maxProperties.json b/tests/draft7/maxProperties.json index aa7209f53..acec14209 100644 --- a/tests/draft7/maxProperties.json +++ b/tests/draft7/maxProperties.json @@ -35,6 +35,22 @@ } ] }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, diff --git a/tests/draft7/minItems.json b/tests/draft7/minItems.json index ed5118815..d3b18720d 100644 --- a/tests/draft7/minItems.json +++ b/tests/draft7/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft7/minLength.json b/tests/draft7/minLength.json index 3f09158de..64db94805 100644 --- a/tests/draft7/minLength.json +++ b/tests/draft7/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft7/minProperties.json b/tests/draft7/minProperties.json index 49a0726e0..9f74f7891 100644 --- a/tests/draft7/minProperties.json +++ b/tests/draft7/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ]