From 20f025d740bf69b7d119fa04674e15f377acc6d5 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 12:01:10 +0200 Subject: [PATCH 1/9] Add helper function --- jsonschema/_utils.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 54d28c041..94830efbe 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -270,6 +270,10 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema): return [] evaluated_keys = [] + def is_valid(errs_it): + """Whether there are no errors in the given iterator.""" + return next(errs_it, None) is None + ref = schema.get("$ref") if ref is not None: resolved = validator._resolver.lookup(ref) @@ -326,13 +330,12 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema): ) for keyword in ["allOf", "oneOf", "anyOf"]: - if keyword in schema: - for subschema in schema[keyword]: - errs = next(validator.descend(instance, subschema), None) - if errs is None: - evaluated_keys += find_evaluated_property_keys_by_schema( - validator, instance, subschema, - ) + for subschema in schema.get(keyword, []): + if not is_valid(validator.descend(instance, subschema)): + continue + evaluated_keys += find_evaluated_property_keys_by_schema( + validator, instance, subschema, + ) if "if" in schema: if validator.evolve(schema=schema["if"]).is_valid(instance): From 75218a4c4632ecafa722724fd338dc3598625764 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 12:01:10 +0200 Subject: [PATCH 2/9] Add test for unevaluatedProperties --- jsonschema/tests/test_validators.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 28cc40273..309229ee6 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -742,6 +742,14 @@ def test_unevaluated_properties_on_invalid_type(self): message = self.message_for(instance="foo", schema=schema) self.assertEqual(message, "'foo' is not of type 'object'") + def test_unevaluated_properties_with_additional_properties(self): + schema = { + "additionalProperties": {"type": "string"}, + "unevaluatedProperties": False, + } + validator = validators._LATEST_VERSION(schema) + validator.validate(instance={"foo": "foo"}) + def test_single_item(self): schema = {"prefixItems": [{}], "items": False} message = self.message_for( From fb57921bcc37ce969550452e1b30351c476e24e5 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 12:01:10 +0200 Subject: [PATCH 3/9] Fix calculation of evaluated properties --- jsonschema/_utils.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 94830efbe..61defd303 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -302,18 +302,18 @@ def is_valid(errs_it): ), ) - for keyword in [ - "properties", "additionalProperties", "unevaluatedProperties", - ]: - if keyword in schema: - schema_value = schema[keyword] - if validator.is_type(schema_value, "boolean") and schema_value: - evaluated_keys += instance.keys() - - elif validator.is_type(schema_value, "object"): - for property in schema_value: - if property in instance: - evaluated_keys.append(property) + properties = schema.get("properties") + if validator.is_type(properties, "object"): + evaluated_keys += properties.keys() & instance.keys() + + for keyword in ["additionalProperties", "unevaluatedProperties"]: + if (subschema := schema.get(keyword)) is None: + continue + evaluated_keys += ( + key + for key, value in instance.items() + if is_valid(validator.descend(value, subschema)) + ) if "patternProperties" in schema: for property in instance: From ef71f1be9b59cc7d6e799acdc0598d45c4f1c144 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 12:01:54 +0200 Subject: [PATCH 4/9] Squashed 'json/' changes from 83e866b4..ab3924a6 REVERT: 83e866b4 Merge pull request #763 from michaelmior/propertynames-const REVERT: c5a9703f Merge pull request #760 from OptimumCode/rfc3490-label-separator REVERT: b4c09b65 Add tests for propertyNames with const/enum REVERT: 4fa572d8 Move tests for rfc3490#3.1 into a separate test case REVERT: ce9f68ca Add link to rfc and quote REVERT: ad94cacc Add test cases for other valid label separators in IDN hostnames REVERT: 39002ae7 Merge pull request #762 from OptimumCode/rfc-html-link REVERT: c8780535 Correct section anchor for rfc URL template REVERT: 5f2ca7d6 Modify rfc url template to use html version REVERT: 9c5d99b6 Merge pull request #761 from OptimumCode/annotation-script-rfc-support REVERT: 9563ce7b Correct rfc URL template - incorrect path pattern was used REVERT: 961bfad0 Correct spec kind extraction from defined key. Continue on unkown URL kind REVERT: e524505b Merge pull request #759 from sirosen/hostname-format-reject-single-dot REVERT: 4a3efd18 Add negative tests for "." for hostname formats REVERT: 4ba013d5 Merge pull request #747 from santhosh-tekuri/duration REVERT: aa500e80 Merge pull request #749 from json-schema-org/gregsdennis/json-everything-update REVERT: eb8ce976 Merge pull request #757 from ajevans99/main REVERT: dcdae5c0 Merge pull request #758 from sirosen/hostname-format-check-empty-string REVERT: db21d21b Merge branch 'main' into hostname-format-check-empty-string REVERT: 3fd78f04 Merge pull request #1 from ajevans99/swift-json-schema REVERT: 3cada3a9 Update README.md REVERT: 82a07749 Merge pull request #753 from json-schema-org/ether/fix-draft-locations REVERT: a66d23d4 move draft-specific files to the dedicated dir for its draft REVERT: 8ef15501 Merge pull request #751 from big-andy-coates/format_tests_under_format REVERT: fe1b1392 All format test cases should be under the `format` directory. REVERT: b1ee90f6 json-everything moved to an org REVERT: c00a3f94 test: duration format must start with P REVERT: 9fc880bf Merge pull request #740 from notEthan/format-pattern-control-char REVERT: cbd48ea5 Simplify test of \a regex character to test directly against `pattern` schema REVERT: d6f1010a Merge pull request #746 from json-schema-org/annotations REVERT: 4aec22c1 Revert the changes to additionalProperties.json. REVERT: 2dc10671 Move the workflow step title. REVERT: d9ce71ac May as well also show quotes in the annotation. REVERT: 1b719a84 Pick the line after the description when attaching spec annotations. REVERT: 08105151 Markdown is apparently not (yet?) supported in annotations. REVERT: 81645773 Tidy up the specification annotator a bit. REVERT: 38628b79 Make the spec URLs structure a bit easier for internal use. REVERT: 4ebbeaf4 Merge branch 'Era-cell/main' REVERT: e4bd7554 dumbness2 corrected REVERT: d8ade402 inside run REVERT: 57c7c869 changed install location REVERT: 11f8e511 Added installing command in workflow REVERT: f2766616 template library, url loads changes REVERT: c2badb12 Merge pull request #734 from OptimumCode/idn-hostname-arabic-indic-mixed REVERT: dd9599a5 Merge branch 'main' of github.com:json-schema-org/JSON-Schema-Test-Suite REVERT: 5b393436 add pr dependencies action REVERT: 3a509007 Clear existin annotations on same PR REVERT: 23674123 Cases for rfc and iso written separately REVERT: 0b780b2c Corected yaml format REVERT: 2b1ffb74 Best practices followed with optimized code REVERT: e88a2da6 Works for all OS REVERT: 7b40efe4 Base path for neighbouring file? REVERT: 564e6957 Walking through all leaf files REVERT: 7b84fb44 Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite REVERT: 891d0265 First workflow2 REVERT: 1c175195 regex correction REVERT: 96f7683a Final correction2 - file names beautufied REVERT: 5f050a07 Final correction1 REVERT: 77527b63 Stupidity corrected REVERT: eb8fd760 Branch name specified REVERT: 540a269b Log2 REVERT: f29d090a Wrong location sepcification REVERT: 582e12be logging logs check REVERT: df3bdecc path corrected REVERT: c6b937ca Reading all jsons and spec urls added REVERT: cbdd1755 change day2 REVERT: 54f3784a Merge pull request #731 from MeastroZI/main REVERT: 79dc92f1 TOKEN REVERT: ce52852d Python file location changed REVERT: 3558c2c6 Fake add to tests REVERT: eecc7b7a Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite REVERT: 810d148a First workflow2 REVERT: 4eac02c7 First workflow REVERT: ff29264c Merge pull request #741 from harrel56/chore/tabs-to-spaces REVERT: 9f39cf73 use spaces instead of tabs REVERT: 2f3b5f7a Corrected replaced unevaluated with additoinalProperties REVERT: 40bcb8b3 Corrected replaced unevaluated with additoinalProperties REVERT: fa9224d7 Merge pull request #732 from MeastroZI/main2 REVERT: 83bedd5c Changing descriptions REVERT: 49f73429 fixing tests REVERT: e6d6a081 adding more test cases REVERT: 7e6c9be6 changing descriptions REVERT: 959aca92 shifting test REVERT: 605d7d78 Update propertyDependencies.json : test must be tests REVERT: deb82824 test for dependentSchema and propertyDependencies with unevaluatedProperties and additionalProperties REVERT: ea485124 Merge branch 'json-schema-org:main' into main REVERT: 64a3e7b3 Merge pull request #721 from json-schema-org/gregsdennis/dynamicref-skips-resources REVERT: b9f14e64 Fix $schema in new new test REVERT: 3d5048e8 Merge pull request #733 from Era-cell/main REVERT: 4ae14268 Add valid first character to avoid Bidi rule violation REVERT: 2480edba Update additionalProperties.json formatting it REVERT: 6aa79c0b Update additionalProperties.json formatting it REVERT: 3e0139a5 Update tests/draft-next/additionalProperties.json REVERT: 616240b0 Update tests/draft-next/additionalProperties.json REVERT: c5f3e4ea Update tests/draft2020-12/propertyNames.json REVERT: 964efb8e propertyNames doesn't affect additionalProperties, tests exist already for unevaluatedProps REVERT: f08b884c Cases go under additional and unevaluated Properties REVERT: 99864ff6 added tests for propertyNames with additionalProperties/unevaluatedProperties, also with specification property REVERT: 3b5782b6 Update ref.json : changing $Ids REVERT: 546b3561 test for $ref with $recursiveAnchor REVERT: 57617f25 Merge pull request #726 from Era-cell/main REVERT: 51fc69cd meta data and property names constraints added, additional Items: string REVERT: 9b169bed specification takes array of objects having section and quote REVERT: 1362a8cc Pattern for para corrected REVERT: 340116ec Schema of specification in much structured REVERT: 003ac021 Test-schema including sub-schema for scpecification REVERT: 50a20280 adding specification enhancement for additionalProperties REVERT: 604f5f99 Drop tests of `$id` and `$anchor` that just test values against meta-schema `pattern` for those properties REVERT: 9cd64ec9 come on man, save all the files REVERT: f494440e use unique $id in optional tests, too REVERT: 468453b0 use unique $id REVERT: 9ec6d17e fix copy/paste error REVERT: b284f423 add tests for $dynamicRef skipping over resources REVERT: bf0360f4 add $recursiveAnchor to 2019-09 meta-schemas REVERT: 0519d1f0 add $dynamicAnchor to meta-schemas REVERT: b41167c7 Merge pull request #714 from json-schema-org/more-not REVERT: 4221a55a Add tests for not: {} schemas for all values. REVERT: c499d1d2 Merge pull request #713 from spacether/patch-1 REVERT: 24a471bd Update README.md REVERT: 544f7c3d Merge pull request #712 from otto-ifak/main REVERT: 9dad3ebe Add tests for enum with array of bool REVERT: 589a0858 Merge pull request #706 from marksparkza/unevaluated-before-ref REVERT: 64d5cab9 Merge pull request #710 from spacether/patch-1 REVERT: 418cdbd6 Removes idea folder REVERT: e0a9e066 Updates all other tests to mention grapheme/graphemes REVERT: 217bf81b Merge pull request #701 from json-schema-org/ether/dynamicRef-boolean REVERT: 7a3d06d7 I remove a test that doesn't make sense. REVERT: e8bf453d Move tests with ids in non-schemas to optional REVERT: 69136952 Update minLength.json REVERT: d545be21 Fix duplidate identifiers in recently added tests REVERT: 4e9640c8 test when $dynamicRef references a boolean schema REVERT: 3dab98ca Merge pull request #705 from json-schema-org/gregsdennis/remove-contains-objects-tests REVERT: 1d3aa495 remove more maxContains REVERT: 4a2c61e8 Test unevaluatedItems|Properties before $ref REVERT: ec553d76 contains no longer applies to objects REVERT: 0433a2bf Merge pull request #704 from big-andy-coates/clarify-format-requirements REVERT: c685195f Merge pull request #703 from big-andy-coates/link-to-creek-validator-comprison-site REVERT: a46174b0 Add more detail around test runner requirements for `format` tests REVERT: bb1de8a9 The site linked to is a data-driven functional and performance benchmark of JVM based validator implementations. REVERT: d38ddd54 Merge pull request #696 from jdesrosiers/unevaluated-dynamicref REVERT: 5d0c05fa Fix copy/paste error REVERT: 95fe6ca2 Merge pull request #694 from json-schema-org/heterogeneous-additionalItems REVERT: 9c88a0be Merge pull request #697 from json-schema-org/gregsdennis/add-ref-into-known-nonapplicator REVERT: 49222046 Add unevaluted with dynamic ref tests to draft-next REVERT: 8ba1c90d Update unevaluted with dynamic ref to be more likely to catch errors REVERT: fea2cf19 add tests for 2019 and 2020 REVERT: 6695ca38 add optional tests for `$ref`ing into known non-applicator keywords REVERT: 2834c630 Add tests for unevaluated with dynamic reference REVERT: cda4281c Merge pull request #695 from json-schema-org/ether/clean-up-subSchemas REVERT: 7b9f45c2 move subSchemas-defs.json to subSchemas.json REVERT: e41ec0ec remove unused definition files REVERT: 349c5a82 Merge pull request #692 from json-schema-org/ether/fix-subSchemas-refs REVERT: 451baca4 Merge pull request #670 from marksparkza/invalid-output-test REVERT: b8da838a Add tests for heterogeneous arrays with additionalItems REVERT: 6d7a44b7 fix subschema locations and their $refs REVERT: a9a1e2e3 Merge pull request #690 from skryukov/add-ipv4-mask-test REVERT: ba52c48a Merge pull request #689 from skryukov/add-schema-keyword-to-required-tests REVERT: 69b53add Add a test case for ipv4 with netmask REVERT: d0c602a7 Add $schema keyword to required tests REVERT: 20f1f52c Merge pull request #688 from spacether/feat_updates_python_exp_impl REVERT: b087b3ca Updates implmentation REVERT: 4ecd01f3 Merge pull request #687 from swaeberle/check-single-label-idn-hostnames REVERT: 732e7275 test single label IDN hostnames REVERT: 202d5625 test: hostname format check fails on empty string REVERT: ea0b63c9 Remove invalid output tests git-subtree-dir: json git-subtree-split: ab3924a663d2f9e6de844f464d185a70d881b9ed --- .github/workflows/pr-dependencies.yml | 12 - .../show_specification_annotations.yml | 21 -- README.md | 16 +- bin/annotate-specification-links | 140 --------- bin/specification_urls.json | 34 -- output-tests/draft2019-09/content/type.json | 26 ++ output-tests/draft2020-12/content/type.json | 26 ++ .../draft-next/format-assertion-false.json | 1 - remotes/draft-next/format-assertion-true.json | 1 - .../draft-next/metaschema-no-validation.json | 1 - .../metaschema-optional-vocabulary.json | 1 - remotes/draft-next/subSchemas-defs.json | 11 + remotes/draft-next/subSchemas.json | 12 +- .../metaschema-no-validation.json | 1 - .../metaschema-optional-vocabulary.json | 1 - remotes/draft2019-09/subSchemas-defs.json | 11 + remotes/draft2019-09/subSchemas.json | 12 +- .../draft2020-12/format-assertion-false.json | 1 - .../draft2020-12/format-assertion-true.json | 1 - .../metaschema-no-validation.json | 1 - .../metaschema-optional-vocabulary.json | 1 - remotes/draft2020-12/subSchemas-defs.json | 11 + remotes/draft2020-12/subSchemas.json | 12 +- remotes/draft4/subSchemas.json | 10 - remotes/draft6/name.json | 15 - remotes/draft6/ref-and-definitions.json | 11 - remotes/draft6/subSchemas.json | 10 - .../draft7/locationIndependentIdentifier.json | 11 - remotes/draft7/name.json | 15 - remotes/draft7/subSchemas.json | 10 - ... locationIndependentIdentifierDraft4.json} | 0 ...locationIndependentIdentifierPre2019.json} | 0 remotes/{draft4 => }/name.json | 0 remotes/{draft7 => }/ref-and-definitions.json | 2 +- .../subSchemas.json => subSchemas-defs.json} | 4 +- remotes/subSchemas.json | 8 + test-schema.json | 63 ---- tests/draft-next/additionalProperties.json | 92 ------ tests/draft-next/anchor.json | 114 +++++++ tests/draft-next/contains.json | 104 ++++++- tests/draft-next/dependentSchemas.json | 1 - tests/draft-next/dynamicRef.json | 85 ----- tests/draft-next/enum.json | 96 ------ tests/draft-next/id.json | 294 ++++++++++++++++++ tests/draft-next/items.json | 20 -- tests/draft-next/maxContains.json | 50 +++ tests/draft-next/maxLength.json | 2 +- tests/draft-next/minLength.json | 2 +- tests/draft-next/oneOf.json | 2 +- tests/draft-next/optional/anchor.json | 60 ---- tests/draft-next/optional/dynamicRef.json | 56 ---- .../draft-next/optional/ecmascript-regex.json | 14 + .../draft-next/optional/format/duration.json | 5 - .../optional/format/ecmascript-regex.json | 16 - .../draft-next/optional/format/hostname.json | 10 - .../optional/format/idn-hostname.json | 84 +---- tests/draft-next/optional/format/ipv4.json | 5 - tests/draft-next/optional/id.json | 53 ---- .../optional/refOfUnknownKeyword.json | 23 -- tests/draft-next/ref.json | 8 - tests/draft-next/refRemote.json | 20 +- tests/draft-next/unevaluatedItems.json | 73 ----- tests/draft-next/unevaluatedProperties.json | 206 +++--------- .../{optional => }/unknownKeyword.json | 0 tests/draft2019-09/additionalItems.json | 20 -- tests/draft2019-09/additionalProperties.json | 57 ---- tests/draft2019-09/anchor.json | 115 +++++++ tests/draft2019-09/dependentSchemas.json | 1 - tests/draft2019-09/enum.json | 96 ------ tests/draft2019-09/id.json | 294 ++++++++++++++++++ tests/draft2019-09/maxLength.json | 2 +- tests/draft2019-09/minLength.json | 2 +- tests/draft2019-09/not.json | 154 +-------- tests/draft2019-09/oneOf.json | 2 +- tests/draft2019-09/optional/anchor.json | 60 ---- .../optional/format/duration.json | 5 - .../optional/format/hostname.json | 10 - .../optional/format/idn-hostname.json | 84 +---- tests/draft2019-09/optional/format/ipv4.json | 5 - tests/draft2019-09/optional/id.json | 53 ---- .../optional/refOfUnknownKeyword.json | 23 -- tests/draft2019-09/propertyNames.json | 53 ---- tests/draft2019-09/ref.json | 63 +--- tests/draft2019-09/refRemote.json | 20 +- tests/draft2019-09/unevaluatedItems.json | 76 ----- tests/draft2019-09/unevaluatedProperties.json | 129 -------- .../{optional => }/unknownKeyword.json | 0 tests/draft2020-12/additionalProperties.json | 67 +--- tests/draft2020-12/anchor.json | 115 +++++++ tests/draft2020-12/dependentSchemas.json | 1 - tests/draft2020-12/dynamicRef.json | 85 ----- tests/draft2020-12/enum.json | 96 ------ tests/draft2020-12/id.json | 294 ++++++++++++++++++ tests/draft2020-12/items.json | 20 -- tests/draft2020-12/maxLength.json | 2 +- tests/draft2020-12/minLength.json | 2 +- tests/draft2020-12/not.json | 154 +-------- tests/draft2020-12/oneOf.json | 2 +- tests/draft2020-12/optional/anchor.json | 60 ---- tests/draft2020-12/optional/dynamicRef.json | 56 ---- .../optional/ecmascript-regex.json | 14 + .../optional/format/duration.json | 5 - .../optional/format/ecmascript-regex.json | 16 - .../optional/format/hostname.json | 10 - .../optional/format/idn-hostname.json | 84 +---- tests/draft2020-12/optional/format/ipv4.json | 5 - tests/draft2020-12/optional/id.json | 53 ---- .../optional/refOfUnknownKeyword.json | 23 -- tests/draft2020-12/propertyNames.json | 83 ----- tests/draft2020-12/ref.json | 23 +- tests/draft2020-12/refRemote.json | 20 +- tests/draft2020-12/unevaluatedItems.json | 81 +---- tests/draft2020-12/unevaluatedProperties.json | 126 -------- .../{optional => }/unknownKeyword.json | 0 tests/draft3/additionalItems.json | 19 -- tests/draft3/maxLength.json | 2 +- tests/draft3/minLength.json | 2 +- .../{format => }/ecmascript-regex.json | 0 tests/draft3/optional/format/host-name.json | 5 - tests/draft3/refRemote.json | 4 +- tests/draft4/additionalItems.json | 19 -- tests/draft4/enum.json | 84 ----- tests/draft4/{optional => }/id.json | 0 tests/draft4/maxLength.json | 2 +- tests/draft4/minLength.json | 2 +- tests/draft4/not.json | 63 +--- tests/draft4/oneOf.json | 2 +- tests/draft4/optional/format/hostname.json | 10 - tests/draft4/optional/format/ipv4.json | 5 - tests/draft4/refRemote.json | 8 +- tests/draft6/additionalItems.json | 19 -- tests/draft6/enum.json | 84 ----- tests/draft6/{optional => }/id.json | 0 tests/draft6/maxLength.json | 2 +- tests/draft6/minLength.json | 2 +- tests/draft6/not.json | 152 +-------- tests/draft6/oneOf.json | 2 +- tests/draft6/optional/format/hostname.json | 10 - tests/draft6/optional/format/ipv4.json | 5 - tests/draft6/propertyNames.json | 47 --- tests/draft6/refRemote.json | 10 +- .../draft6/{optional => }/unknownKeyword.json | 0 tests/draft7/additionalItems.json | 19 -- tests/draft7/enum.json | 84 ----- tests/draft7/{optional => }/id.json | 0 tests/draft7/maxLength.json | 2 +- tests/draft7/minLength.json | 2 +- tests/draft7/not.json | 152 +-------- tests/draft7/oneOf.json | 2 +- tests/draft7/optional/format/hostname.json | 10 - .../draft7/optional/format/idn-hostname.json | 76 +---- tests/draft7/optional/format/ipv4.json | 5 - tests/draft7/propertyNames.json | 47 --- tests/draft7/refRemote.json | 10 +- .../draft7/{optional => }/unknownKeyword.json | 0 155 files changed, 1663 insertions(+), 4135 deletions(-) delete mode 100644 .github/workflows/pr-dependencies.yml delete mode 100644 .github/workflows/show_specification_annotations.yml delete mode 100755 bin/annotate-specification-links delete mode 100644 bin/specification_urls.json create mode 100644 remotes/draft-next/subSchemas-defs.json create mode 100644 remotes/draft2019-09/subSchemas-defs.json create mode 100644 remotes/draft2020-12/subSchemas-defs.json delete mode 100644 remotes/draft4/subSchemas.json delete mode 100644 remotes/draft6/name.json delete mode 100644 remotes/draft6/ref-and-definitions.json delete mode 100644 remotes/draft6/subSchemas.json delete mode 100644 remotes/draft7/locationIndependentIdentifier.json delete mode 100644 remotes/draft7/name.json delete mode 100644 remotes/draft7/subSchemas.json rename remotes/{draft4/locationIndependentIdentifier.json => locationIndependentIdentifierDraft4.json} (100%) rename remotes/{draft6/locationIndependentIdentifier.json => locationIndependentIdentifierPre2019.json} (100%) rename remotes/{draft4 => }/name.json (100%) rename remotes/{draft7 => }/ref-and-definitions.json (74%) rename remotes/{draft3/subSchemas.json => subSchemas-defs.json} (62%) create mode 100644 remotes/subSchemas.json create mode 100644 tests/draft-next/id.json delete mode 100644 tests/draft-next/optional/anchor.json delete mode 100644 tests/draft-next/optional/dynamicRef.json delete mode 100644 tests/draft-next/optional/format/ecmascript-regex.json delete mode 100644 tests/draft-next/optional/id.json rename tests/draft-next/{optional => }/unknownKeyword.json (100%) create mode 100644 tests/draft2019-09/id.json delete mode 100644 tests/draft2019-09/optional/anchor.json delete mode 100644 tests/draft2019-09/optional/id.json rename tests/draft2019-09/{optional => }/unknownKeyword.json (100%) create mode 100644 tests/draft2020-12/id.json delete mode 100644 tests/draft2020-12/optional/anchor.json delete mode 100644 tests/draft2020-12/optional/dynamicRef.json delete mode 100644 tests/draft2020-12/optional/format/ecmascript-regex.json delete mode 100644 tests/draft2020-12/optional/id.json rename tests/draft2020-12/{optional => }/unknownKeyword.json (100%) rename tests/draft3/optional/{format => }/ecmascript-regex.json (100%) rename tests/draft4/{optional => }/id.json (100%) rename tests/draft6/{optional => }/id.json (100%) rename tests/draft6/{optional => }/unknownKeyword.json (100%) rename tests/draft7/{optional => }/id.json (100%) rename tests/draft7/{optional => }/unknownKeyword.json (100%) diff --git a/.github/workflows/pr-dependencies.yml b/.github/workflows/pr-dependencies.yml deleted file mode 100644 index 34a231dcb..000000000 --- a/.github/workflows/pr-dependencies.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Check PR Dependencies - -on: pull_request - -jobs: - check_dependencies: - runs-on: ubuntu-latest - name: Check Dependencies - steps: - - uses: gregsdennis/dependencies-action@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml deleted file mode 100644 index f7d7b398b..000000000 --- a/.github/workflows/show_specification_annotations.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Show Specification Annotations - -on: - pull_request: - paths: - - 'tests/**' - -jobs: - annotate: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: Generate Annotations - run: pip install uritemplate && bin/annotate-specification-links diff --git a/README.md b/README.md index 0bcad8e52..cdd5dc8a4 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ To test a specific version: * For 2019-09 and later published drafts, implementations that are able to detect the draft of each schema via `$schema` SHOULD be configured to do so * For draft-07 and earlier, draft-next, and implementations unable to detect via `$schema`, implementations MUST be configured to expect the draft matching the test directory name -* Load any remote references [described below](#additional-assumptions) and configure your implementation to retrieve them via their URIs +* 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: @@ -159,7 +159,7 @@ If your implementation supports multiple versions, run the above procedure for e ``` 2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run. - In particular, when running tests within the `optional/format` subdirectory, test runners should configure implementations to enable format validation, where the implementation supports it. + 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 @@ -254,14 +254,12 @@ This suite is being used by: ### Java -* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) * [json-schema-validator](https://github.com/daveclayton/json-schema-validator) * [everit-org/json-schema](https://github.com/everit-org/json-schema) * [networknt/json-schema-validator](https://github.com/networknt/json-schema-validator) * [Justify](https://github.com/leadpony/justify) * [Snow](https://github.com/ssilverman/snowy-json) * [jsonschemafriend](https://github.com/jimblackler/jsonschemafriend) -* [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) ### JavaScript @@ -281,10 +279,6 @@ This suite is being used by: * [ajv](https://github.com/epoberezkin/ajv) * [djv](https://github.com/korzio/djv) -### Kotlin - -* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) - ### Node.js For node.js developers, the suite is also available as an [npm](https://www.npmjs.com/package/@json-schema-org/tests) package. @@ -293,7 +287,7 @@ Node-specific support is maintained in a [separate repository](https://github.co ### .NET -* [JsonSchema.Net](https://github.com/json-everything/json-everything) +* [JsonSchema.Net](https://github.com/gregsdennis/json-everything) * [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema) ### Perl @@ -319,7 +313,7 @@ Node-specific support is maintained in a [separate repository](https://github.co * [fastjsonschema](https://github.com/seznam/python-fastjsonschema) * [hypothesis-jsonschema](https://github.com/Zac-HD/hypothesis-jsonschema) * [jschon](https://github.com/marksparkza/jschon) -* [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) +* [python-experimental, OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/python-experimental.md) ### Ruby @@ -333,13 +327,11 @@ Node-specific support is maintained in a [separate repository](https://github.co ### Scala -* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) * [typed-json](https://github.com/frawa/typed-json) ### Swift * [JSONSchema](https://github.com/kylef/JSONSchema.swift) -* [swift-json-schema](https://github.com/ajevans99/swift-json-schema) If you use it as well, please fork and send a pull request adding yourself to the list :). diff --git a/bin/annotate-specification-links b/bin/annotate-specification-links deleted file mode 100755 index 963768b43..000000000 --- a/bin/annotate-specification-links +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -""" -Annotate pull requests to the GitHub repository with links to specifications. -""" - -from __future__ import annotations - -from pathlib import Path -from typing import Any -import json -import re -import sys - -from uritemplate import URITemplate - - -BIN_DIR = Path(__file__).parent -TESTS = BIN_DIR.parent / "tests" -URLS = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text()) - - -def urls(version: str) -> dict[str, URITemplate]: - """ - Retrieve the version-specific URLs for specifications. - """ - for_version = {**URLS["json-schema"][version], **URLS["external"]} - return {k: URITemplate(v) for k, v in for_version.items()} - - -def annotation( - path: Path, - message: str, - line: int = 1, - level: str = "notice", - **kwargs: Any, -) -> str: - """ - Format a GitHub annotation. - - See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions - for full syntax. - """ - - if kwargs: - additional = "," + ",".join(f"{k}={v}" for k, v in kwargs.items()) - else: - additional = "" - - relative = path.relative_to(TESTS.parent) - return f"::{level} file={relative},line={line}{additional}::{message}\n" - - -def line_number_of(path: Path, case: dict[str, Any]) -> int: - """ - Crudely find the line number of a test case. - """ - with path.open() as file: - description = case["description"] - return next( - (i + 1 for i, line in enumerate(file, 1) if description in line), - 1, - ) - -def extract_kind_and_spec(key: str) -> (str, str): - """ - Extracts specification number and kind from the defined key - """ - can_have_spec = ["rfc", "iso"] - if not any(key.startswith(el) for el in can_have_spec): - return key, "" - number = re.search(r"\d+", key) - spec = "" if number is None else number.group(0) - kind = key.removesuffix(spec) - return kind, spec - - -def main(): - # Clear annotations which may have been emitted by a previous run. - sys.stdout.write("::remove-matcher owner=me::\n") - - for version in TESTS.iterdir(): - if version.name in {"draft-next", "latest"}: - continue - - version_urls = urls(version.name) - - for path in version.rglob("*.json"): - try: - contents = json.loads(path.read_text()) - except json.JSONDecodeError as error: - error = annotation( - level="error", - path=path, - line=error.lineno, - col=error.pos + 1, - title=str(error), - message=f"cannot load {path}" - ) - sys.stdout.write(error) - continue - - for test_case in contents: - specifications = test_case.get("specification") - if specifications is not None: - for each in specifications: - quote = each.pop("quote", "") - (key, section), = each.items() - - (kind, spec) = extract_kind_and_spec(key) - - url_template = version_urls[kind] - if url_template is None: - error = annotation( - level="error", - path=path, - line=line_number_of(path, test_case), - title=f"unsupported template '{kind}'", - message=f"cannot find a URL template for '{kind}'" - ) - sys.stdout.write(error) - continue - - url = url_template.expand( - spec=spec, - section=section, - ) - - message = f"{url}\n\n{quote}" if quote else url - sys.stdout.write( - annotation( - path=path, - line=line_number_of(path, test_case), - title="Specification Link", - message=message, - ), - ) - - -if __name__ == "__main__": - main() diff --git a/bin/specification_urls.json b/bin/specification_urls.json deleted file mode 100644 index e1824999a..000000000 --- a/bin/specification_urls.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "json-schema": { - "draft2020-12": { - "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}", - "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}" - }, - "draft2019-09": { - "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}", - "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}" - }, - "draft7": { - "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}", - "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}" - }, - "draft6": { - "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}", - "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}" - }, - "draft4": { - "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}", - "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}" - }, - "draft3": { - "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" - } - }, - - "external": { - "ecma262": "https://262.ecma-international.org/{section}", - "perl5": "https://perldoc.perl.org/perlre#{section}", - "rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.html#section-{section}", - "iso": "https://www.iso.org/obp/ui" - } -} diff --git a/output-tests/draft2019-09/content/type.json b/output-tests/draft2019-09/content/type.json index 21118fd5f..cff77a740 100644 --- a/output-tests/draft2019-09/content/type.json +++ b/output-tests/draft2019-09/content/type.json @@ -31,6 +31,32 @@ "required": ["errors"] } } + }, + { + "description": "correct type yields an output unit", + "data": "a string", + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2019-09/type/0/tests/1/basic", + "$ref": "/draft/2019-09/output/schema", + "properties": { + "annotations": { + "contains": { + "properties": { + "valid": {"const": true}, + "keywordLocation": {"const": "/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2019-09/type/0#/type"}, + "instanceLocation": {"const": ""}, + "annotation": false, + "error": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "required": ["annotations"] + } + } } ] } diff --git a/output-tests/draft2020-12/content/type.json b/output-tests/draft2020-12/content/type.json index 2949a6052..710475b2b 100644 --- a/output-tests/draft2020-12/content/type.json +++ b/output-tests/draft2020-12/content/type.json @@ -31,6 +31,32 @@ "required": ["errors"] } } + }, + { + "description": "correct type yields an output unit", + "data": "a string", + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2020-12/type/0/tests/1/basic", + "$ref": "/draft/2020-12/output/schema", + "properties": { + "annotations": { + "contains": { + "properties": { + "valid": {"const": true}, + "keywordLocation": {"const": "/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2020-12/type/0#/type"}, + "instanceLocation": {"const": ""}, + "annotation": false, + "error": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "required": ["annotations"] + } + } } ] } diff --git a/remotes/draft-next/format-assertion-false.json b/remotes/draft-next/format-assertion-false.json index 9cbd2a1de..91c866996 100644 --- a/remotes/draft-next/format-assertion-false.json +++ b/remotes/draft-next/format-assertion-false.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/next/vocab/core": true, "https://json-schema.org/draft/next/vocab/format-assertion": false }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/core" }, { "$ref": "https://json-schema.org/draft/next/meta/format-assertion" } diff --git a/remotes/draft-next/format-assertion-true.json b/remotes/draft-next/format-assertion-true.json index b3ff69f3a..a33d1435f 100644 --- a/remotes/draft-next/format-assertion-true.json +++ b/remotes/draft-next/format-assertion-true.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/next/vocab/core": true, "https://json-schema.org/draft/next/vocab/format-assertion": true }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/core" }, { "$ref": "https://json-schema.org/draft/next/meta/format-assertion" } diff --git a/remotes/draft-next/metaschema-no-validation.json b/remotes/draft-next/metaschema-no-validation.json index 90e32a672..c19c9e8a7 100644 --- a/remotes/draft-next/metaschema-no-validation.json +++ b/remotes/draft-next/metaschema-no-validation.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/next/vocab/applicator": true, "https://json-schema.org/draft/next/vocab/core": true }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/applicator" }, { "$ref": "https://json-schema.org/draft/next/meta/core" } diff --git a/remotes/draft-next/metaschema-optional-vocabulary.json b/remotes/draft-next/metaschema-optional-vocabulary.json index 1af0cad4c..e78e531d4 100644 --- a/remotes/draft-next/metaschema-optional-vocabulary.json +++ b/remotes/draft-next/metaschema-optional-vocabulary.json @@ -6,7 +6,6 @@ "https://json-schema.org/draft/next/vocab/core": true, "http://localhost:1234/draft/next/vocab/custom": false }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/validation" }, { "$ref": "https://json-schema.org/draft/next/meta/core" } diff --git a/remotes/draft-next/subSchemas-defs.json b/remotes/draft-next/subSchemas-defs.json new file mode 100644 index 000000000..75b7583ca --- /dev/null +++ b/remotes/draft-next/subSchemas-defs.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } + } +} diff --git a/remotes/draft-next/subSchemas.json b/remotes/draft-next/subSchemas.json index 75b7583ca..575dd00c2 100644 --- a/remotes/draft-next/subSchemas.json +++ b/remotes/draft-next/subSchemas.json @@ -1,11 +1,9 @@ { "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" } } diff --git a/remotes/draft2019-09/metaschema-no-validation.json b/remotes/draft2019-09/metaschema-no-validation.json index 859006c27..494f0abff 100644 --- a/remotes/draft2019-09/metaschema-no-validation.json +++ b/remotes/draft2019-09/metaschema-no-validation.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/2019-09/vocab/applicator": true, "https://json-schema.org/draft/2019-09/vocab/core": true }, - "$recursiveAnchor": true, "allOf": [ { "$ref": "https://json-schema.org/draft/2019-09/meta/applicator" }, { "$ref": "https://json-schema.org/draft/2019-09/meta/core" } diff --git a/remotes/draft2019-09/metaschema-optional-vocabulary.json b/remotes/draft2019-09/metaschema-optional-vocabulary.json index 3a7502a21..968597c45 100644 --- a/remotes/draft2019-09/metaschema-optional-vocabulary.json +++ b/remotes/draft2019-09/metaschema-optional-vocabulary.json @@ -6,7 +6,6 @@ "https://json-schema.org/draft/2019-09/vocab/core": true, "http://localhost:1234/draft/2019-09/vocab/custom": false }, - "$recursiveAnchor": true, "allOf": [ { "$ref": "https://json-schema.org/draft/2019-09/meta/validation" }, { "$ref": "https://json-schema.org/draft/2019-09/meta/core" } diff --git a/remotes/draft2019-09/subSchemas-defs.json b/remotes/draft2019-09/subSchemas-defs.json new file mode 100644 index 000000000..fdfee68d9 --- /dev/null +++ b/remotes/draft2019-09/subSchemas-defs.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } + } +} diff --git a/remotes/draft2019-09/subSchemas.json b/remotes/draft2019-09/subSchemas.json index fdfee68d9..6dea22525 100644 --- a/remotes/draft2019-09/subSchemas.json +++ b/remotes/draft2019-09/subSchemas.json @@ -1,11 +1,9 @@ { "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" } } diff --git a/remotes/draft2020-12/format-assertion-false.json b/remotes/draft2020-12/format-assertion-false.json index 43a711c9d..d6dd645b6 100644 --- a/remotes/draft2020-12/format-assertion-false.json +++ b/remotes/draft2020-12/format-assertion-false.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/format-assertion": false }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/core" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" } diff --git a/remotes/draft2020-12/format-assertion-true.json b/remotes/draft2020-12/format-assertion-true.json index 39c6b0abf..bb16d5864 100644 --- a/remotes/draft2020-12/format-assertion-true.json +++ b/remotes/draft2020-12/format-assertion-true.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/format-assertion": true }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/core" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" } diff --git a/remotes/draft2020-12/metaschema-no-validation.json b/remotes/draft2020-12/metaschema-no-validation.json index 71be8b5da..85d74b213 100644 --- a/remotes/draft2020-12/metaschema-no-validation.json +++ b/remotes/draft2020-12/metaschema-no-validation.json @@ -5,7 +5,6 @@ "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/core": true }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/applicator" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/core" } diff --git a/remotes/draft2020-12/metaschema-optional-vocabulary.json b/remotes/draft2020-12/metaschema-optional-vocabulary.json index a6963e548..f38ec281d 100644 --- a/remotes/draft2020-12/metaschema-optional-vocabulary.json +++ b/remotes/draft2020-12/metaschema-optional-vocabulary.json @@ -6,7 +6,6 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "http://localhost:1234/draft/2020-12/vocab/custom": false }, - "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/validation" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/core" } diff --git a/remotes/draft2020-12/subSchemas-defs.json b/remotes/draft2020-12/subSchemas-defs.json new file mode 100644 index 000000000..1bb4846d7 --- /dev/null +++ b/remotes/draft2020-12/subSchemas-defs.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } + } +} diff --git a/remotes/draft2020-12/subSchemas.json b/remotes/draft2020-12/subSchemas.json index 1bb4846d7..5fca21d82 100644 --- a/remotes/draft2020-12/subSchemas.json +++ b/remotes/draft2020-12/subSchemas.json @@ -1,11 +1,9 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" } } diff --git a/remotes/draft4/subSchemas.json b/remotes/draft4/subSchemas.json deleted file mode 100644 index 6e9b3de35..000000000 --- a/remotes/draft4/subSchemas.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "definitions": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/definitions/integer" - } - } -} diff --git a/remotes/draft6/name.json b/remotes/draft6/name.json deleted file mode 100644 index fceacb809..000000000 --- a/remotes/draft6/name.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "definitions": { - "orNull": { - "anyOf": [ - { - "type": "null" - }, - { - "$ref": "#" - } - ] - } - }, - "type": "string" -} diff --git a/remotes/draft6/ref-and-definitions.json b/remotes/draft6/ref-and-definitions.json deleted file mode 100644 index b80deeb7b..000000000 --- a/remotes/draft6/ref-and-definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$id": "http://localhost:1234/draft6/ref-and-definitions.json", - "definitions": { - "inner": { - "properties": { - "bar": { "type": "string" } - } - } - }, - "allOf": [ { "$ref": "#/definitions/inner" } ] -} diff --git a/remotes/draft6/subSchemas.json b/remotes/draft6/subSchemas.json deleted file mode 100644 index 6e9b3de35..000000000 --- a/remotes/draft6/subSchemas.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "definitions": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/definitions/integer" - } - } -} diff --git a/remotes/draft7/locationIndependentIdentifier.json b/remotes/draft7/locationIndependentIdentifier.json deleted file mode 100644 index e72815cd5..000000000 --- a/remotes/draft7/locationIndependentIdentifier.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "definitions": { - "refToInteger": { - "$ref": "#foo" - }, - "A": { - "$id": "#foo", - "type": "integer" - } - } -} diff --git a/remotes/draft7/name.json b/remotes/draft7/name.json deleted file mode 100644 index fceacb809..000000000 --- a/remotes/draft7/name.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "definitions": { - "orNull": { - "anyOf": [ - { - "type": "null" - }, - { - "$ref": "#" - } - ] - } - }, - "type": "string" -} diff --git a/remotes/draft7/subSchemas.json b/remotes/draft7/subSchemas.json deleted file mode 100644 index 6e9b3de35..000000000 --- a/remotes/draft7/subSchemas.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "definitions": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/definitions/integer" - } - } -} diff --git a/remotes/draft4/locationIndependentIdentifier.json b/remotes/locationIndependentIdentifierDraft4.json similarity index 100% rename from remotes/draft4/locationIndependentIdentifier.json rename to remotes/locationIndependentIdentifierDraft4.json diff --git a/remotes/draft6/locationIndependentIdentifier.json b/remotes/locationIndependentIdentifierPre2019.json similarity index 100% rename from remotes/draft6/locationIndependentIdentifier.json rename to remotes/locationIndependentIdentifierPre2019.json diff --git a/remotes/draft4/name.json b/remotes/name.json similarity index 100% rename from remotes/draft4/name.json rename to remotes/name.json diff --git a/remotes/draft7/ref-and-definitions.json b/remotes/ref-and-definitions.json similarity index 74% rename from remotes/draft7/ref-and-definitions.json rename to remotes/ref-and-definitions.json index d5929380c..e0ee802a9 100644 --- a/remotes/draft7/ref-and-definitions.json +++ b/remotes/ref-and-definitions.json @@ -1,5 +1,5 @@ { - "$id": "http://localhost:1234/draft7/ref-and-definitions.json", + "$id": "http://localhost:1234/ref-and-definitions.json", "definitions": { "inner": { "properties": { diff --git a/remotes/draft3/subSchemas.json b/remotes/subSchemas-defs.json similarity index 62% rename from remotes/draft3/subSchemas.json rename to remotes/subSchemas-defs.json index 6e9b3de35..50b7b6dc4 100644 --- a/remotes/draft3/subSchemas.json +++ b/remotes/subSchemas-defs.json @@ -1,10 +1,10 @@ { - "definitions": { + "$defs": { "integer": { "type": "integer" }, "refToInteger": { - "$ref": "#/definitions/integer" + "$ref": "#/$defs/integer" } } } diff --git a/remotes/subSchemas.json b/remotes/subSchemas.json new file mode 100644 index 000000000..9f8030bce --- /dev/null +++ b/remotes/subSchemas.json @@ -0,0 +1,8 @@ +{ + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" + } +} diff --git a/test-schema.json b/test-schema.json index 0087c5e3d..833931620 100644 --- a/test-schema.json +++ b/test-schema.json @@ -27,69 +27,6 @@ "type": "array", "items": { "$ref": "#/$defs/test" }, "minItems": 1 - }, - "specification":{ - "description": "A reference to a specification document which defines the behavior tested by this test case. Typically this should be a JSON Schema specification document, though in cases where the JSON Schema specification points to another RFC it should contain *both* the portion of the JSON Schema specification which indicates what RFC (and section) to follow as *well* as information on where in that specification the behavior is specified.", - - "type": "array", - "minItems": 1, - "uniqueItems": true, - "items":{ - "properties": { - "core": { - "description": "A section in official JSON Schema core drafts", - "url": "https://json-schema.org/specification-links", - "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", - "type":"string" - }, - "validation": { - "description": "A section in official JSON Schema validation drafts", - "url": "https://json-schema.org/specification-links", - "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", - "type":"string" - }, - "ecma262": { - "description": "A section in official ECMA 262 specification for defining regular expressions", - "url": "https://262.ecma-international.org/", - "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", - "type":"string" - }, - "perl5": { - "description": "A section name in Perl documentation for defining regular expressions", - "url": "https://perldoc.perl.org/perlre", - "type":"string" - }, - "quote": { - "description": "Quote describing the test case", - "type":"string" - } - }, - "patternProperties": { - "^rfc\\d+$": { - "description": "A section in official RFC for the given rfc number", - "url": "https://www.rfc-editor.org/", - "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", - "type":"string" - }, - "^iso\\d+$": { - "description": "A section in official ISO for the given iso number", - "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", - "type": "string" - } - }, - "additionalProperties": { "type": "string" }, - "minProperties": 1, - "propertyNames": { - "oneOf": [ - { - "pattern": "^((iso)|(rfc))[0-9]+$" - }, - { - "enum": [ "core", "validation", "ecma262", "perl5", "quote" ] - } - ] - } - } } }, "additionalProperties": false diff --git a/tests/draft-next/additionalProperties.json b/tests/draft-next/additionalProperties.json index 51b0edada..7859fbbf1 100644 --- a/tests/draft-next/additionalProperties.json +++ b/tests/draft-next/additionalProperties.json @@ -152,97 +152,5 @@ "valid": true } ] - }, - { - "description": "additionalProperties with propertyNames", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "propertyNames": { - "maxLength": 5 - }, - "additionalProperties": { - "type": "number" - } - }, - "tests": [ - { - "description": "Valid against both keywords", - "data": { "apple": 4 }, - "valid": true - }, - { - "description": "Valid against propertyNames, but not additionalProperties", - "data": { "fig": 2, "pear": "available" }, - "valid": false - } - ] - }, - { - "description": "propertyDependencies with additionalProperties", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "properties" : {"foo2" : {}}, - "propertyDependencies": { - "foo" : {}, - "foo2": { - "bar": { - "properties": { - "buz": {} - } - } - } - }, - "additionalProperties": false - }, - "tests": [ - { - "description": "additionalProperties doesn't consider propertyDependencies properties" , - "data": {"foo": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see buz even when foo2 is present", - "data": {"foo2": "bar", "buz": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see buz", - "data": {"buz": ""}, - "valid": false - } - ] - }, - { - "description": "dependentSchemas with additionalProperties", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo": {}, - "foo2": { - "properties": { - "bar": {} - } - } - }, - "additionalProperties": false - }, - "tests": [ - { - "description": "additionalProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar even when foo2 is present", - "data": {"foo2": "", "bar": ""}, - "valid": false - } - ] } ] diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index 84d4851ca..321d84461 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -81,6 +81,64 @@ } ] }, + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + }, { "description": "same $anchor with different base uri", "schema": { @@ -116,5 +174,61 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$schema": "https://json-schema.org/draft/next/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 + } + ] + }, + { + "description": "invalid anchors", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false + } + ] } ] diff --git a/tests/draft-next/contains.json b/tests/draft-next/contains.json index 8539a531d..c17f55ee7 100644 --- a/tests/draft-next/contains.json +++ b/tests/draft-next/contains.json @@ -31,6 +31,31 @@ "data": [], "valid": false }, + { + "description": "object with property matching schema (5) is valid", + "data": { "a": 3, "b": 4, "c": 5 }, + "valid": true + }, + { + "description": "object with property matching schema (6) is valid", + "data": { "a": 3, "b": 4, "c": 6 }, + "valid": true + }, + { + "description": "object with two properties matching schema (5, 6) is valid", + "data": { "a": 3, "b": 4, "c": 5, "d": 6 }, + "valid": true + }, + { + "description": "object without properties matching schema is invalid", + "data": { "a": 2, "b": 3, "c": 4 }, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, { "description": "not array or object is valid", "data": 42, @@ -59,6 +84,21 @@ "description": "array without item 5 is invalid", "data": [1, 2, 3, 4], "valid": false + }, + { + "description": "object with property 5 is valid", + "data": { "a": 3, "b": 4, "c": 5 }, + "valid": true + }, + { + "description": "object with two properties 5 is valid", + "data": { "a": 3, "b": 4, "c": 5, "d": 5 }, + "valid": true + }, + { + "description": "object without property 5 is invalid", + "data": { "a": 1, "b": 2, "c": 3, "d": 4 }, + "valid": false } ] }, @@ -78,6 +118,16 @@ "description": "empty array is invalid", "data": [], "valid": false + }, + { + "description": "any non-empty object is valid", + "data": { "a": "foo" }, + "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false } ] }, @@ -99,28 +149,18 @@ "valid": false }, { - "description": "non-arrays are valid - string", - "data": "contains does not apply to strings", - "valid": true + "description": "any non-empty object is invalid", + "data": ["foo"], + "valid": false }, { - "description": "non-arrays are valid - object", + "description": "empty object is invalid", "data": {}, - "valid": true - }, - { - "description": "non-arrays are valid - number", - "data": 42, - "valid": true - }, - { - "description": "non-arrays are valid - boolean", - "data": false, - "valid": true + "valid": false }, { - "description": "non-arrays are valid - null", - "data": null, + "description": "non-arrays/objects are valid", + "data": "contains does not apply to strings", "valid": true } ] @@ -153,6 +193,26 @@ "description": "matches neither items nor contains", "data": [1, 5], "valid": false + }, + { + "description": "matches additionalProperties, does not match contains", + "data": { "a": 2, "b": 4, "c": 8 }, + "valid": false + }, + { + "description": "does not match additionalProperties, matches contains", + "data": { "a": 3, "b": 6, "c": 9 }, + "valid": false + }, + { + "description": "matches both additionalProperties and contains", + "data": { "a": 6, "b": 12 }, + "valid": true + }, + { + "description": "matches neither additionalProperties nor contains", + "data": { "a": 1, "b": 5 }, + "valid": false } ] }, @@ -175,6 +235,16 @@ "description": "empty array is invalid", "data": [], "valid": false + }, + { + "description": "any non-empty object is valid", + "data": { "a": "foo" }, + "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false } ] }, diff --git a/tests/draft-next/dependentSchemas.json b/tests/draft-next/dependentSchemas.json index 86079c34c..8a8477591 100644 --- a/tests/draft-next/dependentSchemas.json +++ b/tests/draft-next/dependentSchemas.json @@ -132,7 +132,6 @@ { "description": "dependent subschema incompatible with root", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "properties": { "foo": {} }, diff --git a/tests/draft-next/dynamicRef.json b/tests/draft-next/dynamicRef.json index 30821c5b1..428c83b34 100644 --- a/tests/draft-next/dynamicRef.json +++ b/tests/draft-next/dynamicRef.json @@ -612,90 +612,5 @@ "valid": false } ] - }, - { - "description": "$dynamicRef points to a boolean schema", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "true": true, - "false": false - }, - "properties": { - "true": { - "$dynamicRef": "#/$defs/true" - }, - "false": { - "$dynamicRef": "#/$defs/false" - } - } - }, - "tests": [ - { - "description": "follow $dynamicRef to a true schema", - "data": { "true": 1 }, - "valid": true - }, - { - "description": "follow $dynamicRef to a false schema", - "data": { "false": 1 }, - "valid": false - } - ] - }, - { - "description": "$dynamicRef skips over intermediate resources - direct reference", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", - "type": "object", - "properties": { - "bar-item": { - "$ref": "item" - } - }, - "$defs": { - "bar": { - "$id": "bar", - "type": "array", - "items": { - "$ref": "item" - }, - "$defs": { - "item": { - "$id": "item", - "type": "object", - "properties": { - "content": { - "$dynamicRef": "#content" - } - }, - "$defs": { - "defaultContent": { - "$dynamicAnchor": "content", - "type": "integer" - } - } - }, - "content": { - "$dynamicAnchor": "content", - "type": "string" - } - } - } - } - }, - "tests": [ - { - "description": "integer property passes", - "data": { "bar-item": { "content": 42 } }, - "valid": true - }, - { - "description": "string property fails", - "data": { "bar-item": { "content": "value" } }, - "valid": false - } - ] } ] diff --git a/tests/draft-next/enum.json b/tests/draft-next/enum.json index e263f3901..32e5af01b 100644 --- a/tests/draft-next/enum.json +++ b/tests/draft-next/enum.json @@ -168,30 +168,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "enum": [[false]] - }, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": { @@ -216,30 +192,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "enum": [[true]] - }, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": { @@ -264,30 +216,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "enum": [[0]] - }, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": { @@ -312,30 +240,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "enum": [[1]] - }, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft-next/id.json b/tests/draft-next/id.json new file mode 100644 index 000000000..9b3a591f0 --- /dev/null +++ b/tests/draft-next/id.json @@ -0,0 +1,294 @@ +[ + { + "description": "Invalid use of fragments in location-independent $id", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "Identifier name", + "data": { + "$ref": "#foo", + "$defs": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name and no ref", + "data": { + "$defs": { + "A": { "$id": "#foo" } + } + }, + "valid": false + }, + { + "description": "Identifier path", + "data": { + "$ref": "#/a/b", + "$defs": { + "A": { + "$id": "#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft-next/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/bar#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier path with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft-next/bar#/a/b", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/bar#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft-next/root", + "$ref": "http://localhost:1234/draft-next/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "valid": false + }, + { + "description": "Identifier path with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft-next/root", + "$ref": "http://localhost:1234/draft-next/nested.json#/a/b", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#/a/b", + "type": "integer" + } + } + } + } + }, + "valid": false + } + ] + }, + { + "description": "Valid use of empty fragments in location-independent $id", + "comment": "These are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft-next/bar", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/bar#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft-next/root", + "$ref": "http://localhost:1234/draft-next/nested.json#/$defs/B", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#", + "type": "integer" + } + } + } + } + }, + "valid": true + } + ] + }, + { + "description": "Unnormalized $ids are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "Unnormalized identifier", + "data": { + "$ref": "http://localhost:1234/draft-next/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment", + "data": { + "$ref": "http://localhost:1234/draft-next/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + } + ] + }, + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft-next/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$schema": "https://json-schema.org/draft/next/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/items.json b/tests/draft-next/items.json index dfb79af2f..459943bef 100644 --- a/tests/draft-next/items.json +++ b/tests/draft-next/items.json @@ -265,26 +265,6 @@ } ] }, - { - "description": "items with heterogeneous array", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "prefixItems": [{}], - "items": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "items with null instance elements", "schema": { diff --git a/tests/draft-next/maxContains.json b/tests/draft-next/maxContains.json index 5af6e4c13..7c1515753 100644 --- a/tests/draft-next/maxContains.json +++ b/tests/draft-next/maxContains.json @@ -15,6 +15,16 @@ "description": "two items still valid against lone maxContains", "data": [1, 2], "valid": true + }, + { + "description": "one property valid against lone maxContains", + "data": { "a": 1 }, + "valid": true + }, + { + "description": "two properties still valid against lone maxContains", + "data": { "a": 1, "b": 2 }, + "valid": true } ] }, @@ -50,6 +60,31 @@ "description": "some elements match, invalid maxContains", "data": [1, 2, 1], "valid": false + }, + { + "description": "empty object", + "data": {}, + "valid": false + }, + { + "description": "all properties match, valid maxContains", + "data": { "a": 1 }, + "valid": true + }, + { + "description": "all properties match, invalid maxContains", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "some properties match, valid maxContains", + "data": { "a": 1, "b": 2 }, + "valid": true + }, + { + "description": "some properties match, invalid maxContains", + "data": { "a": 1, "b": 2, "c": 1 }, + "valid": false } ] }, @@ -96,6 +131,21 @@ "description": "array with minContains < maxContains < actual", "data": [1, 1, 1, 1], "valid": false + }, + { + "description": "object with actual < minContains < maxContains", + "data": {}, + "valid": false + }, + { + "description": "object with minContains < actual < maxContains", + "data": { "a": 1, "b": 1 }, + "valid": true + }, + { + "description": "object with minContains < maxContains < actual", + "data": { "a": 1, "b": 1, "c": 1, "d": 1 }, + "valid": false } ] } diff --git a/tests/draft-next/maxLength.json b/tests/draft-next/maxLength.json index c88f604ef..e09e44ad8 100644 --- a/tests/draft-next/maxLength.json +++ b/tests/draft-next/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft-next/minLength.json b/tests/draft-next/minLength.json index 52c9c9a14..16022acb5 100644 --- a/tests/draft-next/minLength.json +++ b/tests/draft-next/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft-next/oneOf.json b/tests/draft-next/oneOf.json index 840d1579d..e8c077131 100644 --- a/tests/draft-next/oneOf.json +++ b/tests/draft-next/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/next/schema", diff --git a/tests/draft-next/optional/anchor.json b/tests/draft-next/optional/anchor.json deleted file mode 100644 index 1de0b7a70..000000000 --- a/tests/draft-next/optional/anchor.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft-next/optional/dynamicRef.json b/tests/draft-next/optional/dynamicRef.json deleted file mode 100644 index dcace154e..000000000 --- a/tests/draft-next/optional/dynamicRef.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", - "type": "object", - "properties": { - "bar-item": { - "$ref": "bar#/$defs/item" - } - }, - "$defs": { - "bar": { - "$id": "bar", - "type": "array", - "items": { - "$ref": "item" - }, - "$defs": { - "item": { - "$id": "item", - "type": "object", - "properties": { - "content": { - "$dynamicRef": "#content" - } - }, - "$defs": { - "defaultContent": { - "$dynamicAnchor": "content", - "type": "integer" - } - } - }, - "content": { - "$dynamicAnchor": "content", - "type": "string" - } - } - } - } - }, - "tests": [ - { - "description": "integer property passes", - "data": { "bar-item": { "content": 42 } }, - "valid": true - }, - { - "description": "string property fails", - "data": { "bar-item": { "content": "value" } }, - "valid": false - } - ] - }] \ No newline at end of file diff --git a/tests/draft-next/optional/ecmascript-regex.json b/tests/draft-next/optional/ecmascript-regex.json index a1a4f9638..272114503 100644 --- a/tests/draft-next/optional/ecmascript-regex.json +++ b/tests/draft-next/optional/ecmascript-regex.json @@ -405,6 +405,20 @@ } ] }, + { + "description": "\\a is not an ECMA 262 control escape", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "when used as a pattern", + "data": { "pattern": "\\a" }, + "valid": false + } + ] + }, { "description": "pattern with non-ASCII digits", "schema": { diff --git a/tests/draft-next/optional/format/duration.json b/tests/draft-next/optional/format/duration.json index c4aa66bae..d5adca206 100644 --- a/tests/draft-next/optional/format/duration.json +++ b/tests/draft-next/optional/format/duration.json @@ -46,11 +46,6 @@ "data": "PT1D", "valid": false }, - { - "description": "must start with P", - "data": "4DT12H30M5S", - "valid": false - }, { "description": "no elements present", "data": "P", diff --git a/tests/draft-next/optional/format/ecmascript-regex.json b/tests/draft-next/optional/format/ecmascript-regex.json deleted file mode 100644 index 1e19c2729..000000000 --- a/tests/draft-next/optional/format/ecmascript-regex.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "description": "\\a is not an ECMA 262 control escape", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "format": "regex" - }, - "tests": [ - { - "description": "when used as a pattern", - "data": "\\a", - "valid": false - } - ] - } -] diff --git a/tests/draft-next/optional/format/hostname.json b/tests/draft-next/optional/format/hostname.json index bc3a60dcc..bfb306363 100644 --- a/tests/draft-next/optional/format/hostname.json +++ b/tests/draft-next/optional/format/hostname.json @@ -120,16 +120,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft-next/optional/format/idn-hostname.json b/tests/draft-next/optional/format/idn-hostname.json index 1061f4243..ee2e792fa 100644 --- a/tests/draft-next/optional/format/idn-hostname.json +++ b/tests/draft-next/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0628\u0660\u06f0", + "data": "\u0660\u06f0", "valid": false }, { @@ -301,88 +301,6 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true - }, - { - "description": "single label", - "data": "hostname", - "valid": true - }, - { - "description": "single label with hyphen", - "data": "host-name", - "valid": true - }, - { - "description": "single label with digits", - "data": "h0stn4me", - "valid": true - }, - { - "description": "single label starting with digit", - "data": "1host", - "valid": true - }, - { - "description": "single label ending with digit", - "data": "hostnam3", - "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - } - ] - }, - { - "description": "validation of separators in internationalized host names", - "specification": [ - {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} - ], - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "format": "idn-hostname" - }, - "tests": [ - { - "description": "single dot", - "data": ".", - "valid": false - }, - { - "description": "single ideographic full stop", - "data": "\u3002", - "valid": false - }, - { - "description": "single fullwidth full stop", - "data": "\uff0e", - "valid": false - }, - { - "description": "single halfwidth ideographic full stop", - "data": "\uff61", - "valid": false - }, - { - "description": "dot as label separator", - "data": "a.b", - "valid": true - }, - { - "description": "ideographic full stop as label separator", - "data": "a\u3002b", - "valid": true - }, - { - "description": "fullwidth full stop as label separator", - "data": "a\uff0eb", - "valid": true - }, - { - "description": "halfwidth ideographic full stop as label separator", - "data": "a\uff61b", - "valid": true } ] } diff --git a/tests/draft-next/optional/format/ipv4.json b/tests/draft-next/optional/format/ipv4.json index 2a4bc2b2f..e3e944015 100644 --- a/tests/draft-next/optional/format/ipv4.json +++ b/tests/draft-next/optional/format/ipv4.json @@ -81,11 +81,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft-next/optional/id.json b/tests/draft-next/optional/id.json deleted file mode 100644 index fc26f26c2..000000000 --- a/tests/draft-next/optional/id.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft-next/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft-next/optional/refOfUnknownKeyword.json b/tests/draft-next/optional/refOfUnknownKeyword.json index c832e09f6..489701cd2 100644 --- a/tests/draft-next/optional/refOfUnknownKeyword.json +++ b/tests/draft-next/optional/refOfUnknownKeyword.json @@ -42,28 +42,5 @@ "valid": false } ] - }, - { - "description": "reference internals of known non-applicator", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$id": "/base", - "examples": [ - { "type": "string" } - ], - "$ref": "#/examples/0" - }, - "tests": [ - { - "description": "match", - "data": "a string", - "valid": true - }, - { - "description": "mismatch", - "data": 42, - "valid": false - } - ] } ] diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json index 8417ce299..1d5f25613 100644 --- a/tests/draft-next/ref.json +++ b/tests/draft-next/ref.json @@ -862,7 +862,6 @@ { "description": "URN ref with nested pointer ref", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -888,7 +887,6 @@ { "description": "ref to if", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -911,7 +909,6 @@ { "description": "ref to then", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -934,7 +931,6 @@ { "description": "ref to else", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -957,7 +953,6 @@ { "description": "ref with absolute-path-reference", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -987,7 +982,6 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -1012,7 +1006,6 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1037,7 +1030,6 @@ { "description": "empty tokens in $ref json-pointer", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$defs": { "": { "$defs": { diff --git a/tests/draft-next/refRemote.json b/tests/draft-next/refRemote.json index 647fb9f19..9befceb25 100644 --- a/tests/draft-next/refRemote.json +++ b/tests/draft-next/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/draft-next/subSchemas.json#/$defs/integer" + "$ref": "http://localhost:1234/draft-next/subSchemas-defs.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/draft-next/subSchemas.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft-next/subSchemas-defs.json#/$defs/refToInteger" }, "tests": [ { @@ -265,10 +265,7 @@ }, { "description": "remote HTTP ref with different $id", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/different-id-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -284,10 +281,7 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/urn-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -303,10 +297,7 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" - }, + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, "tests": [ { "description": "number is invalid", @@ -323,7 +314,6 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://localhost:1234/draft-next/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft-next/unevaluatedItems.json b/tests/draft-next/unevaluatedItems.json index 08f6ef128..7379afb41 100644 --- a/tests/draft-next/unevaluatedItems.json +++ b/tests/draft-next/unevaluatedItems.json @@ -461,79 +461,6 @@ } ] }, - { - "description": "unevaluatedItems before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "unevaluatedItems": false, - "prefixItems": [ - { "type": "string" } - ], - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "prefixItems": [ - true, - { "type": "string" } - ] - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": ["foo", "bar"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": ["foo", "bar", "baz"], - "valid": false - } - ] - }, - { - "description": "unevaluatedItems with $dynamicRef", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived", - - "$ref": "./baseSchema", - - "$defs": { - "derived": { - "$dynamicAnchor": "addons", - "prefixItems": [ - true, - { "type": "string" } - ] - }, - "baseSchema": { - "$id": "./baseSchema", - - "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", - "unevaluatedItems": false, - "type": "array", - "prefixItems": [ - { "type": "string" } - ], - "$dynamicRef": "#addons" - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": ["foo", "bar"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": ["foo", "bar", "baz"], - "valid": false - } - ] - }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json index 13fe6e03a..69fe8a00c 100644 --- a/tests/draft-next/unevaluatedProperties.json +++ b/tests/draft-next/unevaluatedProperties.json @@ -715,92 +715,6 @@ } ] }, - { - "description": "unevaluatedProperties before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "type": "object", - "unevaluatedProperties": false, - "properties": { - "foo": { "type": "string" } - }, - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "properties": { - "bar": { "type": "string" } - } - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar" - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar", - "baz": "baz" - }, - "valid": false - } - ] - }, - { - "description": "unevaluatedProperties with $dynamicRef", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$id": "https://example.com/unevaluated-properties-with-dynamic-ref/derived", - - "$ref": "./baseSchema", - - "$defs": { - "derived": { - "$dynamicAnchor": "addons", - "properties": { - "bar": { "type": "string" } - } - }, - "baseSchema": { - "$id": "./baseSchema", - - "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", - "unevaluatedProperties": false, - "type": "object", - "properties": { - "foo": { "type": "string" } - }, - "$dynamicRef": "#addons" - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar" - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar", - "baz": "baz" - }, - "valid": false - } - ] - }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1451,6 +1365,57 @@ } ] }, + { + "description": "unevaluatedProperties depends on adjacent contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": { "type": "number" } + }, + "contains": { "type": "string" }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "bar is evaluated by contains", + "data": { "foo": 1, "bar": "foo" }, + "valid": true + }, + { + "description": "contains fails, bar is not evaluated", + "data": { "foo": 1, "bar": 2 }, + "valid": false + }, + { + "description": "contains passes, bar is not evaluated", + "data": { "foo": 1, "bar": 2, "baz": "foo" }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties depends on multiple nested contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { "contains": { "multipleOf": 2 } }, + { "contains": { "multipleOf": 3 } } + ], + "unevaluatedProperties": { "multipleOf": 5 } + }, + "tests": [ + { + "description": "5 not evaluated, passes unevaluatedItems", + "data": { "a": 2, "b": 3, "c": 4, "d": 5, "e": 6 }, + "valid": true + }, + { + "description": "7 not evaluated, fails unevaluatedItems", + "data": { "a": 2, "b": 3, "c": 4, "d": 7, "e": 8 }, + "valid": false + } + ] + }, { "description": "non-object instances are valid", "schema": { @@ -1603,74 +1568,5 @@ "valid": false } ] - }, - { - "description": "propertyDependencies with unevaluatedProperties" , - "schema" : { - "$schema": "https://json-schema.org/draft/next/schema", - "properties" : {"foo2" : {}}, - "propertyDependencies": { - "foo" : {}, - "foo2": { - "bar": { - "properties": { - "buz": {} - } - } - } - }, - "unevaluatedProperties": false - }, - - "tests": [ - { - "description": "unevaluatedProperties doesn't consider propertyDependencies" , - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "unevaluatedProperties sees buz when foo2 is present", - "data": {"foo2": "bar", "buz": ""}, - "valid": true - }, - { - "description": "unevaluatedProperties doesn't see buz when foo2 is absent", - "data": {"buz": ""}, - "valid": false - } - ] - }, - { - "description": "dependentSchemas with unevaluatedProperties", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo" : {}, - "foo2": { - "properties": { - "bar":{} - } - } - }, - "unevaluatedProperties": false - }, - "tests": [ - { - "description": "unevaluatedProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties doesn't see bar when foo2 is absent", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties sees bar when foo2 is present", - "data": {"foo2": "", "bar": ""}, - "valid": true - } - ] } ] diff --git a/tests/draft-next/optional/unknownKeyword.json b/tests/draft-next/unknownKeyword.json similarity index 100% rename from tests/draft-next/optional/unknownKeyword.json rename to tests/draft-next/unknownKeyword.json diff --git a/tests/draft2019-09/additionalItems.json b/tests/draft2019-09/additionalItems.json index 9a7ae4f8a..aa44bcb76 100644 --- a/tests/draft2019-09/additionalItems.json +++ b/tests/draft2019-09/additionalItems.json @@ -182,26 +182,6 @@ } ] }, - { - "description": "additionalItems with heterogeneous array", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": [{}], - "additionalItems": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft2019-09/additionalProperties.json b/tests/draft2019-09/additionalProperties.json index 73f9b909e..f9f03bb04 100644 --- a/tests/draft2019-09/additionalProperties.json +++ b/tests/draft2019-09/additionalProperties.json @@ -152,62 +152,5 @@ "valid": true } ] - }, - { - "description": "additionalProperties with propertyNames", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "propertyNames": { - "maxLength": 5 - }, - "additionalProperties": { - "type": "number" - } - }, - "tests": [ - { - "description": "Valid against both keywords", - "data": { "apple": 4 }, - "valid": true - }, - { - "description": "Valid against propertyNames, but not additionalProperties", - "data": { "fig": 2, "pear": "available" }, - "valid": false - } - ] - }, - { - "description": "dependentSchemas with additionalProperties", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo" : {}, - "foo2": { - "properties": { - "bar":{} - } - } - }, - "additionalProperties": false - }, - "tests": [ - { - "description": "additionalProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar even when foo2 is present", - "data": { "foo2": "", "bar": ""}, - "valid": false - } - ] } ] diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index bce05e800..5d8c86f11 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -81,6 +81,64 @@ } ] }, + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + }, { "description": "same $anchor with different base uri", "schema": { @@ -116,5 +174,62 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/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 + } + ] + }, + { + "description": "invalid anchors", + "comment": "Section 8.2.3", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/dependentSchemas.json b/tests/draft2019-09/dependentSchemas.json index c5b8ea05f..3577efdf4 100644 --- a/tests/draft2019-09/dependentSchemas.json +++ b/tests/draft2019-09/dependentSchemas.json @@ -132,7 +132,6 @@ { "description": "dependent subschema incompatible with root", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {} }, diff --git a/tests/draft2019-09/enum.json b/tests/draft2019-09/enum.json index 1315211ea..f9a44a61d 100644 --- a/tests/draft2019-09/enum.json +++ b/tests/draft2019-09/enum.json @@ -168,30 +168,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [[false]] - }, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": { @@ -216,30 +192,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [[true]] - }, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": { @@ -264,30 +216,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [[0]] - }, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": { @@ -312,30 +240,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [[1]] - }, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json new file mode 100644 index 000000000..e2e403f0b --- /dev/null +++ b/tests/draft2019-09/id.json @@ -0,0 +1,294 @@ +[ + { + "description": "Invalid use of fragments in location-independent $id", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Identifier name", + "data": { + "$ref": "#foo", + "$defs": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name and no ref", + "data": { + "$defs": { + "A": { "$id": "#foo" } + } + }, + "valid": false + }, + { + "description": "Identifier path", + "data": { + "$ref": "#/a/b", + "$defs": { + "A": { + "$id": "#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2019-09/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/bar#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier path with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2019-09/bar#/a/b", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/bar#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2019-09/root", + "$ref": "http://localhost:1234/draft2019-09/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "valid": false + }, + { + "description": "Identifier path with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2019-09/root", + "$ref": "http://localhost:1234/draft2019-09/nested.json#/a/b", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#/a/b", + "type": "integer" + } + } + } + } + }, + "valid": false + } + ] + }, + { + "description": "Valid use of empty fragments in location-independent $id", + "comment": "These are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2019-09/bar", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/bar#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2019-09/root", + "$ref": "http://localhost:1234/draft2019-09/nested.json#/$defs/B", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#", + "type": "integer" + } + } + } + } + }, + "valid": true + } + ] + }, + { + "description": "Unnormalized $ids are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Unnormalized identifier", + "data": { + "$ref": "http://localhost:1234/draft2019-09/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment", + "data": { + "$ref": "http://localhost:1234/draft2019-09/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + } + ] + }, + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft2019-09/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/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/maxLength.json b/tests/draft2019-09/maxLength.json index a0cc7d9b8..f242c3eff 100644 --- a/tests/draft2019-09/maxLength.json +++ b/tests/draft2019-09/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft2019-09/minLength.json b/tests/draft2019-09/minLength.json index 12782660c..19dec2cac 100644 --- a/tests/draft2019-09/minLength.json +++ b/tests/draft2019-09/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft2019-09/not.json b/tests/draft2019-09/not.json index d90728c7b..62c9af9de 100644 --- a/tests/draft2019-09/not.json +++ b/tests/draft2019-09/not.json @@ -97,173 +97,25 @@ ] }, { - "description": "forbid everything with empty schema", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": {} - }, - "tests": [ - { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", - "data": "foo", - "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "forbid everything with boolean schema true", + "description": "not with boolean schema true", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "not": true }, "tests": [ { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", + "description": "any value is invalid", "data": "foo", "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false } ] }, { - "description": "allow everything with boolean schema false", + "description": "not with boolean schema false", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "not": false }, - "tests": [ - { - "description": "number is valid", - "data": 1, - "valid": true - }, - { - "description": "string is valid", - "data": "foo", - "valid": true - }, - { - "description": "boolean true is valid", - "data": true, - "valid": true - }, - { - "description": "boolean false is valid", - "data": false, - "valid": true - }, - { - "description": "null is valid", - "data": null, - "valid": true - }, - { - "description": "object is valid", - "data": {"foo": "bar"}, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "array is valid", - "data": ["foo"], - "valid": true - }, - { - "description": "empty array is valid", - "data": [], - "valid": true - } - ] - }, - { - "description": "double negation", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": { "not": {} } - }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft2019-09/oneOf.json b/tests/draft2019-09/oneOf.json index c27d4865c..9b7a2204e 100644 --- a/tests/draft2019-09/oneOf.json +++ b/tests/draft2019-09/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", diff --git a/tests/draft2019-09/optional/anchor.json b/tests/draft2019-09/optional/anchor.json deleted file mode 100644 index 45951d0a3..000000000 --- a/tests/draft2019-09/optional/anchor.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft2019-09/optional/format/duration.json b/tests/draft2019-09/optional/format/duration.json index 2d515a64a..00d5f47ae 100644 --- a/tests/draft2019-09/optional/format/duration.json +++ b/tests/draft2019-09/optional/format/duration.json @@ -46,11 +46,6 @@ "data": "PT1D", "valid": false }, - { - "description": "must start with P", - "data": "4DT12H30M5S", - "valid": false - }, { "description": "no elements present", "data": "P", diff --git a/tests/draft2019-09/optional/format/hostname.json b/tests/draft2019-09/optional/format/hostname.json index 24bfdfc5a..f3b7181c8 100644 --- a/tests/draft2019-09/optional/format/hostname.json +++ b/tests/draft2019-09/optional/format/hostname.json @@ -120,16 +120,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/idn-hostname.json b/tests/draft2019-09/optional/format/idn-hostname.json index 348c504c8..72f179751 100644 --- a/tests/draft2019-09/optional/format/idn-hostname.json +++ b/tests/draft2019-09/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0628\u0660\u06f0", + "data": "\u0660\u06f0", "valid": false }, { @@ -301,88 +301,6 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true - }, - { - "description": "single label", - "data": "hostname", - "valid": true - }, - { - "description": "single label with hyphen", - "data": "host-name", - "valid": true - }, - { - "description": "single label with digits", - "data": "h0stn4me", - "valid": true - }, - { - "description": "single label starting with digit", - "data": "1host", - "valid": true - }, - { - "description": "single label ending with digit", - "data": "hostnam3", - "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - } - ] - }, - { - "description": "validation of separators in internationalized host names", - "specification": [ - {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} - ], - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "format": "idn-hostname" - }, - "tests": [ - { - "description": "single dot", - "data": ".", - "valid": false - }, - { - "description": "single ideographic full stop", - "data": "\u3002", - "valid": false - }, - { - "description": "single fullwidth full stop", - "data": "\uff0e", - "valid": false - }, - { - "description": "single halfwidth ideographic full stop", - "data": "\uff61", - "valid": false - }, - { - "description": "dot as label separator", - "data": "a.b", - "valid": true - }, - { - "description": "ideographic full stop as label separator", - "data": "a\u3002b", - "valid": true - }, - { - "description": "fullwidth full stop as label separator", - "data": "a\uff0eb", - "valid": true - }, - { - "description": "halfwidth ideographic full stop as label separator", - "data": "a\uff61b", - "valid": true } ] } diff --git a/tests/draft2019-09/optional/format/ipv4.json b/tests/draft2019-09/optional/format/ipv4.json index efe42471b..ac1e14c68 100644 --- a/tests/draft2019-09/optional/format/ipv4.json +++ b/tests/draft2019-09/optional/format/ipv4.json @@ -81,11 +81,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft2019-09/optional/id.json b/tests/draft2019-09/optional/id.json deleted file mode 100644 index 4daa8f51f..000000000 --- a/tests/draft2019-09/optional/id.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft2019-09/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft2019-09/optional/refOfUnknownKeyword.json b/tests/draft2019-09/optional/refOfUnknownKeyword.json index e9a75dd1e..eee1c33ed 100644 --- a/tests/draft2019-09/optional/refOfUnknownKeyword.json +++ b/tests/draft2019-09/optional/refOfUnknownKeyword.json @@ -42,28 +42,5 @@ "valid": false } ] - }, - { - "description": "reference internals of known non-applicator", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "/base", - "examples": [ - { "type": "string" } - ], - "$ref": "#/examples/0" - }, - "tests": [ - { - "description": "match", - "data": "a string", - "valid": true - }, - { - "description": "mismatch", - "data": 42, - "valid": false - } - ] } ] diff --git a/tests/draft2019-09/propertyNames.json b/tests/draft2019-09/propertyNames.json index 3b2bb23bb..b7fecbf71 100644 --- a/tests/draft2019-09/propertyNames.json +++ b/tests/draft2019-09/propertyNames.json @@ -111,58 +111,5 @@ "valid": true } ] - }, - { - "description": "propertyNames with const", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "propertyNames": {"const": "foo"} - }, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"bar": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] - }, - { - "description": "propertyNames with enum", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "propertyNames": {"enum": ["foo", "bar"]} - }, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with property foo and bar is valid", - "data": {"foo": 1, "bar": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"baz": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] } ] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index eff5305c3..7d850414d 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -791,6 +791,21 @@ } ] }, + { + "description": "URN base URI with f-component", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "is invalid", + "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, + "valid": false + } + ] + }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { @@ -847,7 +862,6 @@ { "description": "URN ref with nested pointer ref", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -873,7 +887,6 @@ { "description": "ref to if", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -896,7 +909,6 @@ { "description": "ref to then", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -919,7 +931,6 @@ { "description": "ref to else", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -942,7 +953,6 @@ { "description": "ref with absolute-path-reference", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -972,7 +982,6 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -997,7 +1006,6 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1022,7 +1030,6 @@ { "description": "empty tokens in $ref json-pointer", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$defs": { "": { "$defs": { @@ -1048,43 +1055,5 @@ "valid": false } ] - }, - { - "description": "$ref with $recursiveAnchor", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/schemas/unevaluated-items-are-disallowed", - "$ref": "/schemas/unevaluated-items-are-allowed", - "$recursiveAnchor": true, - "unevaluatedItems": false, - "$defs": { - "/schemas/unevaluated-items-are-allowed": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "/schemas/unevaluated-items-are-allowed", - "$recursiveAnchor": true, - "type": "array", - "items": [ - { - "type": "string" - }, - { - "$ref": "#" - } - ] - } - } - }, - "tests": [ - { - "description": "extra items allowed for inner arrays", - "data" : ["foo",["bar" , [] , 8]], - "valid": true - }, - { - "description": "extra items disallowed for root", - "data" : ["foo",["bar" , [] , 8], 8], - "valid": false - } - ] - } + } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 072894cf2..0bacbfc2e 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/integer" + "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/refToInteger" }, "tests": [ { @@ -265,10 +265,7 @@ }, { "description": "remote HTTP ref with different $id", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/different-id-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -284,10 +281,7 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/urn-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -303,10 +297,7 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" - }, + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, "tests": [ { "description": "number is invalid", @@ -323,7 +314,6 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://localhost:1234/draft2019-09/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json index 8e2ee4b11..53565a0b9 100644 --- a/tests/draft2019-09/unevaluatedItems.json +++ b/tests/draft2019-09/unevaluatedItems.json @@ -480,82 +480,6 @@ } ] }, - { - "description": "unevaluatedItems before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedItems": false, - "items": [ - { "type": "string" } - ], - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "items": [ - true, - { "type": "string" } - ] - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": ["foo", "bar"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": ["foo", "bar", "baz"], - "valid": false - } - ] - }, - { - "description": "unevaluatedItems with $recursiveRef", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/unevaluated-items-with-recursive-ref/extended-tree", - - "$recursiveAnchor": true, - - "$ref": "./tree", - "items": [ - true, - true, - { "type": "string" } - ], - - "$defs": { - "tree": { - "$id": "./tree", - "$recursiveAnchor": true, - - "type": "array", - "items": [ - { "type": "number" }, - { - "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", - "unevaluatedItems": false, - "$recursiveRef": "#" - } - ] - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": [1, [2, [], "b"], "a"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": [1, [2, [], "b", "too many"], "a"], - "valid": false - } - ] - }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json index e8765112c..a6cce8bb6 100644 --- a/tests/draft2019-09/unevaluatedProperties.json +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -715,102 +715,6 @@ } ] }, - { - "description": "unevaluatedProperties before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "unevaluatedProperties": false, - "properties": { - "foo": { "type": "string" } - }, - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "properties": { - "bar": { "type": "string" } - } - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar" - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar", - "baz": "baz" - }, - "valid": false - } - ] - }, - { - "description": "unevaluatedProperties with $recursiveRef", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/unevaluated-properties-with-recursive-ref/extended-tree", - - "$recursiveAnchor": true, - - "$ref": "./tree", - "properties": { - "name": { "type": "string" } - }, - - "$defs": { - "tree": { - "$id": "./tree", - "$recursiveAnchor": true, - - "type": "object", - "properties": { - "node": true, - "branches": { - "$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering", - "unevaluatedProperties": false, - "$recursiveRef": "#" - } - }, - "required": ["node"] - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "name": "a", - "node": 1, - "branches": { - "name": "b", - "node": 2 - } - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "name": "a", - "node": 1, - "branches": { - "foo": "b", - "node": 2 - } - }, - "valid": false - } - ] - }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1567,38 +1471,5 @@ "valid": false } ] - }, - { - "description": "dependentSchemas with unevaluatedProperties", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo" : {}, - "foo2": { - "properties": { - "bar":{} - } - } - }, - "unevaluatedProperties": false - }, - "tests": [ - { - "description": "unevaluatedProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties doesn't see bar when foo2 is absent", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties sees bar when foo2 is present", - "data": { "foo2": "", "bar": ""}, - "valid": true - } - ] } ] diff --git a/tests/draft2019-09/optional/unknownKeyword.json b/tests/draft2019-09/unknownKeyword.json similarity index 100% rename from tests/draft2019-09/optional/unknownKeyword.json rename to tests/draft2019-09/unknownKeyword.json diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json index 9618575e2..29e69c135 100644 --- a/tests/draft2020-12/additionalProperties.json +++ b/tests/draft2020-12/additionalProperties.json @@ -2,7 +2,6 @@ { "description": "additionalProperties being false does not allow other properties", - "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -44,7 +43,6 @@ }, { "description": "non-ASCII pattern with additionalProperties", - "specification": [ { "core":"10.3.2.3"} ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "patternProperties": {"^á": {}}, @@ -65,7 +63,6 @@ }, { "description": "additionalProperties with schema", - "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -90,8 +87,8 @@ ] }, { - "description": "additionalProperties can exist by itself", - "specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ], + "description": + "additionalProperties can exist by itself", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": {"type": "boolean"} @@ -111,7 +108,6 @@ }, { "description": "additionalProperties are allowed by default", - "specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}} @@ -126,7 +122,6 @@ }, { "description": "additionalProperties does not look in applicators", - "specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ @@ -144,7 +139,6 @@ }, { "description": "additionalProperties with null valued instance properties", - "specification": [ { "core":"10.3.2.3" } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": { @@ -158,62 +152,5 @@ "valid": true } ] - }, - { - "description": "additionalProperties with propertyNames", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": { - "maxLength": 5 - }, - "additionalProperties": { - "type": "number" - } - }, - "tests": [ - { - "description": "Valid against both keywords", - "data": { "apple": 4 }, - "valid": true - }, - { - "description": "Valid against propertyNames, but not additionalProperties", - "data": { "fig": 2, "pear": "available" }, - "valid": false - } - ] - }, - { - "description": "dependentSchemas with additionalProperties", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo" : {}, - "foo2": { - "properties": { - "bar": {} - } - } - }, - "additionalProperties": false - }, - "tests": [ - { - "description": "additionalProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "additionalProperties can't see bar even when foo2 is present", - "data": {"foo2": "", "bar": ""}, - "valid": false - } - ] } ] diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 99143fa11..423835dac 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -81,6 +81,64 @@ } ] }, + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + }, { "description": "same $anchor with different base uri", "schema": { @@ -116,5 +174,62 @@ "valid": false } ] + }, + { + "description": "non-schema object containing an $anchor property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/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 + } + ] + }, + { + "description": "invalid anchors", + "comment": "Section 8.2.2", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/dependentSchemas.json b/tests/draft2020-12/dependentSchemas.json index 1c5f0574a..66ac0eb43 100644 --- a/tests/draft2020-12/dependentSchemas.json +++ b/tests/draft2020-12/dependentSchemas.json @@ -132,7 +132,6 @@ { "description": "dependent subschema incompatible with root", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": {} }, diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json index ffa211ba2..c1c56cb8a 100644 --- a/tests/draft2020-12/dynamicRef.json +++ b/tests/draft2020-12/dynamicRef.json @@ -726,90 +726,5 @@ "valid": false } ] - }, - { - "description": "$dynamicRef points to a boolean schema", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "true": true, - "false": false - }, - "properties": { - "true": { - "$dynamicRef": "#/$defs/true" - }, - "false": { - "$dynamicRef": "#/$defs/false" - } - } - }, - "tests": [ - { - "description": "follow $dynamicRef to a true schema", - "data": { "true": 1 }, - "valid": true - }, - { - "description": "follow $dynamicRef to a false schema", - "data": { "false": 1 }, - "valid": false - } - ] - }, - { - "description": "$dynamicRef skips over intermediate resources - direct reference", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", - "type": "object", - "properties": { - "bar-item": { - "$ref": "item" - } - }, - "$defs": { - "bar": { - "$id": "bar", - "type": "array", - "items": { - "$ref": "item" - }, - "$defs": { - "item": { - "$id": "item", - "type": "object", - "properties": { - "content": { - "$dynamicRef": "#content" - } - }, - "$defs": { - "defaultContent": { - "$dynamicAnchor": "content", - "type": "integer" - } - } - }, - "content": { - "$dynamicAnchor": "content", - "type": "string" - } - } - } - } - }, - "tests": [ - { - "description": "integer property passes", - "data": { "bar-item": { "content": 42 } }, - "valid": true - }, - { - "description": "string property fails", - "data": { "bar-item": { "content": "value" } }, - "valid": false - } - ] } ] diff --git a/tests/draft2020-12/enum.json b/tests/draft2020-12/enum.json index c8f35eacf..0d780b2ac 100644 --- a/tests/draft2020-12/enum.json +++ b/tests/draft2020-12/enum.json @@ -168,30 +168,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [[false]] - }, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": { @@ -216,30 +192,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [[true]] - }, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": { @@ -264,30 +216,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [[0]] - }, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": { @@ -312,30 +240,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [[1]] - }, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft2020-12/id.json b/tests/draft2020-12/id.json new file mode 100644 index 000000000..0ae5fe68a --- /dev/null +++ b/tests/draft2020-12/id.json @@ -0,0 +1,294 @@ +[ + { + "description": "Invalid use of fragments in location-independent $id", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "Identifier name", + "data": { + "$ref": "#foo", + "$defs": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name and no ref", + "data": { + "$defs": { + "A": { "$id": "#foo" } + } + }, + "valid": false + }, + { + "description": "Identifier path", + "data": { + "$ref": "#/a/b", + "$defs": { + "A": { + "$id": "#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2020-12/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/bar#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier path with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2020-12/bar#/a/b", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/bar#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2020-12/root", + "$ref": "http://localhost:1234/draft2020-12/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "valid": false + }, + { + "description": "Identifier path with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2020-12/root", + "$ref": "http://localhost:1234/draft2020-12/nested.json#/a/b", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#/a/b", + "type": "integer" + } + } + } + } + }, + "valid": false + } + ] + }, + { + "description": "Valid use of empty fragments in location-independent $id", + "comment": "These are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/draft2020-12/bar", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/bar#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/draft2020-12/root", + "$ref": "http://localhost:1234/draft2020-12/nested.json#/$defs/B", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#", + "type": "integer" + } + } + } + } + }, + "valid": true + } + ] + }, + { + "description": "Unnormalized $ids are allowed but discouraged", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "Unnormalized identifier", + "data": { + "$ref": "http://localhost:1234/draft2020-12/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment", + "data": { + "$ref": "http://localhost:1234/draft2020-12/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + } + ] + }, + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/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/items.json b/tests/draft2020-12/items.json index 6a3e1cf26..1ef18bdd0 100644 --- a/tests/draft2020-12/items.json +++ b/tests/draft2020-12/items.json @@ -265,26 +265,6 @@ } ] }, - { - "description": "items with heterogeneous array", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "prefixItems": [{}], - "items": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "items with null instance elements", "schema": { diff --git a/tests/draft2020-12/maxLength.json b/tests/draft2020-12/maxLength.json index 7462726d7..b6eb03401 100644 --- a/tests/draft2020-12/maxLength.json +++ b/tests/draft2020-12/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft2020-12/minLength.json b/tests/draft2020-12/minLength.json index 5076c5a92..e0930b6fb 100644 --- a/tests/draft2020-12/minLength.json +++ b/tests/draft2020-12/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft2020-12/not.json b/tests/draft2020-12/not.json index d0f2b6e84..57e45ba39 100644 --- a/tests/draft2020-12/not.json +++ b/tests/draft2020-12/not.json @@ -97,173 +97,25 @@ ] }, { - "description": "forbid everything with empty schema", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": {} - }, - "tests": [ - { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", - "data": "foo", - "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "forbid everything with boolean schema true", + "description": "not with boolean schema true", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "not": true }, "tests": [ { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", + "description": "any value is invalid", "data": "foo", "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false } ] }, { - "description": "allow everything with boolean schema false", + "description": "not with boolean schema false", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "not": false }, - "tests": [ - { - "description": "number is valid", - "data": 1, - "valid": true - }, - { - "description": "string is valid", - "data": "foo", - "valid": true - }, - { - "description": "boolean true is valid", - "data": true, - "valid": true - }, - { - "description": "boolean false is valid", - "data": false, - "valid": true - }, - { - "description": "null is valid", - "data": null, - "valid": true - }, - { - "description": "object is valid", - "data": {"foo": "bar"}, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "array is valid", - "data": ["foo"], - "valid": true - }, - { - "description": "empty array is valid", - "data": [], - "valid": true - } - ] - }, - { - "description": "double negation", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": { "not": {} } - }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft2020-12/oneOf.json b/tests/draft2020-12/oneOf.json index 7a7c7ffe3..416c8e570 100644 --- a/tests/draft2020-12/oneOf.json +++ b/tests/draft2020-12/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", diff --git a/tests/draft2020-12/optional/anchor.json b/tests/draft2020-12/optional/anchor.json deleted file mode 100644 index 6d6713be5..000000000 --- a/tests/draft2020-12/optional/anchor.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft2020-12/optional/dynamicRef.json b/tests/draft2020-12/optional/dynamicRef.json deleted file mode 100644 index 7e63f209a..000000000 --- a/tests/draft2020-12/optional/dynamicRef.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", - "type": "object", - "properties": { - "bar-item": { - "$ref": "bar#/$defs/item" - } - }, - "$defs": { - "bar": { - "$id": "bar", - "type": "array", - "items": { - "$ref": "item" - }, - "$defs": { - "item": { - "$id": "item", - "type": "object", - "properties": { - "content": { - "$dynamicRef": "#content" - } - }, - "$defs": { - "defaultContent": { - "$dynamicAnchor": "content", - "type": "integer" - } - } - }, - "content": { - "$dynamicAnchor": "content", - "type": "string" - } - } - } - } - }, - "tests": [ - { - "description": "integer property passes", - "data": { "bar-item": { "content": 42 } }, - "valid": true - }, - { - "description": "string property fails", - "data": { "bar-item": { "content": "value" } }, - "valid": false - } - ] - }] \ No newline at end of file diff --git a/tests/draft2020-12/optional/ecmascript-regex.json b/tests/draft2020-12/optional/ecmascript-regex.json index a4d62e0cf..23b962e4b 100644 --- a/tests/draft2020-12/optional/ecmascript-regex.json +++ b/tests/draft2020-12/optional/ecmascript-regex.json @@ -405,6 +405,20 @@ } ] }, + { + "description": "\\a is not an ECMA 262 control escape", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "when used as a pattern", + "data": { "pattern": "\\a" }, + "valid": false + } + ] + }, { "description": "pattern with non-ASCII digits", "schema": { diff --git a/tests/draft2020-12/optional/format/duration.json b/tests/draft2020-12/optional/format/duration.json index a09fec5ef..a3af56ef0 100644 --- a/tests/draft2020-12/optional/format/duration.json +++ b/tests/draft2020-12/optional/format/duration.json @@ -46,11 +46,6 @@ "data": "PT1D", "valid": false }, - { - "description": "must start with P", - "data": "4DT12H30M5S", - "valid": false - }, { "description": "no elements present", "data": "P", diff --git a/tests/draft2020-12/optional/format/ecmascript-regex.json b/tests/draft2020-12/optional/format/ecmascript-regex.json deleted file mode 100644 index b0648084a..000000000 --- a/tests/draft2020-12/optional/format/ecmascript-regex.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "description": "\\a is not an ECMA 262 control escape", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "format": "regex" - }, - "tests": [ - { - "description": "when used as a pattern", - "data": "\\a", - "valid": false - } - ] - } -] \ No newline at end of file diff --git a/tests/draft2020-12/optional/format/hostname.json b/tests/draft2020-12/optional/format/hostname.json index 57827c4d4..41418dd4a 100644 --- a/tests/draft2020-12/optional/format/hostname.json +++ b/tests/draft2020-12/optional/format/hostname.json @@ -120,16 +120,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft2020-12/optional/format/idn-hostname.json b/tests/draft2020-12/optional/format/idn-hostname.json index f42ae969b..5549c0550 100644 --- a/tests/draft2020-12/optional/format/idn-hostname.json +++ b/tests/draft2020-12/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0628\u0660\u06f0", + "data": "\u0660\u06f0", "valid": false }, { @@ -301,88 +301,6 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true - }, - { - "description": "single label", - "data": "hostname", - "valid": true - }, - { - "description": "single label with hyphen", - "data": "host-name", - "valid": true - }, - { - "description": "single label with digits", - "data": "h0stn4me", - "valid": true - }, - { - "description": "single label starting with digit", - "data": "1host", - "valid": true - }, - { - "description": "single label ending with digit", - "data": "hostnam3", - "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - } - ] - }, - { - "description": "validation of separators in internationalized host names", - "specification": [ - {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} - ], - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "format": "idn-hostname" - }, - "tests": [ - { - "description": "single dot", - "data": ".", - "valid": false - }, - { - "description": "single ideographic full stop", - "data": "\u3002", - "valid": false - }, - { - "description": "single fullwidth full stop", - "data": "\uff0e", - "valid": false - }, - { - "description": "single halfwidth ideographic full stop", - "data": "\uff61", - "valid": false - }, - { - "description": "dot as label separator", - "data": "a.b", - "valid": true - }, - { - "description": "ideographic full stop as label separator", - "data": "a\u3002b", - "valid": true - }, - { - "description": "fullwidth full stop as label separator", - "data": "a\uff0eb", - "valid": true - }, - { - "description": "halfwidth ideographic full stop as label separator", - "data": "a\uff61b", - "valid": true } ] } diff --git a/tests/draft2020-12/optional/format/ipv4.json b/tests/draft2020-12/optional/format/ipv4.json index 86d27bdb7..c72b6fc22 100644 --- a/tests/draft2020-12/optional/format/ipv4.json +++ b/tests/draft2020-12/optional/format/ipv4.json @@ -81,11 +81,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft2020-12/optional/id.json b/tests/draft2020-12/optional/id.json deleted file mode 100644 index 0b7df4e80..000000000 --- a/tests/draft2020-12/optional/id.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - } -] diff --git a/tests/draft2020-12/optional/refOfUnknownKeyword.json b/tests/draft2020-12/optional/refOfUnknownKeyword.json index c2b080a1e..f91c18884 100644 --- a/tests/draft2020-12/optional/refOfUnknownKeyword.json +++ b/tests/draft2020-12/optional/refOfUnknownKeyword.json @@ -42,28 +42,5 @@ "valid": false } ] - }, - { - "description": "reference internals of known non-applicator", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "/base", - "examples": [ - { "type": "string" } - ], - "$ref": "#/examples/0" - }, - "tests": [ - { - "description": "match", - "data": "a string", - "valid": true - }, - { - "description": "mismatch", - "data": 42, - "valid": false - } - ] } ] diff --git a/tests/draft2020-12/propertyNames.json b/tests/draft2020-12/propertyNames.json index b4780088a..7ecfb7ec3 100644 --- a/tests/draft2020-12/propertyNames.json +++ b/tests/draft2020-12/propertyNames.json @@ -44,36 +44,6 @@ } ] }, - { - "description": "propertyNames validation with pattern", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": { "pattern": "^a+$" } - }, - "tests": [ - { - "description": "matching property names valid", - "data": { - "a": {}, - "aa": {}, - "aaa": {} - }, - "valid": true - }, - { - "description": "non-matching property name is invalid", - "data": { - "aaA": {} - }, - "valid": false - }, - { - "description": "object without properties is valid", - "data": {}, - "valid": true - } - ] - }, { "description": "propertyNames with boolean schema true", "schema": { @@ -111,58 +81,5 @@ "valid": true } ] - }, - { - "description": "propertyNames with const", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": {"const": "foo"} - }, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"bar": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] - }, - { - "description": "propertyNames with enum", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": {"enum": ["foo", "bar"]} - }, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with property foo and bar is valid", - "data": {"foo": 1, "bar": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"baz": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] } ] diff --git a/tests/draft2020-12/ref.json b/tests/draft2020-12/ref.json index a1d3efaf7..5f6be8c20 100644 --- a/tests/draft2020-12/ref.json +++ b/tests/draft2020-12/ref.json @@ -791,6 +791,21 @@ } ] }, + { + "description": "URN base URI with f-component", + "schema": { + "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "is invalid", + "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, + "valid": false + } + ] + }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { @@ -847,7 +862,6 @@ { "description": "URN ref with nested pointer ref", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -873,7 +887,6 @@ { "description": "ref to if", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -896,7 +909,6 @@ { "description": "ref to then", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -919,7 +931,6 @@ { "description": "ref to else", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -942,7 +953,6 @@ { "description": "ref with absolute-path-reference", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -972,7 +982,6 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -997,7 +1006,6 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1022,7 +1030,6 @@ { "description": "empty tokens in $ref json-pointer", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "": { "$defs": { diff --git a/tests/draft2020-12/refRemote.json b/tests/draft2020-12/refRemote.json index 047ac74ca..ea4177f0a 100644 --- a/tests/draft2020-12/refRemote.json +++ b/tests/draft2020-12/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/integer" + "$ref": "http://localhost:1234/draft2020-12/subSchemas-defs.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft2020-12/subSchemas-defs.json#/$defs/refToInteger" }, "tests": [ { @@ -265,10 +265,7 @@ }, { "description": "remote HTTP ref with different $id", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/different-id-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -284,10 +281,7 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/urn-ref-string.json" - }, + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, "tests": [ { "description": "number is invalid", @@ -303,10 +297,7 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" - }, + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, "tests": [ { "description": "number is invalid", @@ -323,7 +314,6 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://localhost:1234/draft2020-12/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index f861cefad..2615c4c41 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -461,86 +461,6 @@ } ] }, - { - "description": "unevaluatedItems before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "prefixItems": [ - { "type": "string" } - ], - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "prefixItems": [ - true, - { "type": "string" } - ] - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": ["foo", "bar"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": ["foo", "bar", "baz"], - "valid": false - } - ] - }, - { - "description": "unevaluatedItems with $dynamicRef", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived", - - "$ref": "./baseSchema", - - "$defs": { - "derived": { - "$dynamicAnchor": "addons", - "prefixItems": [ - true, - { "type": "string" } - ] - }, - "baseSchema": { - "$id": "./baseSchema", - - "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", - "unevaluatedItems": false, - "type": "array", - "prefixItems": [ - { "type": "string" } - ], - "$dynamicRef": "#addons", - - "$defs": { - "defaultAddons": { - "$comment": "Needed to satisfy the bookending requirement", - "$dynamicAnchor": "addons" - } - } - } - } - }, - "tests": [ - { - "description": "with no unevaluated items", - "data": ["foo", "bar"], - "valid": true - }, - { - "description": "with unevaluated items", - "data": ["foo", "bar", "baz"], - "valid": false - } - ] - }, { "description": "unevaluatedItems can't see inside cousins", "schema": { @@ -793,6 +713,7 @@ "data": [ "b" ], "valid": false } + ] } ] diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json index ae29c9eb3..f7fb420ff 100644 --- a/tests/draft2020-12/unevaluatedProperties.json +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -715,99 +715,6 @@ } ] }, - { - "description": "unevaluatedProperties before $ref", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "unevaluatedProperties": false, - "properties": { - "foo": { "type": "string" } - }, - "$ref": "#/$defs/bar", - "$defs": { - "bar": { - "properties": { - "bar": { "type": "string" } - } - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar" - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar", - "baz": "baz" - }, - "valid": false - } - ] - }, - { - "description": "unevaluatedProperties with $dynamicRef", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/unevaluated-properties-with-dynamic-ref/derived", - - "$ref": "./baseSchema", - - "$defs": { - "derived": { - "$dynamicAnchor": "addons", - "properties": { - "bar": { "type": "string" } - } - }, - "baseSchema": { - "$id": "./baseSchema", - - "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", - "unevaluatedProperties": false, - "type": "object", - "properties": { - "foo": { "type": "string" } - }, - "$dynamicRef": "#addons", - - "$defs": { - "defaultAddons": { - "$comment": "Needed to satisfy the bookending requirement", - "$dynamicAnchor": "addons" - } - } - } - } - }, - "tests": [ - { - "description": "with no unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar" - }, - "valid": true - }, - { - "description": "with unevaluated properties", - "data": { - "foo": "foo", - "bar": "bar", - "baz": "baz" - }, - "valid": false - } - ] - }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1564,38 +1471,5 @@ "valid": false } ] - }, - { - "description": "dependentSchemas with unevaluatedProperties", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": {"foo2": {}}, - "dependentSchemas": { - "foo" : {}, - "foo2": { - "properties": { - "bar":{} - } - } - }, - "unevaluatedProperties": false - }, - "tests": [ - { - "description": "unevaluatedProperties doesn't consider dependentSchemas", - "data": {"foo": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties doesn't see bar when foo2 is absent", - "data": {"bar": ""}, - "valid": false - }, - { - "description": "unevaluatedProperties sees bar when foo2 is present", - "data": { "foo2": "", "bar": ""}, - "valid": true - } - ] } ] diff --git a/tests/draft2020-12/optional/unknownKeyword.json b/tests/draft2020-12/unknownKeyword.json similarity index 100% rename from tests/draft2020-12/optional/unknownKeyword.json rename to tests/draft2020-12/unknownKeyword.json diff --git a/tests/draft3/additionalItems.json b/tests/draft3/additionalItems.json index ab44a2eb3..0cb668701 100644 --- a/tests/draft3/additionalItems.json +++ b/tests/draft3/additionalItems.json @@ -110,25 +110,6 @@ } ] }, - { - "description": "additionalItems with heterogeneous array", - "schema": { - "items": [{}], - "additionalItems": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft3/maxLength.json b/tests/draft3/maxLength.json index b0a9ea5be..4de42bcab 100644 --- a/tests/draft3/maxLength.json +++ b/tests/draft3/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft3/minLength.json b/tests/draft3/minLength.json index 6652c7509..3f09158de 100644 --- a/tests/draft3/minLength.json +++ b/tests/draft3/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft3/optional/format/ecmascript-regex.json b/tests/draft3/optional/ecmascript-regex.json similarity index 100% rename from tests/draft3/optional/format/ecmascript-regex.json rename to tests/draft3/optional/ecmascript-regex.json diff --git a/tests/draft3/optional/format/host-name.json b/tests/draft3/optional/format/host-name.json index 9a75c3c20..d418f3763 100644 --- a/tests/draft3/optional/format/host-name.json +++ b/tests/draft3/optional/format/host-name.json @@ -57,11 +57,6 @@ "description": "exceeds maximum label length", "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", "valid": false - }, - { - "description": "empty string", - "data": "", - "valid": false } ] } diff --git a/tests/draft3/refRemote.json b/tests/draft3/refRemote.json index 81a6c5116..de0cb43a5 100644 --- a/tests/draft3/refRemote.json +++ b/tests/draft3/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/draft3/subSchemas.json#/definitions/integer"}, + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/draft3/subSchemas.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" }, "tests": [ { diff --git a/tests/draft4/additionalItems.json b/tests/draft4/additionalItems.json index c9e681549..deb44fd31 100644 --- a/tests/draft4/additionalItems.json +++ b/tests/draft4/additionalItems.json @@ -146,25 +146,6 @@ } ] }, - { - "description": "additionalItems with heterogeneous array", - "schema": { - "items": [{}], - "additionalItems": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft4/enum.json b/tests/draft4/enum.json index ce43acc02..f085097be 100644 --- a/tests/draft4/enum.json +++ b/tests/draft4/enum.json @@ -154,27 +154,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": {"enum": [[false]]}, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -196,27 +175,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": {"enum": [[true]]}, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -238,27 +196,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": {"enum": [[0]]}, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -280,27 +217,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": {"enum": [[1]]}, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft4/optional/id.json b/tests/draft4/id.json similarity index 100% rename from tests/draft4/optional/id.json rename to tests/draft4/id.json diff --git a/tests/draft4/maxLength.json b/tests/draft4/maxLength.json index 338795943..811d35b25 100644 --- a/tests/draft4/maxLength.json +++ b/tests/draft4/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft4/minLength.json b/tests/draft4/minLength.json index 6652c7509..3f09158de 100644 --- a/tests/draft4/minLength.json +++ b/tests/draft4/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft4/not.json b/tests/draft4/not.json index 525219cf2..cbb7f46bf 100644 --- a/tests/draft4/not.json +++ b/tests/draft4/not.json @@ -91,67 +91,6 @@ "valid": true } ] - }, - { - "description": "forbid everything with empty schema", - "schema": { "not": {} }, - "tests": [ - { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", - "data": "foo", - "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "double negation", - "schema": { "not": { "not": {} } }, - "tests": [ - { - "description": "any value is valid", - "data": "foo", - "valid": true - } - ] } + ] diff --git a/tests/draft4/oneOf.json b/tests/draft4/oneOf.json index 2487f0e38..fb63b0898 100644 --- a/tests/draft4/oneOf.json +++ b/tests/draft4/oneOf.json @@ -159,7 +159,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft4/optional/format/hostname.json b/tests/draft4/optional/format/hostname.json index 866a61788..a8ecd194f 100644 --- a/tests/draft4/optional/format/hostname.json +++ b/tests/draft4/optional/format/hostname.json @@ -112,16 +112,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft4/optional/format/ipv4.json b/tests/draft4/optional/format/ipv4.json index 9680fe620..4706581f2 100644 --- a/tests/draft4/optional/format/ipv4.json +++ b/tests/draft4/optional/format/ipv4.json @@ -78,11 +78,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 65e45190c..412c9ff83 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/draft4/subSchemas.json#/definitions/integer"}, + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/draft4/subSchemas.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "draft4/name.json#/definitions/orNull"} + "name": {"$ref": "name.json#/definitions/orNull"} } }, "tests": [ @@ -171,7 +171,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/draft4/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifierDraft4.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft6/additionalItems.json b/tests/draft6/additionalItems.json index 2c7d15582..cae72361c 100644 --- a/tests/draft6/additionalItems.json +++ b/tests/draft6/additionalItems.json @@ -169,25 +169,6 @@ } ] }, - { - "description": "additionalItems with heterogeneous array", - "schema": { - "items": [{}], - "additionalItems": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft6/enum.json b/tests/draft6/enum.json index ce43acc02..f085097be 100644 --- a/tests/draft6/enum.json +++ b/tests/draft6/enum.json @@ -154,27 +154,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": {"enum": [[false]]}, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -196,27 +175,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": {"enum": [[true]]}, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -238,27 +196,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": {"enum": [[0]]}, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -280,27 +217,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": {"enum": [[1]]}, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft6/optional/id.json b/tests/draft6/id.json similarity index 100% rename from tests/draft6/optional/id.json rename to tests/draft6/id.json diff --git a/tests/draft6/maxLength.json b/tests/draft6/maxLength.json index be60c5407..748b4daaf 100644 --- a/tests/draft6/maxLength.json +++ b/tests/draft6/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft6/minLength.json b/tests/draft6/minLength.json index 23c68fe3f..64db94805 100644 --- a/tests/draft6/minLength.json +++ b/tests/draft6/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft6/not.json b/tests/draft6/not.json index b46c4ed05..98de0eda8 100644 --- a/tests/draft6/not.json +++ b/tests/draft6/not.json @@ -93,161 +93,19 @@ ] }, { - "description": "forbid everything with empty schema", - "schema": { "not": {} }, + "description": "not with boolean schema true", + "schema": {"not": true}, "tests": [ { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", + "description": "any value is invalid", "data": "foo", "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "forbid everything with boolean schema true", - "schema": { "not": true }, - "tests": [ - { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", - "data": "foo", - "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "allow everything with boolean schema false", - "schema": { "not": false }, - "tests": [ - { - "description": "number is valid", - "data": 1, - "valid": true - }, - { - "description": "string is valid", - "data": "foo", - "valid": true - }, - { - "description": "boolean true is valid", - "data": true, - "valid": true - }, - { - "description": "boolean false is valid", - "data": false, - "valid": true - }, - { - "description": "null is valid", - "data": null, - "valid": true - }, - { - "description": "object is valid", - "data": {"foo": "bar"}, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "array is valid", - "data": ["foo"], - "valid": true - }, - { - "description": "empty array is valid", - "data": [], - "valid": true } ] }, { - "description": "double negation", - "schema": { "not": { "not": {} } }, + "description": "not with boolean schema false", + "schema": {"not": false}, "tests": [ { "description": "any value is valid", diff --git a/tests/draft6/oneOf.json b/tests/draft6/oneOf.json index c30a65c0d..eeb7ae866 100644 --- a/tests/draft6/oneOf.json +++ b/tests/draft6/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft6/optional/format/hostname.json b/tests/draft6/optional/format/hostname.json index 866a61788..a8ecd194f 100644 --- a/tests/draft6/optional/format/hostname.json +++ b/tests/draft6/optional/format/hostname.json @@ -112,16 +112,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft6/optional/format/ipv4.json b/tests/draft6/optional/format/ipv4.json index 9680fe620..4706581f2 100644 --- a/tests/draft6/optional/format/ipv4.json +++ b/tests/draft6/optional/format/ipv4.json @@ -78,11 +78,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft6/propertyNames.json b/tests/draft6/propertyNames.json index 7c7b80006..f0788e649 100644 --- a/tests/draft6/propertyNames.json +++ b/tests/draft6/propertyNames.json @@ -103,52 +103,5 @@ "valid": true } ] - }, - { - "description": "propertyNames with const", - "schema": {"propertyNames": {"const": "foo"}}, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"bar": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] - }, - { - "description": "propertyNames with enum", - "schema": {"propertyNames": {"enum": ["foo", "bar"]}}, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with property foo and bar is valid", - "data": {"foo": 1, "bar": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"baz": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 49ead6d1f..5d60fae11 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/draft6/subSchemas.json#/definitions/integer"}, + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/draft6/subSchemas.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "$id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "draft6/name.json#/definitions/orNull"} + "name": {"$ref": "name.json#/definitions/orNull"} } }, "tests": [ @@ -173,7 +173,7 @@ "schema": { "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", "allOf": [ - { "$ref": "draft6/ref-and-definitions.json" } + { "$ref": "ref-and-definitions.json" } ] }, "tests": [ @@ -196,7 +196,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/draft6/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft6/optional/unknownKeyword.json b/tests/draft6/unknownKeyword.json similarity index 100% rename from tests/draft6/optional/unknownKeyword.json rename to tests/draft6/unknownKeyword.json diff --git a/tests/draft7/additionalItems.json b/tests/draft7/additionalItems.json index 2c7d15582..cae72361c 100644 --- a/tests/draft7/additionalItems.json +++ b/tests/draft7/additionalItems.json @@ -169,25 +169,6 @@ } ] }, - { - "description": "additionalItems with heterogeneous array", - "schema": { - "items": [{}], - "additionalItems": false - }, - "tests": [ - { - "description": "heterogeneous invalid instance", - "data": [ "foo", "bar", 37 ], - "valid": false - }, - { - "description": "valid instance", - "data": [ null ], - "valid": true - } - ] - }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft7/enum.json b/tests/draft7/enum.json index ce43acc02..f085097be 100644 --- a/tests/draft7/enum.json +++ b/tests/draft7/enum.json @@ -154,27 +154,6 @@ } ] }, - { - "description": "enum with [false] does not match [0]", - "schema": {"enum": [[false]]}, - "tests": [ - { - "description": "[false] is valid", - "data": [false], - "valid": true - }, - { - "description": "[0] is invalid", - "data": [0], - "valid": false - }, - { - "description": "[0.0] is invalid", - "data": [0.0], - "valid": false - } - ] - }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -196,27 +175,6 @@ } ] }, - { - "description": "enum with [true] does not match [1]", - "schema": {"enum": [[true]]}, - "tests": [ - { - "description": "[true] is valid", - "data": [true], - "valid": true - }, - { - "description": "[1] is invalid", - "data": [1], - "valid": false - }, - { - "description": "[1.0] is invalid", - "data": [1.0], - "valid": false - } - ] - }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -238,27 +196,6 @@ } ] }, - { - "description": "enum with [0] does not match [false]", - "schema": {"enum": [[0]]}, - "tests": [ - { - "description": "[false] is invalid", - "data": [false], - "valid": false - }, - { - "description": "[0] is valid", - "data": [0], - "valid": true - }, - { - "description": "[0.0] is valid", - "data": [0.0], - "valid": true - } - ] - }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -280,27 +217,6 @@ } ] }, - { - "description": "enum with [1] does not match [true]", - "schema": {"enum": [[1]]}, - "tests": [ - { - "description": "[true] is invalid", - "data": [true], - "valid": false - }, - { - "description": "[1] is valid", - "data": [1], - "valid": true - }, - { - "description": "[1.0] is valid", - "data": [1.0], - "valid": true - } - ] - }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft7/optional/id.json b/tests/draft7/id.json similarity index 100% rename from tests/draft7/optional/id.json rename to tests/draft7/id.json diff --git a/tests/draft7/maxLength.json b/tests/draft7/maxLength.json index be60c5407..748b4daaf 100644 --- a/tests/draft7/maxLength.json +++ b/tests/draft7/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two graphemes is long enough", + "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft7/minLength.json b/tests/draft7/minLength.json index 23c68fe3f..64db94805 100644 --- a/tests/draft7/minLength.json +++ b/tests/draft7/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one grapheme is not long enough", + "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft7/not.json b/tests/draft7/not.json index b46c4ed05..98de0eda8 100644 --- a/tests/draft7/not.json +++ b/tests/draft7/not.json @@ -93,161 +93,19 @@ ] }, { - "description": "forbid everything with empty schema", - "schema": { "not": {} }, + "description": "not with boolean schema true", + "schema": {"not": true}, "tests": [ { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", + "description": "any value is invalid", "data": "foo", "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "forbid everything with boolean schema true", - "schema": { "not": true }, - "tests": [ - { - "description": "number is invalid", - "data": 1, - "valid": false - }, - { - "description": "string is invalid", - "data": "foo", - "valid": false - }, - { - "description": "boolean true is invalid", - "data": true, - "valid": false - }, - { - "description": "boolean false is invalid", - "data": false, - "valid": false - }, - { - "description": "null is invalid", - "data": null, - "valid": false - }, - { - "description": "object is invalid", - "data": {"foo": "bar"}, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, - { - "description": "array is invalid", - "data": ["foo"], - "valid": false - }, - { - "description": "empty array is invalid", - "data": [], - "valid": false - } - ] - }, - { - "description": "allow everything with boolean schema false", - "schema": { "not": false }, - "tests": [ - { - "description": "number is valid", - "data": 1, - "valid": true - }, - { - "description": "string is valid", - "data": "foo", - "valid": true - }, - { - "description": "boolean true is valid", - "data": true, - "valid": true - }, - { - "description": "boolean false is valid", - "data": false, - "valid": true - }, - { - "description": "null is valid", - "data": null, - "valid": true - }, - { - "description": "object is valid", - "data": {"foo": "bar"}, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "array is valid", - "data": ["foo"], - "valid": true - }, - { - "description": "empty array is valid", - "data": [], - "valid": true } ] }, { - "description": "double negation", - "schema": { "not": { "not": {} } }, + "description": "not with boolean schema false", + "schema": {"not": false}, "tests": [ { "description": "any value is valid", diff --git a/tests/draft7/oneOf.json b/tests/draft7/oneOf.json index c30a65c0d..eeb7ae866 100644 --- a/tests/draft7/oneOf.json +++ b/tests/draft7/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft7/optional/format/hostname.json b/tests/draft7/optional/format/hostname.json index 866a61788..a8ecd194f 100644 --- a/tests/draft7/optional/format/hostname.json +++ b/tests/draft7/optional/format/hostname.json @@ -112,16 +112,6 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - }, - { - "description": "single dot", - "data": ".", - "valid": false } ] } diff --git a/tests/draft7/optional/format/idn-hostname.json b/tests/draft7/optional/format/idn-hostname.json index 5c8cdc77b..6c8f86a3a 100644 --- a/tests/draft7/optional/format/idn-hostname.json +++ b/tests/draft7/optional/format/idn-hostname.json @@ -254,7 +254,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0628\u0660\u06f0", + "data": "\u0660\u06f0", "valid": false }, { @@ -298,80 +298,6 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true - }, - { - "description": "single label", - "data": "hostname", - "valid": true - }, - { - "description": "single label with hyphen", - "data": "host-name", - "valid": true - }, - { - "description": "single label with digits", - "data": "h0stn4me", - "valid": true - }, - { - "description": "single label ending with digit", - "data": "hostnam3", - "valid": true - }, - { - "description": "empty string", - "data": "", - "valid": false - } - ] - }, - { - "description": "validation of separators in internationalized host names", - "specification": [ - {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} - ], - "schema": { "format": "idn-hostname" }, - "tests": [ - { - "description": "single dot", - "data": ".", - "valid": false - }, - { - "description": "single ideographic full stop", - "data": "\u3002", - "valid": false - }, - { - "description": "single fullwidth full stop", - "data": "\uff0e", - "valid": false - }, - { - "description": "single halfwidth ideographic full stop", - "data": "\uff61", - "valid": false - }, - { - "description": "dot as label separator", - "data": "a.b", - "valid": true - }, - { - "description": "ideographic full stop as label separator", - "data": "a\u3002b", - "valid": true - }, - { - "description": "fullwidth full stop as label separator", - "data": "a\uff0eb", - "valid": true - }, - { - "description": "halfwidth ideographic full stop as label separator", - "data": "a\uff61b", - "valid": true } ] } diff --git a/tests/draft7/optional/format/ipv4.json b/tests/draft7/optional/format/ipv4.json index 9680fe620..4706581f2 100644 --- a/tests/draft7/optional/format/ipv4.json +++ b/tests/draft7/optional/format/ipv4.json @@ -78,11 +78,6 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false - }, - { - "description": "netmask is not a part of ipv4 address", - "data": "192.168.1.0/24", - "valid": false } ] } diff --git a/tests/draft7/propertyNames.json b/tests/draft7/propertyNames.json index 7c7b80006..f0788e649 100644 --- a/tests/draft7/propertyNames.json +++ b/tests/draft7/propertyNames.json @@ -103,52 +103,5 @@ "valid": true } ] - }, - { - "description": "propertyNames with const", - "schema": {"propertyNames": {"const": "foo"}}, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"bar": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] - }, - { - "description": "propertyNames with enum", - "schema": {"propertyNames": {"enum": ["foo", "bar"]}}, - "tests": [ - { - "description": "object with property foo is valid", - "data": {"foo": 1}, - "valid": true - }, - { - "description": "object with property foo and bar is valid", - "data": {"foo": 1, "bar": 1}, - "valid": true - }, - { - "description": "object with any other property is invalid", - "data": {"baz": 1}, - "valid": false - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - } - ] } ] diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index 450787af6..115e12e74 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/draft7/subSchemas.json#/definitions/integer"}, + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/draft7/subSchemas.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "$id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "draft7/name.json#/definitions/orNull"} + "name": {"$ref": "name.json#/definitions/orNull"} } }, "tests": [ @@ -173,7 +173,7 @@ "schema": { "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", "allOf": [ - { "$ref": "draft7/ref-and-definitions.json" } + { "$ref": "ref-and-definitions.json" } ] }, "tests": [ @@ -196,7 +196,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/draft7/locationIndependentIdentifier.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft7/optional/unknownKeyword.json b/tests/draft7/unknownKeyword.json similarity index 100% rename from tests/draft7/optional/unknownKeyword.json rename to tests/draft7/unknownKeyword.json From e3bc2dcda731844a21b4b20633386f65efd9c3f3 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 11:13:05 +0200 Subject: [PATCH 5/9] Adapt test case generation from suite --- jsonschema/tests/test_jsonschema_test_suite.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 41c982553..9ff067f33 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -136,7 +136,6 @@ def leap_second(test): DRAFT4.format_cases(), DRAFT4.optional_cases_of(name="bignum"), DRAFT4.optional_cases_of(name="float-overflow"), - DRAFT4.optional_cases_of(name="id"), DRAFT4.optional_cases_of(name="non-bmp-regex"), DRAFT4.optional_cases_of(name="zeroTerminatedFloats"), Validator=jsonschema.Draft4Validator, @@ -155,7 +154,6 @@ def leap_second(test): DRAFT6.format_cases(), DRAFT6.optional_cases_of(name="bignum"), DRAFT6.optional_cases_of(name="float-overflow"), - DRAFT6.optional_cases_of(name="id"), DRAFT6.optional_cases_of(name="non-bmp-regex"), Validator=jsonschema.Draft6Validator, format_checker=jsonschema.Draft6Validator.FORMAT_CHECKER, @@ -174,9 +172,7 @@ def leap_second(test): DRAFT7.optional_cases_of(name="bignum"), DRAFT7.optional_cases_of(name="cross-draft"), DRAFT7.optional_cases_of(name="float-overflow"), - DRAFT6.optional_cases_of(name="id"), DRAFT7.optional_cases_of(name="non-bmp-regex"), - DRAFT7.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft7Validator, format_checker=jsonschema.Draft7Validator.FORMAT_CHECKER, skip=lambda test: ( @@ -190,15 +186,12 @@ def leap_second(test): TestDraft201909 = DRAFT201909.to_unittest_testcase( DRAFT201909.cases(), - DRAFT201909.optional_cases_of(name="anchor"), DRAFT201909.optional_cases_of(name="bignum"), DRAFT201909.optional_cases_of(name="cross-draft"), DRAFT201909.optional_cases_of(name="float-overflow"), - DRAFT201909.optional_cases_of(name="id"), DRAFT201909.optional_cases_of(name="no-schema"), DRAFT201909.optional_cases_of(name="non-bmp-regex"), DRAFT201909.optional_cases_of(name="refOfUnknownKeyword"), - DRAFT201909.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft201909Validator, skip=skip( message="Vocabulary support is still in-progress.", @@ -227,15 +220,12 @@ def leap_second(test): TestDraft202012 = DRAFT202012.to_unittest_testcase( DRAFT202012.cases(), - DRAFT201909.optional_cases_of(name="anchor"), DRAFT202012.optional_cases_of(name="bignum"), DRAFT202012.optional_cases_of(name="cross-draft"), DRAFT202012.optional_cases_of(name="float-overflow"), - DRAFT202012.optional_cases_of(name="id"), DRAFT202012.optional_cases_of(name="no-schema"), DRAFT202012.optional_cases_of(name="non-bmp-regex"), DRAFT202012.optional_cases_of(name="refOfUnknownKeyword"), - DRAFT202012.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft202012Validator, skip=skip( message="Vocabulary support is still in-progress.", From 2b6d928692e6faf2a6b27c270b36c18cf4d9beca Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Tue, 29 Apr 2025 12:03:41 +0200 Subject: [PATCH 6/9] Revert "Add test for unevaluatedProperties" This reverts commit 75218a4c4632ecafa722724fd338dc3598625764. --- jsonschema/tests/test_validators.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 309229ee6..28cc40273 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -742,14 +742,6 @@ def test_unevaluated_properties_on_invalid_type(self): message = self.message_for(instance="foo", schema=schema) self.assertEqual(message, "'foo' is not of type 'object'") - def test_unevaluated_properties_with_additional_properties(self): - schema = { - "additionalProperties": {"type": "string"}, - "unevaluatedProperties": False, - } - validator = validators._LATEST_VERSION(schema) - validator.validate(instance={"foo": "foo"}) - def test_single_item(self): schema = {"prefixItems": [{}], "items": False} message = self.message_for( From e68b54949f503c0f3c599da5b8b4d265ed9a6eb7 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Mon, 26 May 2025 11:12:55 +0200 Subject: [PATCH 7/9] Move is_valid function to module scope --- jsonschema/_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 61defd303..84a0965e5 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -270,10 +270,6 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema): return [] evaluated_keys = [] - def is_valid(errs_it): - """Whether there are no errors in the given iterator.""" - return next(errs_it, None) is None - ref = schema.get("$ref") if ref is not None: resolved = validator._resolver.lookup(ref) @@ -352,3 +348,8 @@ def is_valid(errs_it): ) return evaluated_keys + + +def is_valid(errs_it): + """Whether there are no errors in the given iterator.""" + return next(errs_it, None) is None From 56ee673df89298879feb9d7fc5737050d64bf94f Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Mon, 26 May 2025 11:32:11 +0200 Subject: [PATCH 8/9] Squashed 'json/' changes from ab3924a6..9ad349be 9ad349be Merge pull request #773 from jdesrosiers/annotation-propname-desc f164982c Merge pull request #771 from bavulapati/add-blaze-as-consumer d2bd2ad2 Update annotation test description for propertyNames a7a64707 Add [Blaze](https://github.com/sourcemeta/blaze) to the README 9f256c88 Change "expected" to an object with schema locations 7f996868 Update content tests to only apply to string instances 5338ecd1 Remove tests that assert a keyword doesn't emit annotations 738653b5 Make order of assertion properties consistent 8b5de3b9 Updates based on feedback from Juan 6270e399 Updates based on feedback from Karen 341df3ec Add automation to check that annotation tests are valid 16988c67 Add annotation tests bc919bdb Merge pull request #755 from V02460/unevaluated-additional-properties 83e866b4 Merge pull request #763 from michaelmior/propertynames-const c5a9703f Merge pull request #760 from OptimumCode/rfc3490-label-separator b4c09b65 Add tests for propertyNames with const/enum 4fa572d8 Move tests for rfc3490#3.1 into a separate test case ce9f68ca Add link to rfc and quote ad94cacc Add test cases for other valid label separators in IDN hostnames 39002ae7 Merge pull request #762 from OptimumCode/rfc-html-link c8780535 Correct section anchor for rfc URL template 5f2ca7d6 Modify rfc url template to use html version 9c5d99b6 Merge pull request #761 from OptimumCode/annotation-script-rfc-support 9563ce7b Correct rfc URL template - incorrect path pattern was used 961bfad0 Correct spec kind extraction from defined key. Continue on unkown URL kind e524505b Merge pull request #759 from sirosen/hostname-format-reject-single-dot 4a3efd18 Add negative tests for "." for hostname formats 4ba013d5 Merge pull request #747 from santhosh-tekuri/duration aa500e80 Merge pull request #749 from json-schema-org/gregsdennis/json-everything-update eb8ce976 Merge pull request #757 from ajevans99/main dcdae5c0 Merge pull request #758 from sirosen/hostname-format-check-empty-string db21d21b Merge branch 'main' into hostname-format-check-empty-string 3fd78f04 Merge pull request #1 from ajevans99/swift-json-schema 3cada3a9 Update README.md 5273e0d6 Make test descriptions more specific 43828fee Simplify adjacent additionalProperties test 347d6099 unevaluatedProperties: Remove type keywords 7dfbb1e9 Add test for unevaluatedProperties 82a07749 Merge pull request #753 from json-schema-org/ether/fix-draft-locations a66d23d4 move draft-specific files to the dedicated dir for its draft 8ef15501 Merge pull request #751 from big-andy-coates/format_tests_under_format fe1b1392 All format test cases should be under the `format` directory. b1ee90f6 json-everything moved to an org c00a3f94 test: duration format must start with P 9fc880bf Merge pull request #740 from notEthan/format-pattern-control-char cbd48ea5 Simplify test of \a regex character to test directly against `pattern` schema d6f1010a Merge pull request #746 from json-schema-org/annotations 4aec22c1 Revert the changes to additionalProperties.json. 2dc10671 Move the workflow step title. d9ce71ac May as well also show quotes in the annotation. 1b719a84 Pick the line after the description when attaching spec annotations. 08105151 Markdown is apparently not (yet?) supported in annotations. 81645773 Tidy up the specification annotator a bit. 38628b79 Make the spec URLs structure a bit easier for internal use. 4ebbeaf4 Merge branch 'Era-cell/main' e4bd7554 dumbness2 corrected d8ade402 inside run 57c7c869 changed install location 11f8e511 Added installing command in workflow f2766616 template library, url loads changes c2badb12 Merge pull request #734 from OptimumCode/idn-hostname-arabic-indic-mixed dd9599a5 Merge branch 'main' of github.com:json-schema-org/JSON-Schema-Test-Suite 5b393436 add pr dependencies action 3a509007 Clear existin annotations on same PR 23674123 Cases for rfc and iso written separately 0b780b2c Corected yaml format 2b1ffb74 Best practices followed with optimized code e88a2da6 Works for all OS 7b40efe4 Base path for neighbouring file? 564e6957 Walking through all leaf files 7b84fb44 Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite 891d0265 First workflow2 1c175195 regex correction 96f7683a Final correction2 - file names beautufied 5f050a07 Final correction1 77527b63 Stupidity corrected eb8fd760 Branch name specified 540a269b Log2 f29d090a Wrong location sepcification 582e12be logging logs check df3bdecc path corrected c6b937ca Reading all jsons and spec urls added cbdd1755 change day2 54f3784a Merge pull request #731 from MeastroZI/main 79dc92f1 TOKEN ce52852d Python file location changed 3558c2c6 Fake add to tests eecc7b7a Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite 810d148a First workflow2 4eac02c7 First workflow ff29264c Merge pull request #741 from harrel56/chore/tabs-to-spaces 9f39cf73 use spaces instead of tabs 2f3b5f7a Corrected replaced unevaluated with additoinalProperties 40bcb8b3 Corrected replaced unevaluated with additoinalProperties fa9224d7 Merge pull request #732 from MeastroZI/main2 83bedd5c Changing descriptions 49f73429 fixing tests e6d6a081 adding more test cases 7e6c9be6 changing descriptions 959aca92 shifting test 605d7d78 Update propertyDependencies.json : test must be tests deb82824 test for dependentSchema and propertyDependencies with unevaluatedProperties and additionalProperties ea485124 Merge branch 'json-schema-org:main' into main 64a3e7b3 Merge pull request #721 from json-schema-org/gregsdennis/dynamicref-skips-resources b9f14e64 Fix $schema in new new test 3d5048e8 Merge pull request #733 from Era-cell/main 4ae14268 Add valid first character to avoid Bidi rule violation 2480edba Update additionalProperties.json formatting it 6aa79c0b Update additionalProperties.json formatting it 3e0139a5 Update tests/draft-next/additionalProperties.json 616240b0 Update tests/draft-next/additionalProperties.json c5f3e4ea Update tests/draft2020-12/propertyNames.json 964efb8e propertyNames doesn't affect additionalProperties, tests exist already for unevaluatedProps f08b884c Cases go under additional and unevaluated Properties 99864ff6 added tests for propertyNames with additionalProperties/unevaluatedProperties, also with specification property 3b5782b6 Update ref.json : changing $Ids 546b3561 test for $ref with $recursiveAnchor 57617f25 Merge pull request #726 from Era-cell/main 51fc69cd meta data and property names constraints added, additional Items: string 9b169bed specification takes array of objects having section and quote 1362a8cc Pattern for para corrected 340116ec Schema of specification in much structured 003ac021 Test-schema including sub-schema for scpecification 50a20280 adding specification enhancement for additionalProperties 604f5f99 Drop tests of `$id` and `$anchor` that just test values against meta-schema `pattern` for those properties 9cd64ec9 come on man, save all the files f494440e use unique $id in optional tests, too 468453b0 use unique $id 9ec6d17e fix copy/paste error b284f423 add tests for $dynamicRef skipping over resources bf0360f4 add $recursiveAnchor to 2019-09 meta-schemas 0519d1f0 add $dynamicAnchor to meta-schemas b41167c7 Merge pull request #714 from json-schema-org/more-not 4221a55a Add tests for not: {} schemas for all values. c499d1d2 Merge pull request #713 from spacether/patch-1 24a471bd Update README.md 544f7c3d Merge pull request #712 from otto-ifak/main 9dad3ebe Add tests for enum with array of bool 589a0858 Merge pull request #706 from marksparkza/unevaluated-before-ref 64d5cab9 Merge pull request #710 from spacether/patch-1 418cdbd6 Removes idea folder e0a9e066 Updates all other tests to mention grapheme/graphemes 217bf81b Merge pull request #701 from json-schema-org/ether/dynamicRef-boolean 7a3d06d7 I remove a test that doesn't make sense. e8bf453d Move tests with ids in non-schemas to optional 69136952 Update minLength.json d545be21 Fix duplidate identifiers in recently added tests 4e9640c8 test when $dynamicRef references a boolean schema 3dab98ca Merge pull request #705 from json-schema-org/gregsdennis/remove-contains-objects-tests 1d3aa495 remove more maxContains 4a2c61e8 Test unevaluatedItems|Properties before $ref ec553d76 contains no longer applies to objects 0433a2bf Merge pull request #704 from big-andy-coates/clarify-format-requirements c685195f Merge pull request #703 from big-andy-coates/link-to-creek-validator-comprison-site a46174b0 Add more detail around test runner requirements for `format` tests bb1de8a9 The site linked to is a data-driven functional and performance benchmark of JVM based validator implementations. d38ddd54 Merge pull request #696 from jdesrosiers/unevaluated-dynamicref 5d0c05fa Fix copy/paste error 95fe6ca2 Merge pull request #694 from json-schema-org/heterogeneous-additionalItems 9c88a0be Merge pull request #697 from json-schema-org/gregsdennis/add-ref-into-known-nonapplicator 49222046 Add unevaluted with dynamic ref tests to draft-next 8ba1c90d Update unevaluted with dynamic ref to be more likely to catch errors fea2cf19 add tests for 2019 and 2020 6695ca38 add optional tests for `$ref`ing into known non-applicator keywords 2834c630 Add tests for unevaluated with dynamic reference cda4281c Merge pull request #695 from json-schema-org/ether/clean-up-subSchemas 7b9f45c2 move subSchemas-defs.json to subSchemas.json e41ec0ec remove unused definition files 349c5a82 Merge pull request #692 from json-schema-org/ether/fix-subSchemas-refs 451baca4 Merge pull request #670 from marksparkza/invalid-output-test b8da838a Add tests for heterogeneous arrays with additionalItems 6d7a44b7 fix subschema locations and their $refs a9a1e2e3 Merge pull request #690 from skryukov/add-ipv4-mask-test ba52c48a Merge pull request #689 from skryukov/add-schema-keyword-to-required-tests 69b53add Add a test case for ipv4 with netmask d0c602a7 Add $schema keyword to required tests 20f1f52c Merge pull request #688 from spacether/feat_updates_python_exp_impl b087b3ca Updates implmentation 4ecd01f3 Merge pull request #687 from swaeberle/check-single-label-idn-hostnames 732e7275 test single label IDN hostnames 202d5625 test: hostname format check fails on empty string ea0b63c9 Remove invalid output tests git-subtree-dir: json git-subtree-split: 9ad349be933f1e74810cb4fd3ad19780694dc77e --- .github/workflows/annotation-tests.yml | 21 + .github/workflows/pr-dependencies.yml | 12 + .../show_specification_annotations.yml | 21 + README.md | 17 +- annotations/README.md | 116 +++ annotations/assertion.schema.json | 24 + annotations/test-case.schema.json | 38 + annotations/test-suite.schema.json | 15 + annotations/test.schema.json | 16 + annotations/tests/applicators.json | 409 +++++++++++ annotations/tests/content.json | 121 ++++ annotations/tests/core.json | 30 + annotations/tests/format.json | 26 + annotations/tests/meta-data.json | 150 ++++ annotations/tests/unevaluated.json | 661 ++++++++++++++++++ annotations/tests/unknown.json | 27 + bin/annotate-specification-links | 140 ++++ bin/annotation-tests.ts | 31 + bin/specification_urls.json | 34 + output-tests/draft2019-09/content/type.json | 26 - output-tests/draft2020-12/content/type.json | 26 - .../draft-next/format-assertion-false.json | 1 + remotes/draft-next/format-assertion-true.json | 1 + .../draft-next/metaschema-no-validation.json | 1 + .../metaschema-optional-vocabulary.json | 1 + remotes/draft-next/subSchemas-defs.json | 11 - remotes/draft-next/subSchemas.json | 12 +- .../metaschema-no-validation.json | 1 + .../metaschema-optional-vocabulary.json | 1 + remotes/draft2019-09/subSchemas-defs.json | 11 - remotes/draft2019-09/subSchemas.json | 12 +- .../draft2020-12/format-assertion-false.json | 1 + .../draft2020-12/format-assertion-true.json | 1 + .../metaschema-no-validation.json | 1 + .../metaschema-optional-vocabulary.json | 1 + remotes/draft2020-12/subSchemas-defs.json | 11 - remotes/draft2020-12/subSchemas.json | 12 +- .../subSchemas.json} | 4 +- .../locationIndependentIdentifier.json} | 0 remotes/{ => draft4}/name.json | 0 remotes/draft4/subSchemas.json | 10 + .../locationIndependentIdentifier.json} | 0 remotes/draft6/name.json | 15 + remotes/{ => draft6}/ref-and-definitions.json | 2 +- remotes/draft6/subSchemas.json | 10 + .../draft7/locationIndependentIdentifier.json | 11 + remotes/draft7/name.json | 15 + remotes/draft7/ref-and-definitions.json | 11 + remotes/draft7/subSchemas.json | 10 + remotes/subSchemas.json | 8 - test-schema.json | 63 ++ tests/draft-next/additionalProperties.json | 92 +++ tests/draft-next/anchor.json | 114 --- tests/draft-next/contains.json | 104 +-- tests/draft-next/dependentSchemas.json | 1 + tests/draft-next/dynamicRef.json | 85 +++ tests/draft-next/enum.json | 96 +++ tests/draft-next/id.json | 294 -------- tests/draft-next/items.json | 20 + tests/draft-next/maxContains.json | 50 -- tests/draft-next/maxLength.json | 2 +- tests/draft-next/minLength.json | 2 +- tests/draft-next/oneOf.json | 2 +- tests/draft-next/optional/anchor.json | 60 ++ tests/draft-next/optional/dynamicRef.json | 56 ++ .../draft-next/optional/ecmascript-regex.json | 14 - .../draft-next/optional/format/duration.json | 5 + .../optional/format/ecmascript-regex.json | 16 + .../draft-next/optional/format/hostname.json | 10 + .../optional/format/idn-hostname.json | 84 ++- tests/draft-next/optional/format/ipv4.json | 5 + tests/draft-next/optional/id.json | 53 ++ .../optional/refOfUnknownKeyword.json | 23 + .../{ => optional}/unknownKeyword.json | 0 tests/draft-next/ref.json | 8 + tests/draft-next/refRemote.json | 20 +- tests/draft-next/unevaluatedItems.json | 73 ++ tests/draft-next/unevaluatedProperties.json | 206 ++++-- tests/draft2019-09/additionalItems.json | 20 + tests/draft2019-09/additionalProperties.json | 57 ++ tests/draft2019-09/anchor.json | 115 --- tests/draft2019-09/dependentSchemas.json | 1 + tests/draft2019-09/enum.json | 96 +++ tests/draft2019-09/id.json | 294 -------- tests/draft2019-09/maxLength.json | 2 +- tests/draft2019-09/minLength.json | 2 +- tests/draft2019-09/not.json | 154 +++- tests/draft2019-09/oneOf.json | 2 +- tests/draft2019-09/optional/anchor.json | 60 ++ .../optional/format/duration.json | 5 + .../optional/format/hostname.json | 10 + .../optional/format/idn-hostname.json | 84 ++- tests/draft2019-09/optional/format/ipv4.json | 5 + tests/draft2019-09/optional/id.json | 53 ++ .../optional/refOfUnknownKeyword.json | 23 + .../{ => optional}/unknownKeyword.json | 0 tests/draft2019-09/propertyNames.json | 53 ++ tests/draft2019-09/ref.json | 63 +- tests/draft2019-09/refRemote.json | 20 +- tests/draft2019-09/unevaluatedItems.json | 76 ++ tests/draft2019-09/unevaluatedProperties.json | 129 ++++ tests/draft2020-12/additionalProperties.json | 67 +- tests/draft2020-12/anchor.json | 115 --- tests/draft2020-12/dependentSchemas.json | 1 + tests/draft2020-12/dynamicRef.json | 85 +++ tests/draft2020-12/enum.json | 96 +++ tests/draft2020-12/id.json | 294 -------- tests/draft2020-12/items.json | 20 + tests/draft2020-12/maxLength.json | 2 +- tests/draft2020-12/minLength.json | 2 +- tests/draft2020-12/not.json | 154 +++- tests/draft2020-12/oneOf.json | 2 +- tests/draft2020-12/optional/anchor.json | 60 ++ tests/draft2020-12/optional/dynamicRef.json | 56 ++ .../optional/ecmascript-regex.json | 14 - .../optional/format/duration.json | 5 + .../optional/format/ecmascript-regex.json | 16 + .../optional/format/hostname.json | 10 + .../optional/format/idn-hostname.json | 84 ++- tests/draft2020-12/optional/format/ipv4.json | 5 + tests/draft2020-12/optional/id.json | 53 ++ .../optional/refOfUnknownKeyword.json | 23 + .../{ => optional}/unknownKeyword.json | 0 tests/draft2020-12/propertyNames.json | 83 +++ tests/draft2020-12/ref.json | 23 +- tests/draft2020-12/refRemote.json | 20 +- tests/draft2020-12/unevaluatedItems.json | 81 ++- tests/draft2020-12/unevaluatedProperties.json | 184 ++++- tests/draft3/additionalItems.json | 19 + tests/draft3/maxLength.json | 2 +- tests/draft3/minLength.json | 2 +- .../{ => format}/ecmascript-regex.json | 0 tests/draft3/optional/format/host-name.json | 5 + tests/draft3/refRemote.json | 4 +- tests/draft4/additionalItems.json | 19 + tests/draft4/enum.json | 84 +++ tests/draft4/maxLength.json | 2 +- tests/draft4/minLength.json | 2 +- tests/draft4/not.json | 63 +- tests/draft4/oneOf.json | 2 +- tests/draft4/optional/format/hostname.json | 10 + tests/draft4/optional/format/ipv4.json | 5 + tests/draft4/{ => optional}/id.json | 0 tests/draft4/refRemote.json | 8 +- tests/draft6/additionalItems.json | 19 + tests/draft6/enum.json | 84 +++ tests/draft6/maxLength.json | 2 +- tests/draft6/minLength.json | 2 +- tests/draft6/not.json | 152 +++- tests/draft6/oneOf.json | 2 +- tests/draft6/optional/format/hostname.json | 10 + tests/draft6/optional/format/ipv4.json | 5 + tests/draft6/{ => optional}/id.json | 0 .../draft6/{ => optional}/unknownKeyword.json | 0 tests/draft6/propertyNames.json | 47 ++ tests/draft6/refRemote.json | 10 +- tests/draft7/additionalItems.json | 19 + tests/draft7/enum.json | 84 +++ tests/draft7/maxLength.json | 2 +- tests/draft7/minLength.json | 2 +- tests/draft7/not.json | 152 +++- tests/draft7/oneOf.json | 2 +- tests/draft7/optional/format/hostname.json | 10 + .../draft7/optional/format/idn-hostname.json | 76 +- tests/draft7/optional/format/ipv4.json | 5 + tests/draft7/{ => optional}/id.json | 0 .../draft7/{ => optional}/unknownKeyword.json | 0 tests/draft7/propertyNames.json | 47 ++ tests/draft7/refRemote.json | 10 +- 169 files changed, 5845 insertions(+), 1697 deletions(-) create mode 100644 .github/workflows/annotation-tests.yml create mode 100644 .github/workflows/pr-dependencies.yml create mode 100644 .github/workflows/show_specification_annotations.yml create mode 100644 annotations/README.md create mode 100644 annotations/assertion.schema.json create mode 100644 annotations/test-case.schema.json create mode 100644 annotations/test-suite.schema.json create mode 100644 annotations/test.schema.json create mode 100644 annotations/tests/applicators.json create mode 100644 annotations/tests/content.json create mode 100644 annotations/tests/core.json create mode 100644 annotations/tests/format.json create mode 100644 annotations/tests/meta-data.json create mode 100644 annotations/tests/unevaluated.json create mode 100644 annotations/tests/unknown.json create mode 100755 bin/annotate-specification-links create mode 100755 bin/annotation-tests.ts create mode 100644 bin/specification_urls.json delete mode 100644 remotes/draft-next/subSchemas-defs.json delete mode 100644 remotes/draft2019-09/subSchemas-defs.json delete mode 100644 remotes/draft2020-12/subSchemas-defs.json rename remotes/{subSchemas-defs.json => draft3/subSchemas.json} (62%) rename remotes/{locationIndependentIdentifierDraft4.json => draft4/locationIndependentIdentifier.json} (100%) rename remotes/{ => draft4}/name.json (100%) create mode 100644 remotes/draft4/subSchemas.json rename remotes/{locationIndependentIdentifierPre2019.json => draft6/locationIndependentIdentifier.json} (100%) create mode 100644 remotes/draft6/name.json rename remotes/{ => draft6}/ref-and-definitions.json (74%) create mode 100644 remotes/draft6/subSchemas.json create mode 100644 remotes/draft7/locationIndependentIdentifier.json create mode 100644 remotes/draft7/name.json create mode 100644 remotes/draft7/ref-and-definitions.json create mode 100644 remotes/draft7/subSchemas.json delete mode 100644 remotes/subSchemas.json delete mode 100644 tests/draft-next/id.json create mode 100644 tests/draft-next/optional/anchor.json create mode 100644 tests/draft-next/optional/dynamicRef.json create mode 100644 tests/draft-next/optional/format/ecmascript-regex.json create mode 100644 tests/draft-next/optional/id.json rename tests/draft-next/{ => optional}/unknownKeyword.json (100%) delete mode 100644 tests/draft2019-09/id.json create mode 100644 tests/draft2019-09/optional/anchor.json create mode 100644 tests/draft2019-09/optional/id.json rename tests/draft2019-09/{ => optional}/unknownKeyword.json (100%) delete mode 100644 tests/draft2020-12/id.json create mode 100644 tests/draft2020-12/optional/anchor.json create mode 100644 tests/draft2020-12/optional/dynamicRef.json create mode 100644 tests/draft2020-12/optional/format/ecmascript-regex.json create mode 100644 tests/draft2020-12/optional/id.json rename tests/draft2020-12/{ => optional}/unknownKeyword.json (100%) rename tests/draft3/optional/{ => format}/ecmascript-regex.json (100%) rename tests/draft4/{ => optional}/id.json (100%) rename tests/draft6/{ => optional}/id.json (100%) rename tests/draft6/{ => optional}/unknownKeyword.json (100%) rename tests/draft7/{ => optional}/id.json (100%) rename tests/draft7/{ => optional}/unknownKeyword.json (100%) diff --git a/.github/workflows/annotation-tests.yml b/.github/workflows/annotation-tests.yml new file mode 100644 index 000000000..16de7b169 --- /dev/null +++ b/.github/workflows/annotation-tests.yml @@ -0,0 +1,21 @@ +name: Validate annotation tests + +on: + pull_request: + paths: + - "annotations/**" + +jobs: + annotate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Deno + uses: denoland/setup-deno@v2 + with: + deno-version: "2.x" + + - name: Validate annotation tests + run: deno --node-modules-dir=auto --allow-read --no-prompt bin/annotation-tests.ts diff --git a/.github/workflows/pr-dependencies.yml b/.github/workflows/pr-dependencies.yml new file mode 100644 index 000000000..34a231dcb --- /dev/null +++ b/.github/workflows/pr-dependencies.yml @@ -0,0 +1,12 @@ +name: Check PR Dependencies + +on: pull_request + +jobs: + check_dependencies: + runs-on: ubuntu-latest + name: Check Dependencies + steps: + - uses: gregsdennis/dependencies-action@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml new file mode 100644 index 000000000..f7d7b398b --- /dev/null +++ b/.github/workflows/show_specification_annotations.yml @@ -0,0 +1,21 @@ +name: Show Specification Annotations + +on: + pull_request: + paths: + - 'tests/**' + +jobs: + annotate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Generate Annotations + run: pip install uritemplate && bin/annotate-specification-links diff --git a/README.md b/README.md index cdd5dc8a4..9f4c516db 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ To test a specific version: * For 2019-09 and later published drafts, implementations that are able to detect the draft of each schema via `$schema` SHOULD be configured to do so * For draft-07 and earlier, draft-next, and implementations unable to detect via `$schema`, implementations MUST be configured to expect the draft matching the test directory name -* Load any remote references [described below](additional-assumptions) and configure your implementation to retrieve them via their URIs +* 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: @@ -159,7 +159,7 @@ If your implementation supports multiple versions, run the above procedure for e ``` 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). + In particular, when running tests within the `optional/format` subdirectory, test runners should configure implementations to enable format validation, where the implementation supports it. ### Invariants & Guarantees @@ -227,6 +227,7 @@ This suite is being used by: ### C++ +* [Blaze](https://github.com/sourcemeta/blaze) * [Modern C++ JSON schema validator](https://github.com/pboettch/json-schema-validator) * [Valijson](https://github.com/tristanpenman/valijson) @@ -254,12 +255,14 @@ This suite is being used by: ### Java +* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) * [json-schema-validator](https://github.com/daveclayton/json-schema-validator) * [everit-org/json-schema](https://github.com/everit-org/json-schema) * [networknt/json-schema-validator](https://github.com/networknt/json-schema-validator) * [Justify](https://github.com/leadpony/justify) * [Snow](https://github.com/ssilverman/snowy-json) * [jsonschemafriend](https://github.com/jimblackler/jsonschemafriend) +* [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) ### JavaScript @@ -279,6 +282,10 @@ This suite is being used by: * [ajv](https://github.com/epoberezkin/ajv) * [djv](https://github.com/korzio/djv) +### Kotlin + +* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) + ### Node.js For node.js developers, the suite is also available as an [npm](https://www.npmjs.com/package/@json-schema-org/tests) package. @@ -287,7 +294,7 @@ Node-specific support is maintained in a [separate repository](https://github.co ### .NET -* [JsonSchema.Net](https://github.com/gregsdennis/json-everything) +* [JsonSchema.Net](https://github.com/json-everything/json-everything) * [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema) ### Perl @@ -313,7 +320,7 @@ Node-specific support is maintained in a [separate repository](https://github.co * [fastjsonschema](https://github.com/seznam/python-fastjsonschema) * [hypothesis-jsonschema](https://github.com/Zac-HD/hypothesis-jsonschema) * [jschon](https://github.com/marksparkza/jschon) -* [python-experimental, OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/python-experimental.md) +* [OpenAPI JSON Schema Generator](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) ### Ruby @@ -327,11 +334,13 @@ Node-specific support is maintained in a [separate repository](https://github.co ### Scala +* [json-schema-validation-comparison](https://www.creekservice.org/json-schema-validation-comparison/functional) (Comparison site for JVM-based validator implementations) * [typed-json](https://github.com/frawa/typed-json) ### Swift * [JSONSchema](https://github.com/kylef/JSONSchema.swift) +* [swift-json-schema](https://github.com/ajevans99/swift-json-schema) If you use it as well, please fork and send a pull request adding yourself to the list :). diff --git a/annotations/README.md b/annotations/README.md new file mode 100644 index 000000000..69cd3dd7e --- /dev/null +++ b/annotations/README.md @@ -0,0 +1,116 @@ +# Annotations Tests Suite + +The Annotations Test Suite tests which annotations should appear (or not appear) +on which values of an instance. These tests are agnostic of any output format. + +## Supported Dialects + +Although the annotation terminology of didn't appear in the spec until 2019-09, +the concept is compatible with every version of JSON Schema. Test Cases in this +Test Suite are designed to be compatible with as many releases of JSON Schema as +possible. They do not include `$schema` or `$id`/`id` keywords so +implementations can run the same Test Suite for each dialect they support. + +Since this Test Suite can be used for a variety of dialects, there are a couple +of options that can be used by Test Runners to filter out Test Cases that don't +apply to the dialect under test. + +## Test Case Components + +### description + +A short description of what behavior the Test Case is covering. + +### compatibility + +The `compatibility` option allows you to set which dialects the Test Case is +compatible with. Test Runners can use this value to filter out Test Cases that +don't apply the to dialect currently under test. The terminology for annotations +didn't appear in the spec until 2019-09, but the concept is compatible with +older releases as well. When setting `compatibility`, test authors should take +into account dialects before 2019-09 for implementations that chose to support +annotations for older dialects. + +Dialects are indicated by the number corresponding to their release. Date-based +releases use just the year. If this option isn't present, it means the Test Case +is compatible with any dialect. + +If this option is present with a number, the number indicates the minimum +release the Test Case is compatible with. This example indicates that the Test +Case is compatible with draft-07 and up. + +**Example**: `"compatibility": "7"` + +You can use a `<=` operator to indicate that the Test Case is compatible with +releases less then or equal to the given release. This example indicates that +the Test Case is compatible with 2019-09 and under. + +**Example**: `"compatibility": "<=2019"` + +You can use comma-separated values to indicate multiple constraints if needed. +This example indicates that the Test Case is compatible with releases between +draft-06 and 2019-09. + +**Example**: `"compatibility": "6,<=2019"` + +For convenience, you can use the `=` operator to indicate a Test Case is only +compatible with a single release. This example indicates that the Test Case is +compatible only with 2020-12. + +**Example**: `"compatibility": "=2020"` + +### schema + +The schema that will serve as the subject for the tests. Whenever possible, this +schema shouldn't include `$schema` or `id`/`$id` because Test Cases should be +designed to work with as many releases as possible. + +### externalSchemas + +This allows you to define additional schemas that `schema` makes references to. +The value is an object where the keys are retrieval URIs and values are schemas. +Most external schemas aren't self identifying (using `id`/`$id`) and rely on the +retrieval URI for identification. This is done to increase the number of +dialects that the test is compatible with. Because `id` changed to `$id` in +draft-06, if you use `$id`, the test becomes incompatible with draft-03/4 and in +most cases, that's not necessary. + +### tests + +A collection of Tests to run to verify the Test Case. + +## Test Components + +### instance + +The JSON instance to be annotated. + +### assertions + +A collection of assertions that must be true for the test to pass. + +## Assertions Components + +### location + +The instance location. + +### keyword + +The annotating keyword. + +### expected + +A collection of `keyword` annotations expected on the instance at `location`. +`expected` is an object where the keys are schema locations and the values are +the annotation that schema location contributed for the given `keyword`. + +There can be more than one expected annotation because multiple schema locations +could contribute annotations for a single keyword. + +An empty object is an assertion that the annotation must not appear at the +`location` for the `keyword`. + +As a convention for this Test Suite, the `expected` array should be sorted such +that the most recently encountered value for an annotation given top-down +evaluation of the schema comes before previously encountered values. diff --git a/annotations/assertion.schema.json b/annotations/assertion.schema.json new file mode 100644 index 000000000..882517887 --- /dev/null +++ b/annotations/assertion.schema.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + + "type": "object", + "properties": { + "location": { + "markdownDescription": "The instance location.", + "type": "string", + "format": "json-pointer" + }, + "keyword": { + "markdownDescription": "The annotation keyword.", + "type": "string" + }, + "expected": { + "markdownDescription": "An object of schemaLocation/annotations pairs for `keyword` annotations expected on the instance at `location`.", + "type": "object", + "propertyNames": { + "format": "uri" + } + } + }, + "required": ["location", "keyword", "expected"] +} diff --git a/annotations/test-case.schema.json b/annotations/test-case.schema.json new file mode 100644 index 000000000..6df5f1098 --- /dev/null +++ b/annotations/test-case.schema.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + + "type": "object", + "properties": { + "description": { + "markdownDescription": "A short description of what behavior the Test Case is covering.", + "type": "string" + }, + "compatibility": { + "markdownDescription": "Set which dialects the Test Case is compatible with. Examples:\n- `\"7\"` -- draft-07 and above\n- `\"<=2019\"` -- 2019-09 and previous\n- `\"6,<=2019\"` -- Between draft-06 and 2019-09\n- `\"=2020\"` -- 2020-12 only", + "type": "string", + "pattern": "^(<=|=)?([123467]|2019|2020)(,(<=|=)?([123467]|2019|2020))*$" + }, + "schema": { + "markdownDescription": "This schema shouldn't include `$schema` or `id`/`$id` unless necesary for the test because Test Cases should be designed to work with as many releases as possible.", + "type": ["boolean", "object"] + }, + "externalSchemas": { + "markdownDescription": "The keys are retrieval URIs and values are schemas.", + "type": "object", + "patternProperties": { + "": { + "type": ["boolean", "object"] + } + }, + "propertyNames": { + "format": "uri" + } + }, + "tests": { + "markdownDescription": "A collection of Tests to run to verify the Test Case.", + "type": "array", + "items": { "$ref": "./test.schema.json" } + } + }, + "required": ["description", "schema", "tests"] +} diff --git a/annotations/test-suite.schema.json b/annotations/test-suite.schema.json new file mode 100644 index 000000000..c8b17f0d5 --- /dev/null +++ b/annotations/test-suite.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "suite": { + "type": "array", + "items": { "$ref": "./test-case.schema.json" } + } + }, + "required": ["description", "suite"] +} diff --git a/annotations/test.schema.json b/annotations/test.schema.json new file mode 100644 index 000000000..3581fbfca --- /dev/null +++ b/annotations/test.schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + + "type": "object", + "properties": { + "instance": { + "markdownDescription": "The JSON instance to be annotated." + }, + "assertions": { + "markdownDescription": "A collection of assertions that must be true for the test to pass.", + "type": "array", + "items": { "$ref": "./assertion.schema.json" } + } + }, + "required": ["instance", "assertions"] +} diff --git a/annotations/tests/applicators.json b/annotations/tests/applicators.json new file mode 100644 index 000000000..ceb5044f3 --- /dev/null +++ b/annotations/tests/applicators.json @@ -0,0 +1,409 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The applicator vocabulary", + "suite": [ + { + "description": "`properties`, `patternProperties`, and `additionalProperties`", + "compatibility": "3", + "schema": { + "properties": { + "foo": { + "title": "Foo" + } + }, + "patternProperties": { + "^a": { + "title": "Bar" + } + }, + "additionalProperties": { + "title": "Baz" + } + }, + "tests": [ + { + "instance": {}, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": {} + }, + { + "location": "/apple", + "keyword": "title", + "expected": {} + }, + { + "location": "/bar", + "keyword": "title", + "expected": {} + } + ] + }, + { + "instance": { + "foo": {}, + "apple": {}, + "baz": {} + }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/properties/foo": "Foo" + } + }, + { + "location": "/apple", + "keyword": "title", + "expected": { + "#/patternProperties/%5Ea": "Bar" + } + }, + { + "location": "/baz", + "keyword": "title", + "expected": { + "#/additionalProperties": "Baz" + } + } + ] + } + ] + }, + { + "description": "`propertyNames` doesn't annotate property values", + "compatibility": "6", + "schema": { + "propertyNames": { + "const": "foo", + "title": "Foo" + } + }, + "tests": [ + { + "instance": { + "foo": 42 + }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": {} + } + ] + } + ] + }, + { + "description": "`prefixItems` and `items`", + "compatibility": "2020", + "schema": { + "prefixItems": [ + { + "title": "Foo" + } + ], + "items": { + "title": "Bar" + } + }, + "tests": [ + { + "instance": [ + "foo", + "bar" + ], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/prefixItems/0": "Foo" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/items": "Bar" + } + }, + { + "location": "/2", + "keyword": "title", + "expected": {} + } + ] + } + ] + }, + { + "description": "`contains`", + "compatibility": "6", + "schema": { + "contains": { + "type": "number", + "title": "Foo" + } + }, + "tests": [ + { + "instance": [ + "foo", + 42, + true + ], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": {} + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/contains": "Foo" + } + }, + { + "location": "/2", + "keyword": "title", + "expected": {} + }, + { + "location": "/3", + "keyword": "title", + "expected": {} + } + ] + } + ] + }, + { + "description": "`allOf`", + "compatibility": "4", + "schema": { + "allOf": [ + { + "title": "Foo" + }, + { + "title": "Bar" + } + ] + }, + "tests": [ + { + "instance": "foo", + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/allOf/1": "Bar", + "#/allOf/0": "Foo" + } + } + ] + } + ] + }, + { + "description": "`anyOf`", + "compatibility": "4", + "schema": { + "anyOf": [ + { + "type": "integer", + "title": "Foo" + }, + { + "type": "number", + "title": "Bar" + } + ] + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/anyOf/1": "Bar", + "#/anyOf/0": "Foo" + } + } + ] + }, + { + "instance": 4.2, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/anyOf/1": "Bar" + } + } + ] + } + ] + }, + { + "description": "`oneOf`", + "compatibility": "4", + "schema": { + "oneOf": [ + { + "type": "string", + "title": "Foo" + }, + { + "type": "number", + "title": "Bar" + } + ] + }, + "tests": [ + { + "instance": "foo", + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/oneOf/0": "Foo" + } + } + ] + }, + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/oneOf/1": "Bar" + } + } + ] + } + ] + }, + { + "description": "`not`", + "compatibility": "4", + "schema": { + "title": "Foo", + "not": { + "not": { + "title": "Bar" + } + } + }, + "tests": [ + { + "instance": {}, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#": "Foo" + } + } + ] + } + ] + }, + { + "description": "`dependentSchemas`", + "compatibility": "2019", + "schema": { + "dependentSchemas": { + "foo": { + "title": "Foo" + } + } + }, + "tests": [ + { + "instance": { + "foo": 42 + }, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/dependentSchemas/foo": "Foo" + } + } + ] + }, + { + "instance": { + "foo": 42 + }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": {} + } + ] + } + ] + }, + { + "description": "`if`, `then`, and `else`", + "compatibility": "7", + "schema": { + "if": { + "title": "If", + "type": "string" + }, + "then": { + "title": "Then" + }, + "else": { + "title": "Else" + } + }, + "tests": [ + { + "instance": "foo", + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/then": "Then", + "#/if": "If" + } + } + ] + }, + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/else": "Else" + } + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/content.json b/annotations/tests/content.json new file mode 100644 index 000000000..07c17a691 --- /dev/null +++ b/annotations/tests/content.json @@ -0,0 +1,121 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The content vocabulary", + "suite": [ + { + "description": "`contentMediaType` is an annotation for string instances", + "compatibility": "7", + "schema": { + "contentMediaType": "application/json" + }, + "tests": [ + { + "instance": "{ \"foo\": \"bar\" }", + "assertions": [ + { + "location": "", + "keyword": "contentMediaType", + "expected": { + "#": "application/json" + } + } + ] + }, + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "contentMediaType", + "expected": {} + } + ] + } + ] + }, + { + "description": "`contentEncoding` is an annotation for string instances", + "compatibility": "7", + "schema": { + "contentEncoding": "base64" + }, + "tests": [ + { + "instance": "SGVsbG8gZnJvbSBKU09OIFNjaGVtYQ==", + "assertions": [ + { + "location": "", + "keyword": "contentEncoding", + "expected": { + "#": "base64" + } + } + ] + }, + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "contentEncoding", + "expected": {} + } + ] + } + ] + }, + { + "description": "`contentSchema` is an annotation for string instances", + "compatibility": "2019", + "schema": { + "$id": "https://annotations.json-schema.org/test/contentSchema-is-an-annotation", + "contentMediaType": "application/json", + "contentSchema": { "type": "number" } + }, + "tests": [ + { + "instance": "42", + "assertions": [ + { + "location": "", + "keyword": "contentSchema", + "expected": { + "#": { "type": "number" } + } + } + ] + }, + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "contentSchema", + "expected": {} + } + ] + } + ] + }, + { + "description": "`contentSchema` requires `contentMediaType`", + "compatibility": "2019", + "schema": { + "$id": "https://annotations.json-schema.org/test/contentSchema-is-an-annotation", + "contentSchema": { "type": "number" } + }, + "tests": [ + { + "instance": "42", + "assertions": [ + { + "location": "", + "keyword": "contentSchema", + "expected": {} + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/core.json b/annotations/tests/core.json new file mode 100644 index 000000000..1d8dee556 --- /dev/null +++ b/annotations/tests/core.json @@ -0,0 +1,30 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The core vocabulary", + "suite": [ + { + "description": "`$ref` and `$defs`", + "compatibility": "2019", + "schema": { + "$ref": "#/$defs/foo", + "$defs": { + "foo": { "title": "Foo" } + } + }, + "tests": [ + { + "instance": "foo", + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#/$defs/foo": "Foo" + } + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/format.json b/annotations/tests/format.json new file mode 100644 index 000000000..d8cf9a7af --- /dev/null +++ b/annotations/tests/format.json @@ -0,0 +1,26 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The format vocabulary", + "suite": [ + { + "description": "`format` is an annotation", + "schema": { + "format": "email" + }, + "tests": [ + { + "instance": "foo@bar.com", + "assertions": [ + { + "location": "", + "keyword": "format", + "expected": { + "#": "email" + } + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/meta-data.json b/annotations/tests/meta-data.json new file mode 100644 index 000000000..be99b652f --- /dev/null +++ b/annotations/tests/meta-data.json @@ -0,0 +1,150 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The meta-data vocabulary", + "suite": [ + { + "description": "`title` is an annotation", + "schema": { + "title": "Foo" + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "title", + "expected": { + "#": "Foo" + } + } + ] + } + ] + }, + { + "description": "`description` is an annotation", + "schema": { + "description": "Foo" + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "description", + "expected": { + "#": "Foo" + } + } + ] + } + ] + }, + { + "description": "`default` is an annotation", + "schema": { + "default": "Foo" + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "default", + "expected": { + "#": "Foo" + } + } + ] + } + ] + }, + { + "description": "`deprecated` is an annotation", + "compatibility": "2019", + "schema": { + "deprecated": true + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "deprecated", + "expected": { + "#": true + } + } + ] + } + ] + }, + { + "description": "`readOnly` is an annotation", + "compatibility": "7", + "schema": { + "readOnly": true + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "readOnly", + "expected": { + "#": true + } + } + ] + } + ] + }, + { + "description": "`writeOnly` is an annotation", + "compatibility": "7", + "schema": { + "writeOnly": true + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "writeOnly", + "expected": { + "#": true + } + } + ] + } + ] + }, + { + "description": "`examples` is an annotation", + "compatibility": "6", + "schema": { + "examples": ["Foo", "Bar"] + }, + "tests": [ + { + "instance": "Foo", + "assertions": [ + { + "location": "", + "keyword": "examples", + "expected": { + "#": ["Foo", "Bar"] + } + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/unevaluated.json b/annotations/tests/unevaluated.json new file mode 100644 index 000000000..9f2db1158 --- /dev/null +++ b/annotations/tests/unevaluated.json @@ -0,0 +1,661 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "The unevaluated vocabulary", + "suite": [ + { + "description": "`unevaluatedProperties` alone", + "compatibility": "2019", + "schema": { + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `properties`", + "compatibility": "2019", + "schema": { + "properties": { + "foo": { "title": "Evaluated" } + }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/properties/foo": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `patternProperties`", + "compatibility": "2019", + "schema": { + "patternProperties": { + "^a": { "title": "Evaluated" } + }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "apple": 42, "bar": 24 }, + "assertions": [ + { + "location": "/apple", + "keyword": "title", + "expected": { + "#/patternProperties/%5Ea": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `additionalProperties`", + "compatibility": "2019", + "schema": { + "additionalProperties": { "title": "Evaluated" }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/additionalProperties": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/additionalProperties": "Evaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `dependentSchemas`", + "compatibility": "2019", + "schema": { + "dependentSchemas": { + "foo": { + "properties": { + "bar": { "title": "Evaluated" } + } + } + }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/dependentSchemas/foo/properties/bar": "Evaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `if`, `then`, and `else`", + "compatibility": "2019", + "schema": { + "if": { + "properties": { + "foo": { + "type": "string", + "title": "If" + } + } + }, + "then": { + "properties": { + "foo": { "title": "Then" } + } + }, + "else": { + "properties": { + "foo": { "title": "Else" } + } + }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": "", "bar": 42 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/then/properties/foo": "Then", + "#/if/properties/foo": "If" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + }, + { + "instance": { "foo": 42, "bar": "" }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/else/properties/foo": "Else" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `allOf`", + "compatibility": "2019", + "schema": { + "allOf": [ + { + "properties": { + "foo": { "title": "Evaluated" } + } + } + ], + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/allOf/0/properties/foo": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `anyOf`", + "compatibility": "2019", + "schema": { + "anyOf": [ + { + "properties": { + "foo": { "title": "Evaluated" } + } + } + ], + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/anyOf/0/properties/foo": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `oneOf`", + "compatibility": "2019", + "schema": { + "oneOf": [ + { + "properties": { + "foo": { "title": "Evaluated" } + } + } + ], + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/oneOf/0/properties/foo": "Evaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedProperties` with `not`", + "compatibility": "2019", + "schema": { + "not": { + "not": { + "properties": { + "foo": { "title": "Evaluated" } + } + } + }, + "unevaluatedProperties": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": { "foo": 42, "bar": 24 }, + "assertions": [ + { + "location": "/foo", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + }, + { + "location": "/bar", + "keyword": "title", + "expected": { + "#/unevaluatedProperties": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` alone", + "compatibility": "2019", + "schema": { + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `prefixItems`", + "compatibility": "2020", + "schema": { + "prefixItems": [{ "title": "Evaluated" }], + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/prefixItems/0": "Evaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `contains`", + "compatibility": "2020", + "schema": { + "contains": { + "type": "string", + "title": "Evaluated" + }, + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": ["foo", 42], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/contains": "Evaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `if`, `then`, and `else`", + "compatibility": "2020", + "schema": { + "if": { + "prefixItems": [ + { + "type": "string", + "title": "If" + } + ] + }, + "then": { + "prefixItems": [ + { "title": "Then" } + ] + }, + "else": { + "prefixItems": [ + { "title": "Else" } + ] + }, + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": ["", 42], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/then/prefixItems/0": "Then", + "#/if/prefixItems/0": "If" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + }, + { + "instance": [42, ""], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/else/prefixItems/0": "Else" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `allOf`", + "compatibility": "2020", + "schema": { + "allOf": [ + { + "prefixItems": [ + { "title": "Evaluated" } + ] + } + ], + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/allOf/0/prefixItems/0": "Evaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `anyOf`", + "compatibility": "2020", + "schema": { + "anyOf": [ + { + "prefixItems": [ + { "title": "Evaluated" } + ] + } + ], + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/anyOf/0/prefixItems/0": "Evaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `oneOf`", + "compatibility": "2020", + "schema": { + "oneOf": [ + { + "prefixItems": [ + { "title": "Evaluated" } + ] + } + ], + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/oneOf/0/prefixItems/0": "Evaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + }, + { + "description": "`unevaluatedItems` with `not`", + "compatibility": "2020", + "schema": { + "not": { + "not": { + "prefixItems": [ + { "title": "Evaluated" } + ] + } + }, + "unevaluatedItems": { "title": "Unevaluated" } + }, + "tests": [ + { + "instance": [42, 24], + "assertions": [ + { + "location": "/0", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + }, + { + "location": "/1", + "keyword": "title", + "expected": { + "#/unevaluatedItems": "Unevaluated" + } + } + ] + } + ] + } + ] +} diff --git a/annotations/tests/unknown.json b/annotations/tests/unknown.json new file mode 100644 index 000000000..b0c89003c --- /dev/null +++ b/annotations/tests/unknown.json @@ -0,0 +1,27 @@ +{ + "$schema": "../test-suite.schema.json", + "description": "Unknown keywords", + "suite": [ + { + "description": "`unknownKeyword` is an annotation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "x-unknownKeyword": "Foo" + }, + "tests": [ + { + "instance": 42, + "assertions": [ + { + "location": "", + "keyword": "x-unknownKeyword", + "expected": { + "#": "Foo" + } + } + ] + } + ] + } + ] +} diff --git a/bin/annotate-specification-links b/bin/annotate-specification-links new file mode 100755 index 000000000..963768b43 --- /dev/null +++ b/bin/annotate-specification-links @@ -0,0 +1,140 @@ +#!/usr/bin/env python3 +""" +Annotate pull requests to the GitHub repository with links to specifications. +""" + +from __future__ import annotations + +from pathlib import Path +from typing import Any +import json +import re +import sys + +from uritemplate import URITemplate + + +BIN_DIR = Path(__file__).parent +TESTS = BIN_DIR.parent / "tests" +URLS = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text()) + + +def urls(version: str) -> dict[str, URITemplate]: + """ + Retrieve the version-specific URLs for specifications. + """ + for_version = {**URLS["json-schema"][version], **URLS["external"]} + return {k: URITemplate(v) for k, v in for_version.items()} + + +def annotation( + path: Path, + message: str, + line: int = 1, + level: str = "notice", + **kwargs: Any, +) -> str: + """ + Format a GitHub annotation. + + See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions + for full syntax. + """ + + if kwargs: + additional = "," + ",".join(f"{k}={v}" for k, v in kwargs.items()) + else: + additional = "" + + relative = path.relative_to(TESTS.parent) + return f"::{level} file={relative},line={line}{additional}::{message}\n" + + +def line_number_of(path: Path, case: dict[str, Any]) -> int: + """ + Crudely find the line number of a test case. + """ + with path.open() as file: + description = case["description"] + return next( + (i + 1 for i, line in enumerate(file, 1) if description in line), + 1, + ) + +def extract_kind_and_spec(key: str) -> (str, str): + """ + Extracts specification number and kind from the defined key + """ + can_have_spec = ["rfc", "iso"] + if not any(key.startswith(el) for el in can_have_spec): + return key, "" + number = re.search(r"\d+", key) + spec = "" if number is None else number.group(0) + kind = key.removesuffix(spec) + return kind, spec + + +def main(): + # Clear annotations which may have been emitted by a previous run. + sys.stdout.write("::remove-matcher owner=me::\n") + + for version in TESTS.iterdir(): + if version.name in {"draft-next", "latest"}: + continue + + version_urls = urls(version.name) + + for path in version.rglob("*.json"): + try: + contents = json.loads(path.read_text()) + except json.JSONDecodeError as error: + error = annotation( + level="error", + path=path, + line=error.lineno, + col=error.pos + 1, + title=str(error), + message=f"cannot load {path}" + ) + sys.stdout.write(error) + continue + + for test_case in contents: + specifications = test_case.get("specification") + if specifications is not None: + for each in specifications: + quote = each.pop("quote", "") + (key, section), = each.items() + + (kind, spec) = extract_kind_and_spec(key) + + url_template = version_urls[kind] + if url_template is None: + error = annotation( + level="error", + path=path, + line=line_number_of(path, test_case), + title=f"unsupported template '{kind}'", + message=f"cannot find a URL template for '{kind}'" + ) + sys.stdout.write(error) + continue + + url = url_template.expand( + spec=spec, + section=section, + ) + + message = f"{url}\n\n{quote}" if quote else url + sys.stdout.write( + annotation( + path=path, + line=line_number_of(path, test_case), + title="Specification Link", + message=message, + ), + ) + + +if __name__ == "__main__": + main() diff --git a/bin/annotation-tests.ts b/bin/annotation-tests.ts new file mode 100755 index 000000000..2d3d19326 --- /dev/null +++ b/bin/annotation-tests.ts @@ -0,0 +1,31 @@ +#!/usr/bin/env deno +import { validate } from "npm:@hyperjump/json-schema/draft-07"; +import { BASIC } from "npm:@hyperjump/json-schema/experimental"; + +const validateTestSuite = await validate("./annotations/test-suite.schema.json"); + +console.log("Validating annotation tests ..."); + +let isValid = true; +for await (const entry of Deno.readDir("./annotations/tests")) { + if (entry.isFile) { + const json = await Deno.readTextFile(`./annotations/tests/${entry.name}`); + const suite = JSON.parse(json); + + const output = validateTestSuite(suite, BASIC); + + if (output.valid) { + console.log(`\x1b[32m✔\x1b[0m ${entry.name}`); + } else { + isValid = false; + console.log(`\x1b[31m✖\x1b[0m ${entry.name}`); + console.log(output); + } + } +} + +console.log("Done."); + +if (!isValid) { + Deno.exit(1); +} diff --git a/bin/specification_urls.json b/bin/specification_urls.json new file mode 100644 index 000000000..e1824999a --- /dev/null +++ b/bin/specification_urls.json @@ -0,0 +1,34 @@ +{ + "json-schema": { + "draft2020-12": { + "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}", + "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}" + }, + "draft2019-09": { + "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}", + "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}" + }, + "draft7": { + "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}", + "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}" + }, + "draft6": { + "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}", + "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}" + }, + "draft4": { + "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}", + "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}" + }, + "draft3": { + "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" + } + }, + + "external": { + "ecma262": "https://262.ecma-international.org/{section}", + "perl5": "https://perldoc.perl.org/perlre#{section}", + "rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.html#section-{section}", + "iso": "https://www.iso.org/obp/ui" + } +} diff --git a/output-tests/draft2019-09/content/type.json b/output-tests/draft2019-09/content/type.json index cff77a740..21118fd5f 100644 --- a/output-tests/draft2019-09/content/type.json +++ b/output-tests/draft2019-09/content/type.json @@ -31,32 +31,6 @@ "required": ["errors"] } } - }, - { - "description": "correct type yields an output unit", - "data": "a string", - "output": { - "basic": { - "$id": "https://json-schema.org/tests/content/draft2019-09/type/0/tests/1/basic", - "$ref": "/draft/2019-09/output/schema", - "properties": { - "annotations": { - "contains": { - "properties": { - "valid": {"const": true}, - "keywordLocation": {"const": "/type"}, - "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2019-09/type/0#/type"}, - "instanceLocation": {"const": ""}, - "annotation": false, - "error": false - }, - "required": ["keywordLocation", "instanceLocation"] - } - } - }, - "required": ["annotations"] - } - } } ] } diff --git a/output-tests/draft2020-12/content/type.json b/output-tests/draft2020-12/content/type.json index 710475b2b..2949a6052 100644 --- a/output-tests/draft2020-12/content/type.json +++ b/output-tests/draft2020-12/content/type.json @@ -31,32 +31,6 @@ "required": ["errors"] } } - }, - { - "description": "correct type yields an output unit", - "data": "a string", - "output": { - "basic": { - "$id": "https://json-schema.org/tests/content/draft2020-12/type/0/tests/1/basic", - "$ref": "/draft/2020-12/output/schema", - "properties": { - "annotations": { - "contains": { - "properties": { - "valid": {"const": true}, - "keywordLocation": {"const": "/type"}, - "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2020-12/type/0#/type"}, - "instanceLocation": {"const": ""}, - "annotation": false, - "error": false - }, - "required": ["keywordLocation", "instanceLocation"] - } - } - }, - "required": ["annotations"] - } - } } ] } diff --git a/remotes/draft-next/format-assertion-false.json b/remotes/draft-next/format-assertion-false.json index 91c866996..9cbd2a1de 100644 --- a/remotes/draft-next/format-assertion-false.json +++ b/remotes/draft-next/format-assertion-false.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/next/vocab/core": true, "https://json-schema.org/draft/next/vocab/format-assertion": false }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/core" }, { "$ref": "https://json-schema.org/draft/next/meta/format-assertion" } diff --git a/remotes/draft-next/format-assertion-true.json b/remotes/draft-next/format-assertion-true.json index a33d1435f..b3ff69f3a 100644 --- a/remotes/draft-next/format-assertion-true.json +++ b/remotes/draft-next/format-assertion-true.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/next/vocab/core": true, "https://json-schema.org/draft/next/vocab/format-assertion": true }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/core" }, { "$ref": "https://json-schema.org/draft/next/meta/format-assertion" } diff --git a/remotes/draft-next/metaschema-no-validation.json b/remotes/draft-next/metaschema-no-validation.json index c19c9e8a7..90e32a672 100644 --- a/remotes/draft-next/metaschema-no-validation.json +++ b/remotes/draft-next/metaschema-no-validation.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/next/vocab/applicator": true, "https://json-schema.org/draft/next/vocab/core": true }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/applicator" }, { "$ref": "https://json-schema.org/draft/next/meta/core" } diff --git a/remotes/draft-next/metaschema-optional-vocabulary.json b/remotes/draft-next/metaschema-optional-vocabulary.json index e78e531d4..1af0cad4c 100644 --- a/remotes/draft-next/metaschema-optional-vocabulary.json +++ b/remotes/draft-next/metaschema-optional-vocabulary.json @@ -6,6 +6,7 @@ "https://json-schema.org/draft/next/vocab/core": true, "http://localhost:1234/draft/next/vocab/custom": false }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/next/meta/validation" }, { "$ref": "https://json-schema.org/draft/next/meta/core" } diff --git a/remotes/draft-next/subSchemas-defs.json b/remotes/draft-next/subSchemas-defs.json deleted file mode 100644 index 75b7583ca..000000000 --- a/remotes/draft-next/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/remotes/draft-next/subSchemas.json b/remotes/draft-next/subSchemas.json index 575dd00c2..75b7583ca 100644 --- a/remotes/draft-next/subSchemas.json +++ b/remotes/draft-next/subSchemas.json @@ -1,9 +1,11 @@ { "$schema": "https://json-schema.org/draft/next/schema", - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/integer" + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } } } diff --git a/remotes/draft2019-09/metaschema-no-validation.json b/remotes/draft2019-09/metaschema-no-validation.json index 494f0abff..859006c27 100644 --- a/remotes/draft2019-09/metaschema-no-validation.json +++ b/remotes/draft2019-09/metaschema-no-validation.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/2019-09/vocab/applicator": true, "https://json-schema.org/draft/2019-09/vocab/core": true }, + "$recursiveAnchor": true, "allOf": [ { "$ref": "https://json-schema.org/draft/2019-09/meta/applicator" }, { "$ref": "https://json-schema.org/draft/2019-09/meta/core" } diff --git a/remotes/draft2019-09/metaschema-optional-vocabulary.json b/remotes/draft2019-09/metaschema-optional-vocabulary.json index 968597c45..3a7502a21 100644 --- a/remotes/draft2019-09/metaschema-optional-vocabulary.json +++ b/remotes/draft2019-09/metaschema-optional-vocabulary.json @@ -6,6 +6,7 @@ "https://json-schema.org/draft/2019-09/vocab/core": true, "http://localhost:1234/draft/2019-09/vocab/custom": false }, + "$recursiveAnchor": true, "allOf": [ { "$ref": "https://json-schema.org/draft/2019-09/meta/validation" }, { "$ref": "https://json-schema.org/draft/2019-09/meta/core" } diff --git a/remotes/draft2019-09/subSchemas-defs.json b/remotes/draft2019-09/subSchemas-defs.json deleted file mode 100644 index fdfee68d9..000000000 --- a/remotes/draft2019-09/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/remotes/draft2019-09/subSchemas.json b/remotes/draft2019-09/subSchemas.json index 6dea22525..fdfee68d9 100644 --- a/remotes/draft2019-09/subSchemas.json +++ b/remotes/draft2019-09/subSchemas.json @@ -1,9 +1,11 @@ { "$schema": "https://json-schema.org/draft/2019-09/schema", - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/integer" + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } } } diff --git a/remotes/draft2020-12/format-assertion-false.json b/remotes/draft2020-12/format-assertion-false.json index d6dd645b6..43a711c9d 100644 --- a/remotes/draft2020-12/format-assertion-false.json +++ b/remotes/draft2020-12/format-assertion-false.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/format-assertion": false }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/core" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" } diff --git a/remotes/draft2020-12/format-assertion-true.json b/remotes/draft2020-12/format-assertion-true.json index bb16d5864..39c6b0abf 100644 --- a/remotes/draft2020-12/format-assertion-true.json +++ b/remotes/draft2020-12/format-assertion-true.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/format-assertion": true }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/core" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" } diff --git a/remotes/draft2020-12/metaschema-no-validation.json b/remotes/draft2020-12/metaschema-no-validation.json index 85d74b213..71be8b5da 100644 --- a/remotes/draft2020-12/metaschema-no-validation.json +++ b/remotes/draft2020-12/metaschema-no-validation.json @@ -5,6 +5,7 @@ "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/core": true }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/applicator" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/core" } diff --git a/remotes/draft2020-12/metaschema-optional-vocabulary.json b/remotes/draft2020-12/metaschema-optional-vocabulary.json index f38ec281d..a6963e548 100644 --- a/remotes/draft2020-12/metaschema-optional-vocabulary.json +++ b/remotes/draft2020-12/metaschema-optional-vocabulary.json @@ -6,6 +6,7 @@ "https://json-schema.org/draft/2020-12/vocab/core": true, "http://localhost:1234/draft/2020-12/vocab/custom": false }, + "$dynamicAnchor": "meta", "allOf": [ { "$ref": "https://json-schema.org/draft/2020-12/meta/validation" }, { "$ref": "https://json-schema.org/draft/2020-12/meta/core" } diff --git a/remotes/draft2020-12/subSchemas-defs.json b/remotes/draft2020-12/subSchemas-defs.json deleted file mode 100644 index 1bb4846d7..000000000 --- a/remotes/draft2020-12/subSchemas-defs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/$defs/integer" - } - } -} diff --git a/remotes/draft2020-12/subSchemas.json b/remotes/draft2020-12/subSchemas.json index 5fca21d82..1bb4846d7 100644 --- a/remotes/draft2020-12/subSchemas.json +++ b/remotes/draft2020-12/subSchemas.json @@ -1,9 +1,11 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/integer" + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } } } diff --git a/remotes/subSchemas-defs.json b/remotes/draft3/subSchemas.json similarity index 62% rename from remotes/subSchemas-defs.json rename to remotes/draft3/subSchemas.json index 50b7b6dc4..6e9b3de35 100644 --- a/remotes/subSchemas-defs.json +++ b/remotes/draft3/subSchemas.json @@ -1,10 +1,10 @@ { - "$defs": { + "definitions": { "integer": { "type": "integer" }, "refToInteger": { - "$ref": "#/$defs/integer" + "$ref": "#/definitions/integer" } } } diff --git a/remotes/locationIndependentIdentifierDraft4.json b/remotes/draft4/locationIndependentIdentifier.json similarity index 100% rename from remotes/locationIndependentIdentifierDraft4.json rename to remotes/draft4/locationIndependentIdentifier.json diff --git a/remotes/name.json b/remotes/draft4/name.json similarity index 100% rename from remotes/name.json rename to remotes/draft4/name.json diff --git a/remotes/draft4/subSchemas.json b/remotes/draft4/subSchemas.json new file mode 100644 index 000000000..6e9b3de35 --- /dev/null +++ b/remotes/draft4/subSchemas.json @@ -0,0 +1,10 @@ +{ + "definitions": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/definitions/integer" + } + } +} diff --git a/remotes/locationIndependentIdentifierPre2019.json b/remotes/draft6/locationIndependentIdentifier.json similarity index 100% rename from remotes/locationIndependentIdentifierPre2019.json rename to remotes/draft6/locationIndependentIdentifier.json diff --git a/remotes/draft6/name.json b/remotes/draft6/name.json new file mode 100644 index 000000000..fceacb809 --- /dev/null +++ b/remotes/draft6/name.json @@ -0,0 +1,15 @@ +{ + "definitions": { + "orNull": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#" + } + ] + } + }, + "type": "string" +} diff --git a/remotes/ref-and-definitions.json b/remotes/draft6/ref-and-definitions.json similarity index 74% rename from remotes/ref-and-definitions.json rename to remotes/draft6/ref-and-definitions.json index e0ee802a9..b80deeb7b 100644 --- a/remotes/ref-and-definitions.json +++ b/remotes/draft6/ref-and-definitions.json @@ -1,5 +1,5 @@ { - "$id": "http://localhost:1234/ref-and-definitions.json", + "$id": "http://localhost:1234/draft6/ref-and-definitions.json", "definitions": { "inner": { "properties": { diff --git a/remotes/draft6/subSchemas.json b/remotes/draft6/subSchemas.json new file mode 100644 index 000000000..6e9b3de35 --- /dev/null +++ b/remotes/draft6/subSchemas.json @@ -0,0 +1,10 @@ +{ + "definitions": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/definitions/integer" + } + } +} diff --git a/remotes/draft7/locationIndependentIdentifier.json b/remotes/draft7/locationIndependentIdentifier.json new file mode 100644 index 000000000..e72815cd5 --- /dev/null +++ b/remotes/draft7/locationIndependentIdentifier.json @@ -0,0 +1,11 @@ +{ + "definitions": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$id": "#foo", + "type": "integer" + } + } +} diff --git a/remotes/draft7/name.json b/remotes/draft7/name.json new file mode 100644 index 000000000..fceacb809 --- /dev/null +++ b/remotes/draft7/name.json @@ -0,0 +1,15 @@ +{ + "definitions": { + "orNull": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#" + } + ] + } + }, + "type": "string" +} diff --git a/remotes/draft7/ref-and-definitions.json b/remotes/draft7/ref-and-definitions.json new file mode 100644 index 000000000..d5929380c --- /dev/null +++ b/remotes/draft7/ref-and-definitions.json @@ -0,0 +1,11 @@ +{ + "$id": "http://localhost:1234/draft7/ref-and-definitions.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] +} diff --git a/remotes/draft7/subSchemas.json b/remotes/draft7/subSchemas.json new file mode 100644 index 000000000..6e9b3de35 --- /dev/null +++ b/remotes/draft7/subSchemas.json @@ -0,0 +1,10 @@ +{ + "definitions": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/definitions/integer" + } + } +} diff --git a/remotes/subSchemas.json b/remotes/subSchemas.json deleted file mode 100644 index 9f8030bce..000000000 --- a/remotes/subSchemas.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "integer": { - "type": "integer" - }, - "refToInteger": { - "$ref": "#/integer" - } -} diff --git a/test-schema.json b/test-schema.json index 833931620..0087c5e3d 100644 --- a/test-schema.json +++ b/test-schema.json @@ -27,6 +27,69 @@ "type": "array", "items": { "$ref": "#/$defs/test" }, "minItems": 1 + }, + "specification":{ + "description": "A reference to a specification document which defines the behavior tested by this test case. Typically this should be a JSON Schema specification document, though in cases where the JSON Schema specification points to another RFC it should contain *both* the portion of the JSON Schema specification which indicates what RFC (and section) to follow as *well* as information on where in that specification the behavior is specified.", + + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items":{ + "properties": { + "core": { + "description": "A section in official JSON Schema core drafts", + "url": "https://json-schema.org/specification-links", + "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", + "type":"string" + }, + "validation": { + "description": "A section in official JSON Schema validation drafts", + "url": "https://json-schema.org/specification-links", + "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", + "type":"string" + }, + "ecma262": { + "description": "A section in official ECMA 262 specification for defining regular expressions", + "url": "https://262.ecma-international.org/", + "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", + "type":"string" + }, + "perl5": { + "description": "A section name in Perl documentation for defining regular expressions", + "url": "https://perldoc.perl.org/perlre", + "type":"string" + }, + "quote": { + "description": "Quote describing the test case", + "type":"string" + } + }, + "patternProperties": { + "^rfc\\d+$": { + "description": "A section in official RFC for the given rfc number", + "url": "https://www.rfc-editor.org/", + "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", + "type":"string" + }, + "^iso\\d+$": { + "description": "A section in official ISO for the given iso number", + "pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$", + "type": "string" + } + }, + "additionalProperties": { "type": "string" }, + "minProperties": 1, + "propertyNames": { + "oneOf": [ + { + "pattern": "^((iso)|(rfc))[0-9]+$" + }, + { + "enum": [ "core", "validation", "ecma262", "perl5", "quote" ] + } + ] + } + } } }, "additionalProperties": false diff --git a/tests/draft-next/additionalProperties.json b/tests/draft-next/additionalProperties.json index 7859fbbf1..51b0edada 100644 --- a/tests/draft-next/additionalProperties.json +++ b/tests/draft-next/additionalProperties.json @@ -152,5 +152,97 @@ "valid": true } ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "Valid against both keywords", + "data": { "apple": 4 }, + "valid": true + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { "fig": 2, "pear": "available" }, + "valid": false + } + ] + }, + { + "description": "propertyDependencies with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties" : {"foo2" : {}}, + "propertyDependencies": { + "foo" : {}, + "foo2": { + "bar": { + "properties": { + "buz": {} + } + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider propertyDependencies properties" , + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see buz even when foo2 is present", + "data": {"foo2": "bar", "buz": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see buz", + "data": {"buz": ""}, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index 321d84461..84d4851ca 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -81,64 +81,6 @@ } ] }, - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - }, { "description": "same $anchor with different base uri", "schema": { @@ -174,61 +116,5 @@ "valid": false } ] - }, - { - "description": "non-schema object containing an $anchor property", - "schema": { - "$schema": "https://json-schema.org/draft/next/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 - } - ] - }, - { - "description": "invalid anchors", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "https://json-schema.org/draft/next/schema" - }, - "tests": [ - { - "description": "MUST start with a letter (and not #)", - "data": { "$anchor" : "#foo" }, - "valid": false - }, - { - "description": "JSON pointers are not valid", - "data": { "$anchor" : "/a/b" }, - "valid": false - }, - { - "description": "invalid with valid beginning", - "data": { "$anchor" : "foo#something" }, - "valid": false - } - ] } ] diff --git a/tests/draft-next/contains.json b/tests/draft-next/contains.json index c17f55ee7..8539a531d 100644 --- a/tests/draft-next/contains.json +++ b/tests/draft-next/contains.json @@ -31,31 +31,6 @@ "data": [], "valid": false }, - { - "description": "object with property matching schema (5) is valid", - "data": { "a": 3, "b": 4, "c": 5 }, - "valid": true - }, - { - "description": "object with property matching schema (6) is valid", - "data": { "a": 3, "b": 4, "c": 6 }, - "valid": true - }, - { - "description": "object with two properties matching schema (5, 6) is valid", - "data": { "a": 3, "b": 4, "c": 5, "d": 6 }, - "valid": true - }, - { - "description": "object without properties matching schema is invalid", - "data": { "a": 2, "b": 3, "c": 4 }, - "valid": false - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false - }, { "description": "not array or object is valid", "data": 42, @@ -84,21 +59,6 @@ "description": "array without item 5 is invalid", "data": [1, 2, 3, 4], "valid": false - }, - { - "description": "object with property 5 is valid", - "data": { "a": 3, "b": 4, "c": 5 }, - "valid": true - }, - { - "description": "object with two properties 5 is valid", - "data": { "a": 3, "b": 4, "c": 5, "d": 5 }, - "valid": true - }, - { - "description": "object without property 5 is invalid", - "data": { "a": 1, "b": 2, "c": 3, "d": 4 }, - "valid": false } ] }, @@ -118,16 +78,6 @@ "description": "empty array is invalid", "data": [], "valid": false - }, - { - "description": "any non-empty object is valid", - "data": { "a": "foo" }, - "valid": true - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false } ] }, @@ -149,18 +99,28 @@ "valid": false }, { - "description": "any non-empty object is invalid", - "data": ["foo"], - "valid": false + "description": "non-arrays are valid - string", + "data": "contains does not apply to strings", + "valid": true }, { - "description": "empty object is invalid", + "description": "non-arrays are valid - object", "data": {}, - "valid": false + "valid": true }, { - "description": "non-arrays/objects are valid", - "data": "contains does not apply to strings", + "description": "non-arrays are valid - number", + "data": 42, + "valid": true + }, + { + "description": "non-arrays are valid - boolean", + "data": false, + "valid": true + }, + { + "description": "non-arrays are valid - null", + "data": null, "valid": true } ] @@ -193,26 +153,6 @@ "description": "matches neither items nor contains", "data": [1, 5], "valid": false - }, - { - "description": "matches additionalProperties, does not match contains", - "data": { "a": 2, "b": 4, "c": 8 }, - "valid": false - }, - { - "description": "does not match additionalProperties, matches contains", - "data": { "a": 3, "b": 6, "c": 9 }, - "valid": false - }, - { - "description": "matches both additionalProperties and contains", - "data": { "a": 6, "b": 12 }, - "valid": true - }, - { - "description": "matches neither additionalProperties nor contains", - "data": { "a": 1, "b": 5 }, - "valid": false } ] }, @@ -235,16 +175,6 @@ "description": "empty array is invalid", "data": [], "valid": false - }, - { - "description": "any non-empty object is valid", - "data": { "a": "foo" }, - "valid": true - }, - { - "description": "empty object is invalid", - "data": {}, - "valid": false } ] }, diff --git a/tests/draft-next/dependentSchemas.json b/tests/draft-next/dependentSchemas.json index 8a8477591..86079c34c 100644 --- a/tests/draft-next/dependentSchemas.json +++ b/tests/draft-next/dependentSchemas.json @@ -132,6 +132,7 @@ { "description": "dependent subschema incompatible with root", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "properties": { "foo": {} }, diff --git a/tests/draft-next/dynamicRef.json b/tests/draft-next/dynamicRef.json index 428c83b34..30821c5b1 100644 --- a/tests/draft-next/dynamicRef.json +++ b/tests/draft-next/dynamicRef.json @@ -612,5 +612,90 @@ "valid": false } ] + }, + { + "description": "$dynamicRef points to a boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "true": true, + "false": false + }, + "properties": { + "true": { + "$dynamicRef": "#/$defs/true" + }, + "false": { + "$dynamicRef": "#/$defs/false" + } + } + }, + "tests": [ + { + "description": "follow $dynamicRef to a true schema", + "data": { "true": 1 }, + "valid": true + }, + { + "description": "follow $dynamicRef to a false schema", + "data": { "false": 1 }, + "valid": false + } + ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] } ] diff --git a/tests/draft-next/enum.json b/tests/draft-next/enum.json index 32e5af01b..e263f3901 100644 --- a/tests/draft-next/enum.json +++ b/tests/draft-next/enum.json @@ -168,6 +168,30 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [[false]] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": { @@ -192,6 +216,30 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [[true]] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": { @@ -216,6 +264,30 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [[0]] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": { @@ -240,6 +312,30 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [[1]] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft-next/id.json b/tests/draft-next/id.json deleted file mode 100644 index 9b3a591f0..000000000 --- a/tests/draft-next/id.json +++ /dev/null @@ -1,294 +0,0 @@ -[ - { - "description": "Invalid use of fragments in location-independent $id", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "https://json-schema.org/draft/next/schema" - }, - "tests": [ - { - "description": "Identifier name", - "data": { - "$ref": "#foo", - "$defs": { - "A": { - "$id": "#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name and no ref", - "data": { - "$defs": { - "A": { "$id": "#foo" } - } - }, - "valid": false - }, - { - "description": "Identifier path", - "data": { - "$ref": "#/a/b", - "$defs": { - "A": { - "$id": "#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft-next/bar#foo", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/bar#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier path with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft-next/bar#/a/b", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/bar#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft-next/root", - "$ref": "http://localhost:1234/draft-next/nested.json#foo", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#foo", - "type": "integer" - } - } - } - } - }, - "valid": false - }, - { - "description": "Identifier path with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft-next/root", - "$ref": "http://localhost:1234/draft-next/nested.json#/a/b", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#/a/b", - "type": "integer" - } - } - } - } - }, - "valid": false - } - ] - }, - { - "description": "Valid use of empty fragments in location-independent $id", - "comment": "These are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "https://json-schema.org/draft/next/schema" - }, - "tests": [ - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft-next/bar", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/bar#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft-next/root", - "$ref": "http://localhost:1234/draft-next/nested.json#/$defs/B", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#", - "type": "integer" - } - } - } - } - }, - "valid": true - } - ] - }, - { - "description": "Unnormalized $ids are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "https://json-schema.org/draft/next/schema" - }, - "tests": [ - { - "description": "Unnormalized identifier", - "data": { - "$ref": "http://localhost:1234/draft-next/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment", - "data": { - "$ref": "http://localhost:1234/draft-next/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft-next/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - } - ] - }, - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft-next/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft-next/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - }, - { - "description": "non-schema object containing an $id property", - "schema": { - "$schema": "https://json-schema.org/draft/next/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/items.json b/tests/draft-next/items.json index 459943bef..dfb79af2f 100644 --- a/tests/draft-next/items.json +++ b/tests/draft-next/items.json @@ -265,6 +265,26 @@ } ] }, + { + "description": "items with heterogeneous array", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{}], + "items": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "items with null instance elements", "schema": { diff --git a/tests/draft-next/maxContains.json b/tests/draft-next/maxContains.json index 7c1515753..5af6e4c13 100644 --- a/tests/draft-next/maxContains.json +++ b/tests/draft-next/maxContains.json @@ -15,16 +15,6 @@ "description": "two items still valid against lone maxContains", "data": [1, 2], "valid": true - }, - { - "description": "one property valid against lone maxContains", - "data": { "a": 1 }, - "valid": true - }, - { - "description": "two properties still valid against lone maxContains", - "data": { "a": 1, "b": 2 }, - "valid": true } ] }, @@ -60,31 +50,6 @@ "description": "some elements match, invalid maxContains", "data": [1, 2, 1], "valid": false - }, - { - "description": "empty object", - "data": {}, - "valid": false - }, - { - "description": "all properties match, valid maxContains", - "data": { "a": 1 }, - "valid": true - }, - { - "description": "all properties match, invalid maxContains", - "data": { "a": 1, "b": 1 }, - "valid": false - }, - { - "description": "some properties match, valid maxContains", - "data": { "a": 1, "b": 2 }, - "valid": true - }, - { - "description": "some properties match, invalid maxContains", - "data": { "a": 1, "b": 2, "c": 1 }, - "valid": false } ] }, @@ -131,21 +96,6 @@ "description": "array with minContains < maxContains < actual", "data": [1, 1, 1, 1], "valid": false - }, - { - "description": "object with actual < minContains < maxContains", - "data": {}, - "valid": false - }, - { - "description": "object with minContains < actual < maxContains", - "data": { "a": 1, "b": 1 }, - "valid": true - }, - { - "description": "object with minContains < maxContains < actual", - "data": { "a": 1, "b": 1, "c": 1, "d": 1 }, - "valid": false } ] } diff --git a/tests/draft-next/maxLength.json b/tests/draft-next/maxLength.json index e09e44ad8..c88f604ef 100644 --- a/tests/draft-next/maxLength.json +++ b/tests/draft-next/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft-next/minLength.json b/tests/draft-next/minLength.json index 16022acb5..52c9c9a14 100644 --- a/tests/draft-next/minLength.json +++ b/tests/draft-next/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft-next/oneOf.json b/tests/draft-next/oneOf.json index e8c077131..840d1579d 100644 --- a/tests/draft-next/oneOf.json +++ b/tests/draft-next/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/next/schema", diff --git a/tests/draft-next/optional/anchor.json b/tests/draft-next/optional/anchor.json new file mode 100644 index 000000000..1de0b7a70 --- /dev/null +++ b/tests/draft-next/optional/anchor.json @@ -0,0 +1,60 @@ +[ + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/dynamicRef.json b/tests/draft-next/optional/dynamicRef.json new file mode 100644 index 000000000..dcace154e --- /dev/null +++ b/tests/draft-next/optional/dynamicRef.json @@ -0,0 +1,56 @@ +[ + { + "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "bar#/$defs/item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] + }] \ No newline at end of file diff --git a/tests/draft-next/optional/ecmascript-regex.json b/tests/draft-next/optional/ecmascript-regex.json index 272114503..a1a4f9638 100644 --- a/tests/draft-next/optional/ecmascript-regex.json +++ b/tests/draft-next/optional/ecmascript-regex.json @@ -405,20 +405,6 @@ } ] }, - { - "description": "\\a is not an ECMA 262 control escape", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "https://json-schema.org/draft/next/schema" - }, - "tests": [ - { - "description": "when used as a pattern", - "data": { "pattern": "\\a" }, - "valid": false - } - ] - }, { "description": "pattern with non-ASCII digits", "schema": { diff --git a/tests/draft-next/optional/format/duration.json b/tests/draft-next/optional/format/duration.json index d5adca206..c4aa66bae 100644 --- a/tests/draft-next/optional/format/duration.json +++ b/tests/draft-next/optional/format/duration.json @@ -46,6 +46,11 @@ "data": "PT1D", "valid": false }, + { + "description": "must start with P", + "data": "4DT12H30M5S", + "valid": false + }, { "description": "no elements present", "data": "P", diff --git a/tests/draft-next/optional/format/ecmascript-regex.json b/tests/draft-next/optional/format/ecmascript-regex.json new file mode 100644 index 000000000..1e19c2729 --- /dev/null +++ b/tests/draft-next/optional/format/ecmascript-regex.json @@ -0,0 +1,16 @@ +[ + { + "description": "\\a is not an ECMA 262 control escape", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "regex" + }, + "tests": [ + { + "description": "when used as a pattern", + "data": "\\a", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/hostname.json b/tests/draft-next/optional/format/hostname.json index bfb306363..bc3a60dcc 100644 --- a/tests/draft-next/optional/format/hostname.json +++ b/tests/draft-next/optional/format/hostname.json @@ -120,6 +120,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft-next/optional/format/idn-hostname.json b/tests/draft-next/optional/format/idn-hostname.json index ee2e792fa..1061f4243 100644 --- a/tests/draft-next/optional/format/idn-hostname.json +++ b/tests/draft-next/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0660\u06f0", + "data": "\u0628\u0660\u06f0", "valid": false }, { @@ -301,6 +301,88 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true + }, + { + "description": "single label", + "data": "hostname", + "valid": true + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + } + ] + }, + { + "description": "validation of separators in internationalized host names", + "specification": [ + {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} + ], + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "single dot", + "data": ".", + "valid": false + }, + { + "description": "single ideographic full stop", + "data": "\u3002", + "valid": false + }, + { + "description": "single fullwidth full stop", + "data": "\uff0e", + "valid": false + }, + { + "description": "single halfwidth ideographic full stop", + "data": "\uff61", + "valid": false + }, + { + "description": "dot as label separator", + "data": "a.b", + "valid": true + }, + { + "description": "ideographic full stop as label separator", + "data": "a\u3002b", + "valid": true + }, + { + "description": "fullwidth full stop as label separator", + "data": "a\uff0eb", + "valid": true + }, + { + "description": "halfwidth ideographic full stop as label separator", + "data": "a\uff61b", + "valid": true } ] } diff --git a/tests/draft-next/optional/format/ipv4.json b/tests/draft-next/optional/format/ipv4.json index e3e944015..2a4bc2b2f 100644 --- a/tests/draft-next/optional/format/ipv4.json +++ b/tests/draft-next/optional/format/ipv4.json @@ -81,6 +81,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft-next/optional/id.json b/tests/draft-next/optional/id.json new file mode 100644 index 000000000..fc26f26c2 --- /dev/null +++ b/tests/draft-next/optional/id.json @@ -0,0 +1,53 @@ +[ + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft-next/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft-next/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/refOfUnknownKeyword.json b/tests/draft-next/optional/refOfUnknownKeyword.json index 489701cd2..c832e09f6 100644 --- a/tests/draft-next/optional/refOfUnknownKeyword.json +++ b/tests/draft-next/optional/refOfUnknownKeyword.json @@ -42,5 +42,28 @@ "valid": false } ] + }, + { + "description": "reference internals of known non-applicator", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "/base", + "examples": [ + { "type": "string" } + ], + "$ref": "#/examples/0" + }, + "tests": [ + { + "description": "match", + "data": "a string", + "valid": true + }, + { + "description": "mismatch", + "data": 42, + "valid": false + } + ] } ] diff --git a/tests/draft-next/unknownKeyword.json b/tests/draft-next/optional/unknownKeyword.json similarity index 100% rename from tests/draft-next/unknownKeyword.json rename to tests/draft-next/optional/unknownKeyword.json diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json index 1d5f25613..8417ce299 100644 --- a/tests/draft-next/ref.json +++ b/tests/draft-next/ref.json @@ -862,6 +862,7 @@ { "description": "URN ref with nested pointer ref", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -887,6 +888,7 @@ { "description": "ref to if", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -909,6 +911,7 @@ { "description": "ref to then", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -931,6 +934,7 @@ { "description": "ref to else", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -953,6 +957,7 @@ { "description": "ref with absolute-path-reference", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -982,6 +987,7 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -1006,6 +1012,7 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1030,6 +1037,7 @@ { "description": "empty tokens in $ref json-pointer", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$defs": { "": { "$defs": { diff --git a/tests/draft-next/refRemote.json b/tests/draft-next/refRemote.json index 9befceb25..647fb9f19 100644 --- a/tests/draft-next/refRemote.json +++ b/tests/draft-next/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/draft-next/subSchemas-defs.json#/$defs/integer" + "$ref": "http://localhost:1234/draft-next/subSchemas.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/next/schema", - "$ref": "http://localhost:1234/draft-next/subSchemas-defs.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft-next/subSchemas.json#/$defs/refToInteger" }, "tests": [ { @@ -265,7 +265,10 @@ }, { "description": "remote HTTP ref with different $id", - "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/different-id-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -281,7 +284,10 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/urn-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -297,7 +303,10 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" + }, "tests": [ { "description": "number is invalid", @@ -314,6 +323,7 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "$ref": "http://localhost:1234/draft-next/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft-next/unevaluatedItems.json b/tests/draft-next/unevaluatedItems.json index 7379afb41..08f6ef128 100644 --- a/tests/draft-next/unevaluatedItems.json +++ b/tests/draft-next/unevaluatedItems.json @@ -461,6 +461,79 @@ } ] }, + { + "description": "unevaluatedItems before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": false, + "prefixItems": [ + { "type": "string" } + ], + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "prefixItems": [ + true, + { "type": "string" } + ] + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived", + + "$ref": "./baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "prefixItems": [ + true, + { "type": "string" } + ] + }, + "baseSchema": { + "$id": "./baseSchema", + + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "type": "array", + "prefixItems": [ + { "type": "string" } + ], + "$dynamicRef": "#addons" + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json index 69fe8a00c..13fe6e03a 100644 --- a/tests/draft-next/unevaluatedProperties.json +++ b/tests/draft-next/unevaluatedProperties.json @@ -715,6 +715,92 @@ } ] }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "unevaluatedProperties": false, + "properties": { + "foo": { "type": "string" } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { "type": "string" } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://example.com/unevaluated-properties-with-dynamic-ref/derived", + + "$ref": "./baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "properties": { + "bar": { "type": "string" } + } + }, + "baseSchema": { + "$id": "./baseSchema", + + "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "$dynamicRef": "#addons" + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1365,57 +1451,6 @@ } ] }, - { - "description": "unevaluatedProperties depends on adjacent contains", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "properties": { - "foo": { "type": "number" } - }, - "contains": { "type": "string" }, - "unevaluatedProperties": false - }, - "tests": [ - { - "description": "bar is evaluated by contains", - "data": { "foo": 1, "bar": "foo" }, - "valid": true - }, - { - "description": "contains fails, bar is not evaluated", - "data": { "foo": 1, "bar": 2 }, - "valid": false - }, - { - "description": "contains passes, bar is not evaluated", - "data": { "foo": 1, "bar": 2, "baz": "foo" }, - "valid": false - } - ] - }, - { - "description": "unevaluatedProperties depends on multiple nested contains", - "schema": { - "$schema": "https://json-schema.org/draft/next/schema", - "allOf": [ - { "contains": { "multipleOf": 2 } }, - { "contains": { "multipleOf": 3 } } - ], - "unevaluatedProperties": { "multipleOf": 5 } - }, - "tests": [ - { - "description": "5 not evaluated, passes unevaluatedItems", - "data": { "a": 2, "b": 3, "c": 4, "d": 5, "e": 6 }, - "valid": true - }, - { - "description": "7 not evaluated, fails unevaluatedItems", - "data": { "a": 2, "b": 3, "c": 4, "d": 7, "e": 8 }, - "valid": false - } - ] - }, { "description": "non-object instances are valid", "schema": { @@ -1568,5 +1603,74 @@ "valid": false } ] + }, + { + "description": "propertyDependencies with unevaluatedProperties" , + "schema" : { + "$schema": "https://json-schema.org/draft/next/schema", + "properties" : {"foo2" : {}}, + "propertyDependencies": { + "foo" : {}, + "foo2": { + "bar": { + "properties": { + "buz": {} + } + } + } + }, + "unevaluatedProperties": false + }, + + "tests": [ + { + "description": "unevaluatedProperties doesn't consider propertyDependencies" , + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "unevaluatedProperties sees buz when foo2 is present", + "data": {"foo2": "bar", "buz": ""}, + "valid": true + }, + { + "description": "unevaluatedProperties doesn't see buz when foo2 is absent", + "data": {"buz": ""}, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/additionalItems.json b/tests/draft2019-09/additionalItems.json index aa44bcb76..9a7ae4f8a 100644 --- a/tests/draft2019-09/additionalItems.json +++ b/tests/draft2019-09/additionalItems.json @@ -182,6 +182,26 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft2019-09/additionalProperties.json b/tests/draft2019-09/additionalProperties.json index f9f03bb04..73f9b909e 100644 --- a/tests/draft2019-09/additionalProperties.json +++ b/tests/draft2019-09/additionalProperties.json @@ -152,5 +152,62 @@ "valid": true } ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "Valid against both keywords", + "data": { "apple": 4 }, + "valid": true + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { "fig": 2, "pear": "available" }, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index 5d8c86f11..bce05e800 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -81,64 +81,6 @@ } ] }, - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - }, { "description": "same $anchor with different base uri", "schema": { @@ -174,62 +116,5 @@ "valid": false } ] - }, - { - "description": "non-schema object containing an $anchor property", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/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 - } - ] - }, - { - "description": "invalid anchors", - "comment": "Section 8.2.3", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "MUST start with a letter (and not #)", - "data": { "$anchor" : "#foo" }, - "valid": false - }, - { - "description": "JSON pointers are not valid", - "data": { "$anchor" : "/a/b" }, - "valid": false - }, - { - "description": "invalid with valid beginning", - "data": { "$anchor" : "foo#something" }, - "valid": false - } - ] } ] diff --git a/tests/draft2019-09/dependentSchemas.json b/tests/draft2019-09/dependentSchemas.json index 3577efdf4..c5b8ea05f 100644 --- a/tests/draft2019-09/dependentSchemas.json +++ b/tests/draft2019-09/dependentSchemas.json @@ -132,6 +132,7 @@ { "description": "dependent subschema incompatible with root", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {} }, diff --git a/tests/draft2019-09/enum.json b/tests/draft2019-09/enum.json index f9a44a61d..1315211ea 100644 --- a/tests/draft2019-09/enum.json +++ b/tests/draft2019-09/enum.json @@ -168,6 +168,30 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [[false]] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": { @@ -192,6 +216,30 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [[true]] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": { @@ -216,6 +264,30 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [[0]] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": { @@ -240,6 +312,30 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [[1]] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json deleted file mode 100644 index e2e403f0b..000000000 --- a/tests/draft2019-09/id.json +++ /dev/null @@ -1,294 +0,0 @@ -[ - { - "description": "Invalid use of fragments in location-independent $id", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "Identifier name", - "data": { - "$ref": "#foo", - "$defs": { - "A": { - "$id": "#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name and no ref", - "data": { - "$defs": { - "A": { "$id": "#foo" } - } - }, - "valid": false - }, - { - "description": "Identifier path", - "data": { - "$ref": "#/a/b", - "$defs": { - "A": { - "$id": "#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2019-09/bar#foo", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/bar#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier path with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2019-09/bar#/a/b", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/bar#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2019-09/root", - "$ref": "http://localhost:1234/draft2019-09/nested.json#foo", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#foo", - "type": "integer" - } - } - } - } - }, - "valid": false - }, - { - "description": "Identifier path with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2019-09/root", - "$ref": "http://localhost:1234/draft2019-09/nested.json#/a/b", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#/a/b", - "type": "integer" - } - } - } - } - }, - "valid": false - } - ] - }, - { - "description": "Valid use of empty fragments in location-independent $id", - "comment": "These are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2019-09/bar", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/bar#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2019-09/root", - "$ref": "http://localhost:1234/draft2019-09/nested.json#/$defs/B", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#", - "type": "integer" - } - } - } - } - }, - "valid": true - } - ] - }, - { - "description": "Unnormalized $ids are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "Unnormalized identifier", - "data": { - "$ref": "http://localhost:1234/draft2019-09/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment", - "data": { - "$ref": "http://localhost:1234/draft2019-09/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2019-09/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - } - ] - }, - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft2019-09/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - }, - { - "description": "non-schema object containing an $id property", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/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/maxLength.json b/tests/draft2019-09/maxLength.json index f242c3eff..a0cc7d9b8 100644 --- a/tests/draft2019-09/maxLength.json +++ b/tests/draft2019-09/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft2019-09/minLength.json b/tests/draft2019-09/minLength.json index 19dec2cac..12782660c 100644 --- a/tests/draft2019-09/minLength.json +++ b/tests/draft2019-09/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft2019-09/not.json b/tests/draft2019-09/not.json index 62c9af9de..d90728c7b 100644 --- a/tests/draft2019-09/not.json +++ b/tests/draft2019-09/not.json @@ -97,25 +97,173 @@ ] }, { - "description": "not with boolean schema true", + "description": "forbid everything with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": {} + }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "not": true }, "tests": [ { - "description": "any value is invalid", + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", "data": "foo", "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false } ] }, { - "description": "not with boolean schema false", + "description": "allow everything with boolean schema false", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "double negation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { "not": {} } + }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft2019-09/oneOf.json b/tests/draft2019-09/oneOf.json index 9b7a2204e..c27d4865c 100644 --- a/tests/draft2019-09/oneOf.json +++ b/tests/draft2019-09/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", diff --git a/tests/draft2019-09/optional/anchor.json b/tests/draft2019-09/optional/anchor.json new file mode 100644 index 000000000..45951d0a3 --- /dev/null +++ b/tests/draft2019-09/optional/anchor.json @@ -0,0 +1,60 @@ +[ + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/format/duration.json b/tests/draft2019-09/optional/format/duration.json index 00d5f47ae..2d515a64a 100644 --- a/tests/draft2019-09/optional/format/duration.json +++ b/tests/draft2019-09/optional/format/duration.json @@ -46,6 +46,11 @@ "data": "PT1D", "valid": false }, + { + "description": "must start with P", + "data": "4DT12H30M5S", + "valid": false + }, { "description": "no elements present", "data": "P", diff --git a/tests/draft2019-09/optional/format/hostname.json b/tests/draft2019-09/optional/format/hostname.json index f3b7181c8..24bfdfc5a 100644 --- a/tests/draft2019-09/optional/format/hostname.json +++ b/tests/draft2019-09/optional/format/hostname.json @@ -120,6 +120,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/idn-hostname.json b/tests/draft2019-09/optional/format/idn-hostname.json index 72f179751..348c504c8 100644 --- a/tests/draft2019-09/optional/format/idn-hostname.json +++ b/tests/draft2019-09/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0660\u06f0", + "data": "\u0628\u0660\u06f0", "valid": false }, { @@ -301,6 +301,88 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true + }, + { + "description": "single label", + "data": "hostname", + "valid": true + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + } + ] + }, + { + "description": "validation of separators in internationalized host names", + "specification": [ + {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} + ], + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "single dot", + "data": ".", + "valid": false + }, + { + "description": "single ideographic full stop", + "data": "\u3002", + "valid": false + }, + { + "description": "single fullwidth full stop", + "data": "\uff0e", + "valid": false + }, + { + "description": "single halfwidth ideographic full stop", + "data": "\uff61", + "valid": false + }, + { + "description": "dot as label separator", + "data": "a.b", + "valid": true + }, + { + "description": "ideographic full stop as label separator", + "data": "a\u3002b", + "valid": true + }, + { + "description": "fullwidth full stop as label separator", + "data": "a\uff0eb", + "valid": true + }, + { + "description": "halfwidth ideographic full stop as label separator", + "data": "a\uff61b", + "valid": true } ] } diff --git a/tests/draft2019-09/optional/format/ipv4.json b/tests/draft2019-09/optional/format/ipv4.json index ac1e14c68..efe42471b 100644 --- a/tests/draft2019-09/optional/format/ipv4.json +++ b/tests/draft2019-09/optional/format/ipv4.json @@ -81,6 +81,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/id.json b/tests/draft2019-09/optional/id.json new file mode 100644 index 000000000..4daa8f51f --- /dev/null +++ b/tests/draft2019-09/optional/id.json @@ -0,0 +1,53 @@ +[ + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft2019-09/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/refOfUnknownKeyword.json b/tests/draft2019-09/optional/refOfUnknownKeyword.json index eee1c33ed..e9a75dd1e 100644 --- a/tests/draft2019-09/optional/refOfUnknownKeyword.json +++ b/tests/draft2019-09/optional/refOfUnknownKeyword.json @@ -42,5 +42,28 @@ "valid": false } ] + }, + { + "description": "reference internals of known non-applicator", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "/base", + "examples": [ + { "type": "string" } + ], + "$ref": "#/examples/0" + }, + "tests": [ + { + "description": "match", + "data": "a string", + "valid": true + }, + { + "description": "mismatch", + "data": 42, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/unknownKeyword.json b/tests/draft2019-09/optional/unknownKeyword.json similarity index 100% rename from tests/draft2019-09/unknownKeyword.json rename to tests/draft2019-09/optional/unknownKeyword.json diff --git a/tests/draft2019-09/propertyNames.json b/tests/draft2019-09/propertyNames.json index b7fecbf71..3b2bb23bb 100644 --- a/tests/draft2019-09/propertyNames.json +++ b/tests/draft2019-09/propertyNames.json @@ -111,5 +111,58 @@ "valid": true } ] + }, + { + "description": "propertyNames with const", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": {"const": "foo"} + }, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": {"enum": ["foo", "bar"]} + }, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property foo and bar is valid", + "data": {"foo": 1, "bar": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"baz": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index 7d850414d..eff5305c3 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -791,21 +791,6 @@ } ] }, - { - "description": "URN base URI with f-component", - "schema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", - "$ref": "https://json-schema.org/draft/2019-09/schema" - }, - "tests": [ - { - "description": "is invalid", - "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, - "valid": false - } - ] - }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { @@ -862,6 +847,7 @@ { "description": "URN ref with nested pointer ref", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -887,6 +873,7 @@ { "description": "ref to if", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -909,6 +896,7 @@ { "description": "ref to then", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -931,6 +919,7 @@ { "description": "ref to else", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -953,6 +942,7 @@ { "description": "ref with absolute-path-reference", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -982,6 +972,7 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -1006,6 +997,7 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1030,6 +1022,7 @@ { "description": "empty tokens in $ref json-pointer", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$defs": { "": { "$defs": { @@ -1055,5 +1048,43 @@ "valid": false } ] - } + }, + { + "description": "$ref with $recursiveAnchor", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/schemas/unevaluated-items-are-disallowed", + "$ref": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "unevaluatedItems": false, + "$defs": { + "/schemas/unevaluated-items-are-allowed": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "type": "array", + "items": [ + { + "type": "string" + }, + { + "$ref": "#" + } + ] + } + } + }, + "tests": [ + { + "description": "extra items allowed for inner arrays", + "data" : ["foo",["bar" , [] , 8]], + "valid": true + }, + { + "description": "extra items disallowed for root", + "data" : ["foo",["bar" , [] , 8], 8], + "valid": false + } + ] + } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 0bacbfc2e..072894cf2 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/integer" + "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/refToInteger" }, "tests": [ { @@ -265,7 +265,10 @@ }, { "description": "remote HTTP ref with different $id", - "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/different-id-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -281,7 +284,10 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/urn-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -297,7 +303,10 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" + }, "tests": [ { "description": "number is invalid", @@ -314,6 +323,7 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "http://localhost:1234/draft2019-09/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json index 53565a0b9..8e2ee4b11 100644 --- a/tests/draft2019-09/unevaluatedItems.json +++ b/tests/draft2019-09/unevaluatedItems.json @@ -480,6 +480,82 @@ } ] }, + { + "description": "unevaluatedItems before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false, + "items": [ + { "type": "string" } + ], + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "items": [ + true, + { "type": "string" } + ] + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/unevaluated-items-with-recursive-ref/extended-tree", + + "$recursiveAnchor": true, + + "$ref": "./tree", + "items": [ + true, + true, + { "type": "string" } + ], + + "$defs": { + "tree": { + "$id": "./tree", + "$recursiveAnchor": true, + + "type": "array", + "items": [ + { "type": "number" }, + { + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "$recursiveRef": "#" + } + ] + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [1, [2, [], "b"], "a"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": [1, [2, [], "b", "too many"], "a"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json index a6cce8bb6..e8765112c 100644 --- a/tests/draft2019-09/unevaluatedProperties.json +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -715,6 +715,102 @@ } ] }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": false, + "properties": { + "foo": { "type": "string" } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { "type": "string" } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/unevaluated-properties-with-recursive-ref/extended-tree", + + "$recursiveAnchor": true, + + "$ref": "./tree", + "properties": { + "name": { "type": "string" } + }, + + "$defs": { + "tree": { + "$id": "./tree", + "$recursiveAnchor": true, + + "type": "object", + "properties": { + "node": true, + "branches": { + "$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "$recursiveRef": "#" + } + }, + "required": ["node"] + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "name": "b", + "node": 2 + } + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "foo": "b", + "node": 2 + } + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -1471,5 +1567,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json index 29e69c135..9618575e2 100644 --- a/tests/draft2020-12/additionalProperties.json +++ b/tests/draft2020-12/additionalProperties.json @@ -2,6 +2,7 @@ { "description": "additionalProperties being false does not allow other properties", + "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -43,6 +44,7 @@ }, { "description": "non-ASCII pattern with additionalProperties", + "specification": [ { "core":"10.3.2.3"} ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "patternProperties": {"^á": {}}, @@ -63,6 +65,7 @@ }, { "description": "additionalProperties with schema", + "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}}, @@ -87,8 +90,8 @@ ] }, { - "description": - "additionalProperties can exist by itself", + "description": "additionalProperties can exist by itself", + "specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": {"type": "boolean"} @@ -108,6 +111,7 @@ }, { "description": "additionalProperties are allowed by default", + "specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": {"foo": {}, "bar": {}} @@ -122,6 +126,7 @@ }, { "description": "additionalProperties does not look in applicators", + "specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "allOf": [ @@ -139,6 +144,7 @@ }, { "description": "additionalProperties with null valued instance properties", + "specification": [ { "core":"10.3.2.3" } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": { @@ -152,5 +158,62 @@ "valid": true } ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "Valid against both keywords", + "data": { "apple": 4 }, + "valid": true + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { "fig": 2, "pear": "available" }, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 423835dac..99143fa11 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -81,64 +81,6 @@ } ] }, - { - "description": "$anchor inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $anchor buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "anchor_in_enum": { - "enum": [ - { - "$anchor": "my_anchor", - "type": "null" - } - ] - }, - "real_identifier_in_schema": { - "$anchor": "my_anchor", - "type": "string" - }, - "zzz_anchor_in_const": { - "const": { - "$anchor": "my_anchor", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/anchor_in_enum" }, - { "$ref": "#my_anchor" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$anchor": "my_anchor", - "type": "null" - }, - "valid": true - }, - { - "description": "in implementations that strip $anchor, this may match either $def", - "data": { - "type": "null" - }, - "valid": false - }, - { - "description": "match $ref to $anchor", - "data": "a string to match #/$defs/anchor_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $anchor", - "data": 1, - "valid": false - } - ] - }, { "description": "same $anchor with different base uri", "schema": { @@ -174,62 +116,5 @@ "valid": false } ] - }, - { - "description": "non-schema object containing an $anchor property", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/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 - } - ] - }, - { - "description": "invalid anchors", - "comment": "Section 8.2.2", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "MUST start with a letter (and not #)", - "data": { "$anchor" : "#foo" }, - "valid": false - }, - { - "description": "JSON pointers are not valid", - "data": { "$anchor" : "/a/b" }, - "valid": false - }, - { - "description": "invalid with valid beginning", - "data": { "$anchor" : "foo#something" }, - "valid": false - } - ] } ] diff --git a/tests/draft2020-12/dependentSchemas.json b/tests/draft2020-12/dependentSchemas.json index 66ac0eb43..1c5f0574a 100644 --- a/tests/draft2020-12/dependentSchemas.json +++ b/tests/draft2020-12/dependentSchemas.json @@ -132,6 +132,7 @@ { "description": "dependent subschema incompatible with root", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": {} }, diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json index c1c56cb8a..ffa211ba2 100644 --- a/tests/draft2020-12/dynamicRef.json +++ b/tests/draft2020-12/dynamicRef.json @@ -726,5 +726,90 @@ "valid": false } ] + }, + { + "description": "$dynamicRef points to a boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "true": true, + "false": false + }, + "properties": { + "true": { + "$dynamicRef": "#/$defs/true" + }, + "false": { + "$dynamicRef": "#/$defs/false" + } + } + }, + "tests": [ + { + "description": "follow $dynamicRef to a true schema", + "data": { "true": 1 }, + "valid": true + }, + { + "description": "follow $dynamicRef to a false schema", + "data": { "false": 1 }, + "valid": false + } + ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/enum.json b/tests/draft2020-12/enum.json index 0d780b2ac..c8f35eacf 100644 --- a/tests/draft2020-12/enum.json +++ b/tests/draft2020-12/enum.json @@ -168,6 +168,30 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [[false]] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": { @@ -192,6 +216,30 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [[true]] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": { @@ -216,6 +264,30 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [[0]] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": { @@ -240,6 +312,30 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [[1]] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { diff --git a/tests/draft2020-12/id.json b/tests/draft2020-12/id.json deleted file mode 100644 index 0ae5fe68a..000000000 --- a/tests/draft2020-12/id.json +++ /dev/null @@ -1,294 +0,0 @@ -[ - { - "description": "Invalid use of fragments in location-independent $id", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "Identifier name", - "data": { - "$ref": "#foo", - "$defs": { - "A": { - "$id": "#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name and no ref", - "data": { - "$defs": { - "A": { "$id": "#foo" } - } - }, - "valid": false - }, - { - "description": "Identifier path", - "data": { - "$ref": "#/a/b", - "$defs": { - "A": { - "$id": "#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2020-12/bar#foo", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/bar#foo", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier path with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2020-12/bar#/a/b", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/bar#/a/b", - "type": "integer" - } - } - }, - "valid": false - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2020-12/root", - "$ref": "http://localhost:1234/draft2020-12/nested.json#foo", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#foo", - "type": "integer" - } - } - } - } - }, - "valid": false - }, - { - "description": "Identifier path with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2020-12/root", - "$ref": "http://localhost:1234/draft2020-12/nested.json#/a/b", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#/a/b", - "type": "integer" - } - } - } - } - }, - "valid": false - } - ] - }, - { - "description": "Valid use of empty fragments in location-independent $id", - "comment": "These are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "Identifier name with absolute URI", - "data": { - "$ref": "http://localhost:1234/draft2020-12/bar", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/bar#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Identifier name with base URI change in subschema", - "data": { - "$id": "http://localhost:1234/draft2020-12/root", - "$ref": "http://localhost:1234/draft2020-12/nested.json#/$defs/B", - "$defs": { - "A": { - "$id": "nested.json", - "$defs": { - "B": { - "$id": "#", - "type": "integer" - } - } - } - } - }, - "valid": true - } - ] - }, - { - "description": "Unnormalized $ids are allowed but discouraged", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "Unnormalized identifier", - "data": { - "$ref": "http://localhost:1234/draft2020-12/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment", - "data": { - "$ref": "http://localhost:1234/draft2020-12/foo/baz", - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - }, - { - "description": "Unnormalized identifier with empty fragment and no ref", - "data": { - "$defs": { - "A": { - "$id": "http://localhost:1234/draft2020-12/foo/bar/../baz#", - "type": "integer" - } - } - }, - "valid": true - } - ] - }, - { - "description": "$id inside an enum is not a real identifier", - "comment": "the implementation must not be confused by an $id buried in the enum", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "id_in_enum": { - "enum": [ - { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - } - ] - }, - "real_id_in_schema": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "string" - }, - "zzz_id_in_const": { - "const": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - } - } - }, - "anyOf": [ - { "$ref": "#/$defs/id_in_enum" }, - { "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" } - ] - }, - "tests": [ - { - "description": "exact match to enum, and type matches", - "data": { - "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", - "type": "null" - }, - "valid": true - }, - { - "description": "match $ref to $id", - "data": "a string to match #/$defs/id_in_enum", - "valid": true - }, - { - "description": "no match on enum or $ref to $id", - "data": 1, - "valid": false - } - ] - }, - { - "description": "non-schema object containing an $id property", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/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/items.json b/tests/draft2020-12/items.json index 1ef18bdd0..6a3e1cf26 100644 --- a/tests/draft2020-12/items.json +++ b/tests/draft2020-12/items.json @@ -265,6 +265,26 @@ } ] }, + { + "description": "items with heterogeneous array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{}], + "items": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "items with null instance elements", "schema": { diff --git a/tests/draft2020-12/maxLength.json b/tests/draft2020-12/maxLength.json index b6eb03401..7462726d7 100644 --- a/tests/draft2020-12/maxLength.json +++ b/tests/draft2020-12/maxLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft2020-12/minLength.json b/tests/draft2020-12/minLength.json index e0930b6fb..5076c5a92 100644 --- a/tests/draft2020-12/minLength.json +++ b/tests/draft2020-12/minLength.json @@ -27,7 +27,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft2020-12/not.json b/tests/draft2020-12/not.json index 57e45ba39..d0f2b6e84 100644 --- a/tests/draft2020-12/not.json +++ b/tests/draft2020-12/not.json @@ -97,25 +97,173 @@ ] }, { - "description": "not with boolean schema true", + "description": "forbid everything with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": {} + }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "not": true }, "tests": [ { - "description": "any value is invalid", + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", "data": "foo", "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false } ] }, { - "description": "not with boolean schema false", + "description": "allow everything with boolean schema false", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "double negation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { "not": {} } + }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft2020-12/oneOf.json b/tests/draft2020-12/oneOf.json index 416c8e570..7a7c7ffe3 100644 --- a/tests/draft2020-12/oneOf.json +++ b/tests/draft2020-12/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", diff --git a/tests/draft2020-12/optional/anchor.json b/tests/draft2020-12/optional/anchor.json new file mode 100644 index 000000000..6d6713be5 --- /dev/null +++ b/tests/draft2020-12/optional/anchor.json @@ -0,0 +1,60 @@ +[ + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/anchor_in_enum" }, + { "$ref": "#my_anchor" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/dynamicRef.json b/tests/draft2020-12/optional/dynamicRef.json new file mode 100644 index 000000000..7e63f209a --- /dev/null +++ b/tests/draft2020-12/optional/dynamicRef.json @@ -0,0 +1,56 @@ +[ + { + "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "bar#/$defs/item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] + }] \ No newline at end of file diff --git a/tests/draft2020-12/optional/ecmascript-regex.json b/tests/draft2020-12/optional/ecmascript-regex.json index 23b962e4b..a4d62e0cf 100644 --- a/tests/draft2020-12/optional/ecmascript-regex.json +++ b/tests/draft2020-12/optional/ecmascript-regex.json @@ -405,20 +405,6 @@ } ] }, - { - "description": "\\a is not an ECMA 262 control escape", - "schema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "when used as a pattern", - "data": { "pattern": "\\a" }, - "valid": false - } - ] - }, { "description": "pattern with non-ASCII digits", "schema": { diff --git a/tests/draft2020-12/optional/format/duration.json b/tests/draft2020-12/optional/format/duration.json index a3af56ef0..a09fec5ef 100644 --- a/tests/draft2020-12/optional/format/duration.json +++ b/tests/draft2020-12/optional/format/duration.json @@ -46,6 +46,11 @@ "data": "PT1D", "valid": false }, + { + "description": "must start with P", + "data": "4DT12H30M5S", + "valid": false + }, { "description": "no elements present", "data": "P", diff --git a/tests/draft2020-12/optional/format/ecmascript-regex.json b/tests/draft2020-12/optional/format/ecmascript-regex.json new file mode 100644 index 000000000..b0648084a --- /dev/null +++ b/tests/draft2020-12/optional/format/ecmascript-regex.json @@ -0,0 +1,16 @@ +[ + { + "description": "\\a is not an ECMA 262 control escape", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "tests": [ + { + "description": "when used as a pattern", + "data": "\\a", + "valid": false + } + ] + } +] \ No newline at end of file diff --git a/tests/draft2020-12/optional/format/hostname.json b/tests/draft2020-12/optional/format/hostname.json index 41418dd4a..57827c4d4 100644 --- a/tests/draft2020-12/optional/format/hostname.json +++ b/tests/draft2020-12/optional/format/hostname.json @@ -120,6 +120,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft2020-12/optional/format/idn-hostname.json b/tests/draft2020-12/optional/format/idn-hostname.json index 5549c0550..f42ae969b 100644 --- a/tests/draft2020-12/optional/format/idn-hostname.json +++ b/tests/draft2020-12/optional/format/idn-hostname.json @@ -257,7 +257,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0660\u06f0", + "data": "\u0628\u0660\u06f0", "valid": false }, { @@ -301,6 +301,88 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true + }, + { + "description": "single label", + "data": "hostname", + "valid": true + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + } + ] + }, + { + "description": "validation of separators in internationalized host names", + "specification": [ + {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} + ], + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "single dot", + "data": ".", + "valid": false + }, + { + "description": "single ideographic full stop", + "data": "\u3002", + "valid": false + }, + { + "description": "single fullwidth full stop", + "data": "\uff0e", + "valid": false + }, + { + "description": "single halfwidth ideographic full stop", + "data": "\uff61", + "valid": false + }, + { + "description": "dot as label separator", + "data": "a.b", + "valid": true + }, + { + "description": "ideographic full stop as label separator", + "data": "a\u3002b", + "valid": true + }, + { + "description": "fullwidth full stop as label separator", + "data": "a\uff0eb", + "valid": true + }, + { + "description": "halfwidth ideographic full stop as label separator", + "data": "a\uff61b", + "valid": true } ] } diff --git a/tests/draft2020-12/optional/format/ipv4.json b/tests/draft2020-12/optional/format/ipv4.json index c72b6fc22..86d27bdb7 100644 --- a/tests/draft2020-12/optional/format/ipv4.json +++ b/tests/draft2020-12/optional/format/ipv4.json @@ -81,6 +81,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft2020-12/optional/id.json b/tests/draft2020-12/optional/id.json new file mode 100644 index 000000000..0b7df4e80 --- /dev/null +++ b/tests/draft2020-12/optional/id.json @@ -0,0 +1,53 @@ +[ + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_enum" }, + { "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/refOfUnknownKeyword.json b/tests/draft2020-12/optional/refOfUnknownKeyword.json index f91c18884..c2b080a1e 100644 --- a/tests/draft2020-12/optional/refOfUnknownKeyword.json +++ b/tests/draft2020-12/optional/refOfUnknownKeyword.json @@ -42,5 +42,28 @@ "valid": false } ] + }, + { + "description": "reference internals of known non-applicator", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "/base", + "examples": [ + { "type": "string" } + ], + "$ref": "#/examples/0" + }, + "tests": [ + { + "description": "match", + "data": "a string", + "valid": true + }, + { + "description": "mismatch", + "data": 42, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/unknownKeyword.json b/tests/draft2020-12/optional/unknownKeyword.json similarity index 100% rename from tests/draft2020-12/unknownKeyword.json rename to tests/draft2020-12/optional/unknownKeyword.json diff --git a/tests/draft2020-12/propertyNames.json b/tests/draft2020-12/propertyNames.json index 7ecfb7ec3..b4780088a 100644 --- a/tests/draft2020-12/propertyNames.json +++ b/tests/draft2020-12/propertyNames.json @@ -44,6 +44,36 @@ } ] }, + { + "description": "propertyNames validation with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { "pattern": "^a+$" } + }, + "tests": [ + { + "description": "matching property names valid", + "data": { + "a": {}, + "aa": {}, + "aaa": {} + }, + "valid": true + }, + { + "description": "non-matching property name is invalid", + "data": { + "aaA": {} + }, + "valid": false + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + } + ] + }, { "description": "propertyNames with boolean schema true", "schema": { @@ -81,5 +111,58 @@ "valid": true } ] + }, + { + "description": "propertyNames with const", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": {"const": "foo"} + }, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": {"enum": ["foo", "bar"]} + }, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property foo and bar is valid", + "data": {"foo": 1, "bar": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"baz": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft2020-12/ref.json b/tests/draft2020-12/ref.json index 5f6be8c20..a1d3efaf7 100644 --- a/tests/draft2020-12/ref.json +++ b/tests/draft2020-12/ref.json @@ -791,21 +791,6 @@ } ] }, - { - "description": "URN base URI with f-component", - "schema": { - "$comment": "RFC 8141 §2.3.3, but we don't allow fragments", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema" - }, - "tests": [ - { - "description": "is invalid", - "data": {"$id": "urn:example:foo-bar-baz-qux#somepart"}, - "valid": false - } - ] - }, { "description": "URN base URI with URN and JSON pointer ref", "schema": { @@ -862,6 +847,7 @@ { "description": "URN ref with nested pointer ref", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", "$defs": { "foo": { @@ -887,6 +873,7 @@ { "description": "ref to if", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/if", "if": { "$id": "http://example.com/ref/if", @@ -909,6 +896,7 @@ { "description": "ref to then", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/then", "then": { "$id": "http://example.com/ref/then", @@ -931,6 +919,7 @@ { "description": "ref to else", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://example.com/ref/else", "else": { "$id": "http://example.com/ref/else", @@ -953,6 +942,7 @@ { "description": "ref with absolute-path-reference", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "http://example.com/ref/absref.json", "$defs": { "a": { @@ -982,6 +972,7 @@ { "description": "$id with file URI still resolves pointers - *nix", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "file:///folder/file.json", "$defs": { "foo": { @@ -1006,6 +997,7 @@ { "description": "$id with file URI still resolves pointers - windows", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "file:///c:/folder/file.json", "$defs": { "foo": { @@ -1030,6 +1022,7 @@ { "description": "empty tokens in $ref json-pointer", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$defs": { "": { "$defs": { diff --git a/tests/draft2020-12/refRemote.json b/tests/draft2020-12/refRemote.json index ea4177f0a..047ac74ca 100644 --- a/tests/draft2020-12/refRemote.json +++ b/tests/draft2020-12/refRemote.json @@ -22,7 +22,7 @@ "description": "fragment within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/draft2020-12/subSchemas-defs.json#/$defs/integer" + "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/integer" }, "tests": [ { @@ -60,7 +60,7 @@ "description": "ref within remote ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://localhost:1234/draft2020-12/subSchemas-defs.json#/$defs/refToInteger" + "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/refToInteger" }, "tests": [ { @@ -265,7 +265,10 @@ }, { "description": "remote HTTP ref with different $id", - "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/different-id-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -281,7 +284,10 @@ }, { "description": "remote HTTP ref with different URN $id", - "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/urn-ref-string.json" + }, "tests": [ { "description": "number is invalid", @@ -297,7 +303,10 @@ }, { "description": "remote HTTP ref with nested absolute ref", - "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" + }, "tests": [ { "description": "number is invalid", @@ -314,6 +323,7 @@ { "description": "$ref to $ref finds detached $anchor", "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "http://localhost:1234/draft2020-12/detached-ref.json#/$defs/foo" }, "tests": [ diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index 2615c4c41..f861cefad 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -461,6 +461,86 @@ } ] }, + { + "description": "unevaluatedItems before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false, + "prefixItems": [ + { "type": "string" } + ], + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "prefixItems": [ + true, + { "type": "string" } + ] + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived", + + "$ref": "./baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "prefixItems": [ + true, + { "type": "string" } + ] + }, + "baseSchema": { + "$id": "./baseSchema", + + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "type": "array", + "prefixItems": [ + { "type": "string" } + ], + "$dynamicRef": "#addons", + + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, { "description": "unevaluatedItems can't see inside cousins", "schema": { @@ -713,7 +793,6 @@ "data": [ "b" ], "valid": false } - ] } ] diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json index f7fb420ff..0da38f679 100644 --- a/tests/draft2020-12/unevaluatedProperties.json +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -3,7 +3,6 @@ "description": "unevaluatedProperties true", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "unevaluatedProperties": true }, "tests": [ @@ -25,7 +24,6 @@ "description": "unevaluatedProperties schema", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "unevaluatedProperties": { "type": "string", "minLength": 3 @@ -57,7 +55,6 @@ "description": "unevaluatedProperties false", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "unevaluatedProperties": false }, "tests": [ @@ -79,7 +76,6 @@ "description": "unevaluatedProperties with adjacent properties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -107,7 +103,6 @@ "description": "unevaluatedProperties with adjacent patternProperties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "patternProperties": { "^foo": { "type": "string" } }, @@ -132,13 +127,9 @@ ] }, { - "description": "unevaluatedProperties with adjacent additionalProperties", + "description": "unevaluatedProperties with adjacent bool additionalProperties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": { - "foo": { "type": "string" } - }, "additionalProperties": true, "unevaluatedProperties": false }, @@ -160,11 +151,35 @@ } ] }, + { + "description": "unevaluatedProperties with adjacent non-bool additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": { "type": "string" }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with only valid additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with invalid additional properties", + "data": { + "foo": "foo", + "bar": 1 + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties with nested properties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -201,7 +216,6 @@ "description": "unevaluatedProperties with nested patternProperties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -238,7 +252,6 @@ "description": "unevaluatedProperties with nested additionalProperties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -271,7 +284,6 @@ "description": "unevaluatedProperties with nested unevaluatedProperties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -307,7 +319,6 @@ "description": "unevaluatedProperties with anyOf", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -376,7 +387,6 @@ "description": "unevaluatedProperties with oneOf", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -420,7 +430,6 @@ "description": "unevaluatedProperties with not", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -449,7 +458,6 @@ "description": "unevaluatedProperties with if/then/else", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "if": { "properties": { "foo": { "const": "then" } @@ -509,7 +517,6 @@ "description": "unevaluatedProperties with if/then/else, then not defined", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "if": { "properties": { "foo": { "const": "then" } @@ -563,7 +570,6 @@ "description": "unevaluatedProperties with if/then/else, else not defined", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "if": { "properties": { "foo": { "const": "then" } @@ -617,7 +623,6 @@ "description": "unevaluatedProperties with dependentSchemas", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -653,7 +658,6 @@ "description": "unevaluatedProperties with boolean schemas", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -681,7 +685,6 @@ "description": "unevaluatedProperties with $ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "$ref": "#/$defs/bar", "properties": { "foo": { "type": "string" } @@ -715,6 +718,97 @@ } ] }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedProperties": false, + "properties": { + "foo": { "type": "string" } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { "type": "string" } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/unevaluated-properties-with-dynamic-ref/derived", + + "$ref": "./baseSchema", + + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "properties": { + "bar": { "type": "string" } + } + }, + "baseSchema": { + "$id": "./baseSchema", + + "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "properties": { + "foo": { "type": "string" } + }, + "$dynamicRef": "#addons", + + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, { "description": "unevaluatedProperties can't see inside cousins", "schema": { @@ -769,7 +863,6 @@ "description": "nested unevaluatedProperties, outer false, inner true, properties outside", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -802,7 +895,6 @@ "description": "nested unevaluatedProperties, outer false, inner true, properties inside", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "properties": { @@ -835,7 +927,6 @@ "description": "nested unevaluatedProperties, outer true, inner false, properties outside", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { "type": "string" } }, @@ -868,7 +959,6 @@ "description": "nested unevaluatedProperties, outer true, inner false, properties inside", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "properties": { @@ -901,7 +991,6 @@ "description": "cousin unevaluatedProperties, true and false, true with properties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "properties": { @@ -936,7 +1025,6 @@ "description": "cousin unevaluatedProperties, true and false, false with properties", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "unevaluatedProperties": true @@ -972,10 +1060,8 @@ "comment": "see https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "foo": { - "type": "object", "properties": { "bar": { "type": "string" @@ -1024,7 +1110,6 @@ "description": "in-place applicator siblings, allOf has unevaluated", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "properties": { @@ -1070,7 +1155,6 @@ "description": "in-place applicator siblings, anyOf has unevaluated", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "allOf": [ { "properties": { @@ -1116,7 +1200,6 @@ "description": "unevaluatedProperties + single cyclic ref", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", "properties": { "x": { "$ref": "#" } }, @@ -1471,5 +1554,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft3/additionalItems.json b/tests/draft3/additionalItems.json index 0cb668701..ab44a2eb3 100644 --- a/tests/draft3/additionalItems.json +++ b/tests/draft3/additionalItems.json @@ -110,6 +110,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft3/maxLength.json b/tests/draft3/maxLength.json index 4de42bcab..b0a9ea5be 100644 --- a/tests/draft3/maxLength.json +++ b/tests/draft3/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft3/minLength.json b/tests/draft3/minLength.json index 3f09158de..6652c7509 100644 --- a/tests/draft3/minLength.json +++ b/tests/draft3/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft3/optional/ecmascript-regex.json b/tests/draft3/optional/format/ecmascript-regex.json similarity index 100% rename from tests/draft3/optional/ecmascript-regex.json rename to tests/draft3/optional/format/ecmascript-regex.json diff --git a/tests/draft3/optional/format/host-name.json b/tests/draft3/optional/format/host-name.json index d418f3763..9a75c3c20 100644 --- a/tests/draft3/optional/format/host-name.json +++ b/tests/draft3/optional/format/host-name.json @@ -57,6 +57,11 @@ "description": "exceeds maximum label length", "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", "valid": false + }, + { + "description": "empty string", + "data": "", + "valid": false } ] } diff --git a/tests/draft3/refRemote.json b/tests/draft3/refRemote.json index de0cb43a5..81a6c5116 100644 --- a/tests/draft3/refRemote.json +++ b/tests/draft3/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "schema": {"$ref": "http://localhost:1234/draft3/subSchemas.json#/definitions/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + "$ref": "http://localhost:1234/draft3/subSchemas.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft4/additionalItems.json b/tests/draft4/additionalItems.json index deb44fd31..c9e681549 100644 --- a/tests/draft4/additionalItems.json +++ b/tests/draft4/additionalItems.json @@ -146,6 +146,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft4/enum.json b/tests/draft4/enum.json index f085097be..ce43acc02 100644 --- a/tests/draft4/enum.json +++ b/tests/draft4/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft4/maxLength.json b/tests/draft4/maxLength.json index 811d35b25..338795943 100644 --- a/tests/draft4/maxLength.json +++ b/tests/draft4/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft4/minLength.json b/tests/draft4/minLength.json index 3f09158de..6652c7509 100644 --- a/tests/draft4/minLength.json +++ b/tests/draft4/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft4/not.json b/tests/draft4/not.json index cbb7f46bf..525219cf2 100644 --- a/tests/draft4/not.json +++ b/tests/draft4/not.json @@ -91,6 +91,67 @@ "valid": true } ] + }, + { + "description": "forbid everything with empty schema", + "schema": { "not": {} }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "double negation", + "schema": { "not": { "not": {} } }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] } - ] diff --git a/tests/draft4/oneOf.json b/tests/draft4/oneOf.json index fb63b0898..2487f0e38 100644 --- a/tests/draft4/oneOf.json +++ b/tests/draft4/oneOf.json @@ -159,7 +159,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft4/optional/format/hostname.json b/tests/draft4/optional/format/hostname.json index a8ecd194f..866a61788 100644 --- a/tests/draft4/optional/format/hostname.json +++ b/tests/draft4/optional/format/hostname.json @@ -112,6 +112,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft4/optional/format/ipv4.json b/tests/draft4/optional/format/ipv4.json index 4706581f2..9680fe620 100644 --- a/tests/draft4/optional/format/ipv4.json +++ b/tests/draft4/optional/format/ipv4.json @@ -78,6 +78,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft4/id.json b/tests/draft4/optional/id.json similarity index 100% rename from tests/draft4/id.json rename to tests/draft4/optional/id.json diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 412c9ff83..65e45190c 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "schema": {"$ref": "http://localhost:1234/draft4/subSchemas.json#/definitions/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + "$ref": "http://localhost:1234/draft4/subSchemas.json#/definitions/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "name.json#/definitions/orNull"} + "name": {"$ref": "draft4/name.json#/definitions/orNull"} } }, "tests": [ @@ -171,7 +171,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifierDraft4.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/draft4/locationIndependentIdentifier.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft6/additionalItems.json b/tests/draft6/additionalItems.json index cae72361c..2c7d15582 100644 --- a/tests/draft6/additionalItems.json +++ b/tests/draft6/additionalItems.json @@ -169,6 +169,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft6/enum.json b/tests/draft6/enum.json index f085097be..ce43acc02 100644 --- a/tests/draft6/enum.json +++ b/tests/draft6/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft6/maxLength.json b/tests/draft6/maxLength.json index 748b4daaf..be60c5407 100644 --- a/tests/draft6/maxLength.json +++ b/tests/draft6/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft6/minLength.json b/tests/draft6/minLength.json index 64db94805..23c68fe3f 100644 --- a/tests/draft6/minLength.json +++ b/tests/draft6/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft6/not.json b/tests/draft6/not.json index 98de0eda8..b46c4ed05 100644 --- a/tests/draft6/not.json +++ b/tests/draft6/not.json @@ -93,19 +93,161 @@ ] }, { - "description": "not with boolean schema true", - "schema": {"not": true}, + "description": "forbid everything with empty schema", + "schema": { "not": {} }, "tests": [ { - "description": "any value is invalid", + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", "data": "foo", "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { "not": true }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true } ] }, { - "description": "not with boolean schema false", - "schema": {"not": false}, + "description": "double negation", + "schema": { "not": { "not": {} } }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft6/oneOf.json b/tests/draft6/oneOf.json index eeb7ae866..c30a65c0d 100644 --- a/tests/draft6/oneOf.json +++ b/tests/draft6/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft6/optional/format/hostname.json b/tests/draft6/optional/format/hostname.json index a8ecd194f..866a61788 100644 --- a/tests/draft6/optional/format/hostname.json +++ b/tests/draft6/optional/format/hostname.json @@ -112,6 +112,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft6/optional/format/ipv4.json b/tests/draft6/optional/format/ipv4.json index 4706581f2..9680fe620 100644 --- a/tests/draft6/optional/format/ipv4.json +++ b/tests/draft6/optional/format/ipv4.json @@ -78,6 +78,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft6/id.json b/tests/draft6/optional/id.json similarity index 100% rename from tests/draft6/id.json rename to tests/draft6/optional/id.json diff --git a/tests/draft6/unknownKeyword.json b/tests/draft6/optional/unknownKeyword.json similarity index 100% rename from tests/draft6/unknownKeyword.json rename to tests/draft6/optional/unknownKeyword.json diff --git a/tests/draft6/propertyNames.json b/tests/draft6/propertyNames.json index f0788e649..7c7b80006 100644 --- a/tests/draft6/propertyNames.json +++ b/tests/draft6/propertyNames.json @@ -103,5 +103,52 @@ "valid": true } ] + }, + { + "description": "propertyNames with const", + "schema": {"propertyNames": {"const": "foo"}}, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with enum", + "schema": {"propertyNames": {"enum": ["foo", "bar"]}}, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property foo and bar is valid", + "data": {"foo": 1, "bar": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"baz": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 5d60fae11..49ead6d1f 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "schema": {"$ref": "http://localhost:1234/draft6/subSchemas.json#/definitions/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + "$ref": "http://localhost:1234/draft6/subSchemas.json#/definitions/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "$id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "name.json#/definitions/orNull"} + "name": {"$ref": "draft6/name.json#/definitions/orNull"} } }, "tests": [ @@ -173,7 +173,7 @@ "schema": { "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", "allOf": [ - { "$ref": "ref-and-definitions.json" } + { "$ref": "draft6/ref-and-definitions.json" } ] }, "tests": [ @@ -196,7 +196,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/draft6/locationIndependentIdentifier.json#/definitions/refToInteger" }, "tests": [ { diff --git a/tests/draft7/additionalItems.json b/tests/draft7/additionalItems.json index cae72361c..2c7d15582 100644 --- a/tests/draft7/additionalItems.json +++ b/tests/draft7/additionalItems.json @@ -169,6 +169,25 @@ } ] }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [{}], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ "foo", "bar", 37 ], + "valid": false + }, + { + "description": "valid instance", + "data": [ null ], + "valid": true + } + ] + }, { "description": "additionalItems with null instance elements", "schema": { diff --git a/tests/draft7/enum.json b/tests/draft7/enum.json index f085097be..ce43acc02 100644 --- a/tests/draft7/enum.json +++ b/tests/draft7/enum.json @@ -154,6 +154,27 @@ } ] }, + { + "description": "enum with [false] does not match [0]", + "schema": {"enum": [[false]]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, @@ -175,6 +196,27 @@ } ] }, + { + "description": "enum with [true] does not match [1]", + "schema": {"enum": [[true]]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, @@ -196,6 +238,27 @@ } ] }, + { + "description": "enum with [0] does not match [false]", + "schema": {"enum": [[0]]}, + "tests": [ + { + "description": "[false] is invalid", + "data": [false], + "valid": false + }, + { + "description": "[0] is valid", + "data": [0], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [0.0], + "valid": true + } + ] + }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, @@ -217,6 +280,27 @@ } ] }, + { + "description": "enum with [1] does not match [true]", + "schema": {"enum": [[1]]}, + "tests": [ + { + "description": "[true] is invalid", + "data": [true], + "valid": false + }, + { + "description": "[1] is valid", + "data": [1], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [1.0], + "valid": true + } + ] + }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, diff --git a/tests/draft7/maxLength.json b/tests/draft7/maxLength.json index 748b4daaf..be60c5407 100644 --- a/tests/draft7/maxLength.json +++ b/tests/draft7/maxLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "two supplementary Unicode code points is long enough", + "description": "two graphemes is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } diff --git a/tests/draft7/minLength.json b/tests/draft7/minLength.json index 64db94805..23c68fe3f 100644 --- a/tests/draft7/minLength.json +++ b/tests/draft7/minLength.json @@ -24,7 +24,7 @@ "valid": true }, { - "description": "one supplementary Unicode code point is not long enough", + "description": "one grapheme is not long enough", "data": "\uD83D\uDCA9", "valid": false } diff --git a/tests/draft7/not.json b/tests/draft7/not.json index 98de0eda8..b46c4ed05 100644 --- a/tests/draft7/not.json +++ b/tests/draft7/not.json @@ -93,19 +93,161 @@ ] }, { - "description": "not with boolean schema true", - "schema": {"not": true}, + "description": "forbid everything with empty schema", + "schema": { "not": {} }, "tests": [ { - "description": "any value is invalid", + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", "data": "foo", "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { "not": true }, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + }, + { + "description": "object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { "not": false }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true } ] }, { - "description": "not with boolean schema false", - "schema": {"not": false}, + "description": "double negation", + "schema": { "not": { "not": {} } }, "tests": [ { "description": "any value is valid", diff --git a/tests/draft7/oneOf.json b/tests/draft7/oneOf.json index eeb7ae866..c30a65c0d 100644 --- a/tests/draft7/oneOf.json +++ b/tests/draft7/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft7/optional/format/hostname.json b/tests/draft7/optional/format/hostname.json index a8ecd194f..866a61788 100644 --- a/tests/draft7/optional/format/hostname.json +++ b/tests/draft7/optional/format/hostname.json @@ -112,6 +112,16 @@ "description": "single label ending with digit", "data": "hostnam3", "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "single dot", + "data": ".", + "valid": false } ] } diff --git a/tests/draft7/optional/format/idn-hostname.json b/tests/draft7/optional/format/idn-hostname.json index 6c8f86a3a..5c8cdc77b 100644 --- a/tests/draft7/optional/format/idn-hostname.json +++ b/tests/draft7/optional/format/idn-hostname.json @@ -254,7 +254,7 @@ { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", - "data": "\u0660\u06f0", + "data": "\u0628\u0660\u06f0", "valid": false }, { @@ -298,6 +298,80 @@ "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true + }, + { + "description": "single label", + "data": "hostname", + "valid": true + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true + }, + { + "description": "empty string", + "data": "", + "valid": false + } + ] + }, + { + "description": "validation of separators in internationalized host names", + "specification": [ + {"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"} + ], + "schema": { "format": "idn-hostname" }, + "tests": [ + { + "description": "single dot", + "data": ".", + "valid": false + }, + { + "description": "single ideographic full stop", + "data": "\u3002", + "valid": false + }, + { + "description": "single fullwidth full stop", + "data": "\uff0e", + "valid": false + }, + { + "description": "single halfwidth ideographic full stop", + "data": "\uff61", + "valid": false + }, + { + "description": "dot as label separator", + "data": "a.b", + "valid": true + }, + { + "description": "ideographic full stop as label separator", + "data": "a\u3002b", + "valid": true + }, + { + "description": "fullwidth full stop as label separator", + "data": "a\uff0eb", + "valid": true + }, + { + "description": "halfwidth ideographic full stop as label separator", + "data": "a\uff61b", + "valid": true } ] } diff --git a/tests/draft7/optional/format/ipv4.json b/tests/draft7/optional/format/ipv4.json index 4706581f2..9680fe620 100644 --- a/tests/draft7/optional/format/ipv4.json +++ b/tests/draft7/optional/format/ipv4.json @@ -78,6 +78,11 @@ "description": "invalid non-ASCII '২' (a Bengali 2)", "data": "1২7.0.0.1", "valid": false + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false } ] } diff --git a/tests/draft7/id.json b/tests/draft7/optional/id.json similarity index 100% rename from tests/draft7/id.json rename to tests/draft7/optional/id.json diff --git a/tests/draft7/unknownKeyword.json b/tests/draft7/optional/unknownKeyword.json similarity index 100% rename from tests/draft7/unknownKeyword.json rename to tests/draft7/optional/unknownKeyword.json diff --git a/tests/draft7/propertyNames.json b/tests/draft7/propertyNames.json index f0788e649..7c7b80006 100644 --- a/tests/draft7/propertyNames.json +++ b/tests/draft7/propertyNames.json @@ -103,5 +103,52 @@ "valid": true } ] + }, + { + "description": "propertyNames with const", + "schema": {"propertyNames": {"const": "foo"}}, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with enum", + "schema": {"propertyNames": {"enum": ["foo", "bar"]}}, + "tests": [ + { + "description": "object with property foo is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property foo and bar is valid", + "data": {"foo": 1, "bar": 1}, + "valid": true + }, + { + "description": "object with any other property is invalid", + "data": {"baz": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index 115e12e74..450787af6 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -17,7 +17,7 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "schema": {"$ref": "http://localhost:1234/draft7/subSchemas.json#/definitions/integer"}, "tests": [ { "description": "remote fragment valid", @@ -34,7 +34,7 @@ { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + "$ref": "http://localhost:1234/draft7/subSchemas.json#/definitions/refToInteger" }, "tests": [ { @@ -139,7 +139,7 @@ "$id": "http://localhost:1234/object", "type": "object", "properties": { - "name": {"$ref": "name.json#/definitions/orNull"} + "name": {"$ref": "draft7/name.json#/definitions/orNull"} } }, "tests": [ @@ -173,7 +173,7 @@ "schema": { "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", "allOf": [ - { "$ref": "ref-and-definitions.json" } + { "$ref": "draft7/ref-and-definitions.json" } ] }, "tests": [ @@ -196,7 +196,7 @@ { "description": "Location-independent identifier in remote ref", "schema": { - "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + "$ref": "http://localhost:1234/draft7/locationIndependentIdentifier.json#/definitions/refToInteger" }, "tests": [ { From 36623dd80683aa4b4d2a70337410595191203a35 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Mon, 26 May 2025 11:33:17 +0200 Subject: [PATCH 9/9] Revert "Adapt test case generation from suite" This reverts commit e3bc2dcda731844a21b4b20633386f65efd9c3f3. --- jsonschema/tests/test_jsonschema_test_suite.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 9ff067f33..41c982553 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -136,6 +136,7 @@ def leap_second(test): DRAFT4.format_cases(), DRAFT4.optional_cases_of(name="bignum"), DRAFT4.optional_cases_of(name="float-overflow"), + DRAFT4.optional_cases_of(name="id"), DRAFT4.optional_cases_of(name="non-bmp-regex"), DRAFT4.optional_cases_of(name="zeroTerminatedFloats"), Validator=jsonschema.Draft4Validator, @@ -154,6 +155,7 @@ def leap_second(test): DRAFT6.format_cases(), DRAFT6.optional_cases_of(name="bignum"), DRAFT6.optional_cases_of(name="float-overflow"), + DRAFT6.optional_cases_of(name="id"), DRAFT6.optional_cases_of(name="non-bmp-regex"), Validator=jsonschema.Draft6Validator, format_checker=jsonschema.Draft6Validator.FORMAT_CHECKER, @@ -172,7 +174,9 @@ def leap_second(test): DRAFT7.optional_cases_of(name="bignum"), DRAFT7.optional_cases_of(name="cross-draft"), DRAFT7.optional_cases_of(name="float-overflow"), + DRAFT6.optional_cases_of(name="id"), DRAFT7.optional_cases_of(name="non-bmp-regex"), + DRAFT7.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft7Validator, format_checker=jsonschema.Draft7Validator.FORMAT_CHECKER, skip=lambda test: ( @@ -186,12 +190,15 @@ def leap_second(test): TestDraft201909 = DRAFT201909.to_unittest_testcase( DRAFT201909.cases(), + DRAFT201909.optional_cases_of(name="anchor"), DRAFT201909.optional_cases_of(name="bignum"), DRAFT201909.optional_cases_of(name="cross-draft"), DRAFT201909.optional_cases_of(name="float-overflow"), + DRAFT201909.optional_cases_of(name="id"), DRAFT201909.optional_cases_of(name="no-schema"), DRAFT201909.optional_cases_of(name="non-bmp-regex"), DRAFT201909.optional_cases_of(name="refOfUnknownKeyword"), + DRAFT201909.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft201909Validator, skip=skip( message="Vocabulary support is still in-progress.", @@ -220,12 +227,15 @@ def leap_second(test): TestDraft202012 = DRAFT202012.to_unittest_testcase( DRAFT202012.cases(), + DRAFT201909.optional_cases_of(name="anchor"), DRAFT202012.optional_cases_of(name="bignum"), DRAFT202012.optional_cases_of(name="cross-draft"), DRAFT202012.optional_cases_of(name="float-overflow"), + DRAFT202012.optional_cases_of(name="id"), DRAFT202012.optional_cases_of(name="no-schema"), DRAFT202012.optional_cases_of(name="non-bmp-regex"), DRAFT202012.optional_cases_of(name="refOfUnknownKeyword"), + DRAFT202012.optional_cases_of(name="unknownKeyword"), Validator=jsonschema.Draft202012Validator, skip=skip( message="Vocabulary support is still in-progress.",