From 93efc1a12164eb1c50995065c9e9317054f1e383 Mon Sep 17 00:00:00 2001 From: David Harsha Date: Sun, 21 May 2023 23:49:10 -0700 Subject: [PATCH] Squashed 'JSON-Schema-Test-Suite/' changes from 689d2f28..7950d9e0 7950d9e0 Merge pull request #674 from jmigual/feature/alah e6a089ae Changed description about `main` branch b3c07477 Add comment about live at head philosophy ab4bd012 Merge pull request #671 from marksparkza/schemaloc-fragment e7aba097 Include fragment in schemaLocation 6afa9b38 Merge pull request #664 from santhosh-tekuri/empty-tokens e4bceb1a Bump the python-jsonschema version used for the sanity check. 8025fc0d Merge pull request #128 from iainbeeston/foundations-of-json-schema-paper cf767707 Make all root $ids absolute URIs 07fd389a Added test cases from Foundations of JSON Schema research paper 1008edce ref: test empty tokens in json-pointer 9beb3cfb Merge pull request #627 from json-schema-org/ether/output-readme-fixes f2b0490b minor edit to trigger gh action c305ce54 Merge pull request #669 from hauner/typo 5e2845c1 Merge pull request #668 from hauner/if-without-then-else-creates-annotations 2f1df229 typo c1fae002 test unevaluated* can see annotations from if without then/else 987a4c8f Merge pull request #666 from json-schema-org/gregsdennis/file-refs 90b2a58c fix *nix uris 68d18c6a rename tests to fix sanity check e9166bcb fix indentation 1d1ec749 add file-id ref tests fb60ed17 Merge pull request #663 from json-schema-org/ether/restore-format-tests f32cd8b8 Revert "Revert "by default, "format" only annotates, not validates"" 47958f82 Merge pull request #654 from santhosh-tekuri/output-escape 5262997e Merge pull request #661 from santhosh-tekuri/2019-output ce2c1657 output-tests: correct 2019 output-schema.json 0788c226 Merge pull request #659 from jvtm/python311-date-iso8601-values 4248f3c7 test: cover ISO8601 date values accepted by Python 3.11 datetime module 19947eaa test: unevaluatedProperties not affected by propertyNames c9d94385 output: ensure ~ and / are escaped in json-pointer 82927063 Check that large integers are multiples of small multipleOf b59543f6 Merge pull request #647 from santhosh-tekuri/ref-start-slash 6e5d45d7 Merge pull request #646 from santhosh-tekuri/vocab-optional 0311dfda Merge pull request #651 from santhosh-tekuri/dynamicref-without-anchor 4503eeaf test: A $dynamicRef without anchor in fragment behaves identical to $ref 39af4c1b test: $ref with absolute-path-reference 880c9933 test/vocabulary: ignore unrecognized optional vocabulary fd80307f Merge pull request #642 from santhosh-tekuri/time-2digit a76ae650 Merge pull request #645 from json-schema-org/gregsdennis/add-vocab-tests-link 0e2b4eef Merge pull request #643 from 0xSudarshan/main 2b78ccfc slight tweaking to wording 8716c405 add link for vocab test suite to readme c49ba544 Fix an incorrect $schema identifier. f0e5ce71 Added test for schema-items alongside "ignored" additionalItems 76dae88a Merge pull request #640 from santhosh-tekuri/refRemote-anchor cb82e237 Merge pull request #641 from json-schema-org/gregsdennis/unevaluated-not-draft-next e4afd233 test/format: hour, min, sec must be two digits 7efd5131 fix unevaluatedProperties/not tests for draft-next e39c6ea6 test/refRemote: anchor within remote ref bf51b32f Merge pull request #639 from json-schema-org/additionalItems-unevaluatedItems 52160b36 Add a test for 2019's interaction between additional/unevaluatedItems 69a09a33 Fixed tests for annotation collection inside not. e4e1a220 Draft7 if/then/else ref tests need to be wrapped in an allOf. f5bd2f6c Merge pull request #632 from json-schema-org/ether/annotations-inside-not 626b433e test that annations are collected inside a "not" f57d3e0c Merge pull request #631 from json-schema-org/if-then-else-ref 3b8c281f Ensure $ids are collected within if/then/else schemas. 02905b21 Fix a sloppy bug in the sanity checks in CI. f6b2324b minor spelling and markdown formatting fixes; `valid` has also been removed from the tests d21ed578 Merge pull request #628 from json-schema-org/catch-unknown-keywords 42b4c364 Ensure we don't use unknown keywords unless intended. 6b3cac42 Merge pull request #624 from json-schema-org/gregsdennis/propertyDependencies-fixups ef6fb998 update unevaluatedProperties test to define foo with properties 19130148 add definition for expectedTypes 197cb33a fixed propertyDependencies $schema & $id; removed invalid test cases a390e321 Merge pull request #619 from json-schema-org/gregsdennis/output-tests b538fe75 Bump the validator version used for suite sanity checks. c2644010 Blacked. 8ee43236 add some more detail in readme; add redundant keyword to some tests c8835529 absoluteKeywordLocation is not required when there is no `$ref` 1a860cfb added $id to all output schemas; reindexed test cases to 0 (instead of 1) 930e87e7 add clarification on no changes between 2019 and 2020 f5197e08 Fix the output check to ignore output-schema.json. a8b28057 Minor style tweaks. 3413863a Inline the relevant parts of the test schema to output tests. dc6e8204 Merge remote-tracking branch 'origin/main' into gregsdennis/output-tests b1267590 Update bin/jsonschema_suite b40a6cac Update bin/jsonschema_suite 691d039c update $dynamic* value in schemas d263bf01 add blank lines at the end of all the files 78c88827 Merge pull request #618 from json-schema-org/gregsdennis/contentschema-should-fail-content 5cbc53bc Merge pull request #613 from santhosh-tekuri/rjp-multidigit bb000ce9 Merge pull request #620 from json-schema-org/ether/remove-unused-remotes c4c490f1 Merge pull request #617 from json-schema-org/gregsdennis/dynamicAnchor-inside-propertyDependencies 0189831a remove schemas that are never referenced cf1b9424 Merge pull request #610 from handrews/rm-remotes daf42a74 attempt to update ci for output tests d6490e81 move anchors into defs 2f9d117c Merge pull request #616 from json-schema-org/gregsdennis/propertyDependencies-and-unevaluated 4e5649cd move tests to draft-next 46bc7ace add readme note about output-schema.json files efeee1d4 update tests to reference output schemas 147df486 add output schemas fe25ba95 updated readme; fixed $schema typo; tests for 2020-12 87c184d2 add .editorconfig; rearrange folders e9f54002 initial run at creating output tests a41f2f6c added type:object to contentSchema schemas 2f50e786 add tests for $dynamicAnchor in multiple branches of propertyDependencies 4794a199 add tests for unevaluatedProperties seeing inside propertyDependencies 27cc299f Add RJP test 'multi-digit integer prefix' 716b95d9 Merge pull request #612 from santhosh-tekuri/rjp-positive 320c804d Add RJP test 'explicit positive prefix' c8f210c3 Merge pull request #611 from santhosh-tekuri/time-alpha 3faeb222 add time test 'contains letters' 642441f2 Merge pull request #603 from santhosh-tekuri/uuid-nonstr 94d5043c add non-string uri tests 0c81374a Remove unneeded remotes 97a3e215 Merge pull request #608 from json-schema-org/json-everything-uses-the-test-suite bdaf7e8b added json-everything to 'who uses' section of readme; removed manatee.json (deprecated) f00ec100 Merge pull request #606 from santhosh-tekuri/duration-nounit 13448072 Merge pull request #607 from santhosh-tekuri/time-offsetprefix dd4538ee Test time format 'offset not starting with plus or minus' 80fe2db1 test duration format 'element without unit' 38ea1511 Merge pull request #604 from santhosh-tekuri/time-offset 613ec170 second fraction, not offset ee4bd4eb Add time format test with second fraction, no offset 86c2517c Merge pull request #605 from santhosh-tekuri/rjp-empty cfe80006 Add relative-json-pointer test with empty string 31796b3b add non-string uuid tests 9251ebff Merge pull request #602 from santhosh-tekuri/format-assertion 69a36154 Fix vocabulary metaschema uris in format-assertion-*.json 0fa89d2a Merge pull request #595 from json-schema-org/ether/cousins-reverse 2b1f711d Merge pull request #598 from flaksp/patch-1 104f9f98 Merge pull request #599 from tristanpenman/main 209ba640 Add Valijson to 'Who Uses the Test Suite' 47bf107c Fix typo in comment of "order of evaluation: $id and $anchor and $ref" suite dee0edad Merge pull request #597 from json-schema-org/contributing f54f00a2 Explicitly mention that one approval doesn't override other concerns. e17668ec Add additional notes about writing good tests. a6520db4 Add in a contributors document outlining the repo's process. julian@Airm 6ce9bc4c Merge pull request #596 from json-schema-org/steering 8defd758 Add a note about the future TSC. b9bb50bc also test allOf schemas presented in the reverse order ed0b855e Merge pull request #594 from json-schema-org/differing-uris ae065139 Merge pull request #593 from json-schema-org/gregsdennis-propertyDependencies-tests 6eaf7dff Merge pull request #586 from handrews/dollar-schema 0ba0976d more varied test cases b78035ee Merge branch 'gregsdennis-propertyDependencies-tests' of github.com:json-schema-org/JSON-Schema-Test-Suite into gregsdennis-propertyDependencies-tests 8c2b46f7 rework functional tests to better illustrate purpose of keyword 33d9c648 Update tests/draft-next/propertyDependencies.json de3f7691 Add tests for some more differing URI scenarios. e5951050 additional 'ignore' tests with nested matches fc6cee5a propertyDependencies non-string property value tests 99f3b60c add basic propertyDependencies tests b5270c56 Update all draft-next $schema, $id, $ref. dd343685 Copy remotes to draft-next without changes. 8919ce99 Add $schema to optional/format 2019-09 tests d88c04ff Add $schema for optional/format 2020-12 da237da5 draft-specific 2020-12 remotes, $refs, and $ids 0eb6893f draft-specific 2019-09 remotes, $refs, and $ids 4cfead7b Fix #585 on Windows. 14d05dce Merge pull request #585 from json-schema-org/absolute-uri b3c8672a Merge pull request #587 from json-schema-org/cross-draft-tests b643e11f Tweak the remotes retrieval README language a bit more. e2a681ac $comment -> comment c0ba85b6 Remove accidental duplication 52eb2790 add draft 2020-12 -> draft 2019-09 test c4ed16df add draft 2019-09 -> draft 7 test 3df4712a add draft 2019-09 -> draft 2020-12 test dab94fac add draft 7 -> draft 2019-09 test e8851f1a Add "$schema" to all document roots 8d653be4 Copy remotes to draft dirs, no changes yet 113a08e5 Optional tests for no $schema (2019-09+) 90983590 Update README to reflect $schema detection be49e5b0 Add $schema to all 2019-09 tests 64793fe6 Add $schema for all 2020-12 tests. 0c90a5f9 Explicitly mention the base URI for those not using jsonschema_remotes. 79daf05b Emit fully absolute URIs from `jsonschema_suite remotes`. dfcea626 Merge pull request #584 from json-schema-org/doi e4a59d96 Add a badge for a Zenodo DOI. 597b1fb0 Ensure JS implementations don't traverse the prototype chain. 0015d524 Merge pull request #583 from santhosh-tekuri/defs e14c68bb Replace '$defs' with 'definitions' in drafts 6,7 c4341bd0 Merge pull request #582 from santhosh-tekuri/defs 4ae2c9b9 Replace '$defs' with 'definitions' in draft 6,7 91ecacf6 Forward port a missing null instance property test. fe3eda22 Apply #579 to case descriptions as well. f8276408 Merge pull request #579 from json-schema-org/sanity-check-strengthening 2782d7c2 Fix two last clashing $ids in draft-next too. e5d5e0a2 Also prevent 'tests that' from descriptions. eaf06b1e Remove the last few 'shoulds' from items descriptions. b7da24fb Kill more shoulds from ECMA and ref tests. 85899fdf More description cleanup for Bengali non-ASCII tests. b84b900f Remove 'should' from a format test which anyhow needed a clearer description. 721397c1 Prevent tests from using 'should' in sanity check. 68f380c6 Fix the last non-unique case descriptions. 6383ef63 Remove mistakenly duplicated anyOf tests in draft{4,6,7}. a5b459fa Make sure bignum cases have unique descriptions. b82b18cd Assert case descriptions are also unique in sanity checks. d3d08221 Also check case description length in sanity checks. 5e7804c5 Use subtests when running sanity checks. 8ade9234 Fix two last clashing $ids in draft-next too. 685ac631 Merge pull request #578 from json-schema-org/urn 5347f29e Deduplicate URIs in the URN tests. 87cf3257 Also add tests for refs with URN+pointer and URN+fragment. 96255eff Add some simple tests for URN base URIs. fd9bcfbd Merge pull request #421 from willson-chen/bug601_addtestcase 13685a6c Forward port the nested ref test. 5be19e21 Give the nested ref schema a clearer name, and fix refs to it. e9db2e58 subschema nested ref in remote ref 69acf529 Merge pull request #572 from json-schema-org/default-reviewers 26a51ca3 Merge pull request #575 from jdesrosiers/add-package-json d0e80a96 Re-add package.json 88d69482 Merge pull request #573 from json-schema-org/handling-nulls-in-instances bd653f34 fixed findings by julian eab34ba6 fix `prefixItems` tests to actually use it (instead of `items`, copy-paste error) 6680a003 fixed typo in `type` declaration: surround with quotes 257f5220 added null-handling tests for unevaluatedItems e3c007dd added null-handling tests for unevaluatedProperties 3d3bdf4e added null-handling tests for properties 54cc5703 added null-handling tests for patternProperties 28419842 added null-handling tests for contains 4d1a916a added null-handling tests for additionalItems 6e47a99a added null-handling tests for prefixItems; fixed indentation on previous commit 761d4b2b added null-handling tests for array-form items 6315a51d added null-handling tests for single-form items 278e5b3b added null-handling tests for additionalProperties bce6b82a Set up default reviewers (the whole test suite team). 9cb7da92 Merge pull request #564 from json-schema-org/sanity-check-terminology 2a316683 Merge pull request #569 from spacether/feat_adds_new_python_consumer fae0017d Removes idea files 8af12a3f Adds python-experimental to the users list b7d13f4b Merge pull request #567 from json-schema-org/invalid-anchors 4811789d Also add an anchor test with valid prefix (but still invalid). b62f97cc Add tests for invalid anchors. af5075ca Merge pull request #568 from json-schema-org/ether/perl-implementations dc5c91e9 update the list of Perl implementations 1047a1aa Merge pull request #565 from json-schema-org/update-test-schema 7967a87b Merge pull request #566 from json-schema-org/tidy-unevaluatedItems b45a7878 Remove unnecessary type validation from unevaluatedItems tests. 2b536c02 Update the test schema to Draft 2020, and fix a bug in it. 39d1d24d Merge pull request #317 from Relequestual/#291 b683de5a Forward-port and reword the new unevaluatedItems test. 816441f4 Add tests for Single-schema items and unevaluatedItems Resolves #291 c7a0f3e9 Reconcile terminology in the sanity checker with the README 1e0ebd20 Merge pull request #563 from json-schema-org/update-sanity-checker e1dbaebb Merge pull request #562 from json-schema-org/remove-conditional-id-tests-from-draft6 53da77f3 Update the sanity checker to use a version which supports 2019+. 5aff83e5 reintroduce tests without using if/then/else 9495e3e4 remove conditional $id tests from draft 6 d3f5cd43 Merge pull request #559 from json-schema-org/ether/revert-pr-376 f0f619d1 Merge pull request #560 from json-schema-org/ether/fix-383 fa791ada remove tests that are not valid for draft7 0f341dca Merge pull request #429 from notEthan/decimal_minItems 32ec6305 test validation of keywords which expect integers when their value has a decimal f605fbfe Revert PR#376. 547330dd Tweak the markdown table syntax in the README. 28ed3022 Restructure the README further. 45d6e5e7 README: Add new content and update the structure 4de0966a Merge pull request #558 from yakimun/replace-definitions-with-defs aad0f350 Replace definitions with for 2019 and later drafts 0b777ffa Merge branch 'ether/more-anchor-and-id-tests' d593591d Forward port the just-added tests to 2020 and next. e157bc0b squash: use a unique $id to prevent namespace collisions across tests 1d5583de some tests of the interactions between $id, $anchor and $ref 07c45c0d Restore the dependencies tests as optional for 2019, 2020, and next cf78d97d Handle differences in $ref for the location-independent ref remote. c2b28e96 Forward port the just-added test to 2020 and draft-next. 64090104 Apply suggestion f37aa47a Add tests for location-independent identifiers in remote ref 84177bde Merge pull request #556 from jviotti/gitignore-python 76f5a107 Merge pull request #555 from jviotti/delete-broken-js-tests 8b0ea0e7 Add a Python-based .gitignore definition 47e6e32a Remove the broken and obsolete JavaScript-based test integration d40b3e62 Fix two remaining future-keywords tests in draft 4. c23c720a Merge branch 'ether/unrecognized-keywords' ea68a4ff Move the future keywords tests to optional. 900695b7 squash: add $schema keyword to be clear that strict conformance is requested acfd00c6 squash: contains does not exist in draft4 f506651a squash: fix minContains b666c202 sq - add $dynamic*, prefixItems to drafts 4,6,7 as well and fix keyword name d14242e6 squash: fix test names f1efe00d squash: $defs - definitions c295358e squash: remove tests of $anchor and $ref 9defa772 squash: add prefixItems: another new 2020-0X keyword ebb359df squash: add $recursiveRef tests from #391 90bd7fb2 squash - fix 2019-09 future-keywords e8e64efa very basic test of $dynamicRef 6c027209 rename files to future-keywords.json cb064e96 some tests for keywords added in later drafts e42e8417 \a is not a valid ECMA 262 regex. 387d690a Back/forward port the tests from #550 to 2019 and next. 528fb622 Merge pull request #550 from EpicWink/unevaluated-on-invalid b1fb4559 Mark tests as expected-to-pass db3fdd3f Merge pull request #551 from EpicWink/bin-cli-command-required 4d4c636f Require command in test-app invocation args 72463d44 Add tests for 'unevaluatedX' on invalid types 060caae0 Merge pull request #467 from gene-hightower/strict-rfc-grammar 995932c7 Additional RFC-5321 Mailbox tests 637f0ac3 Merge pull request #542 from jdesrosiers/dyanmicref-no-bookending 87944e52 Merge pull request #543 from jdesrosiers/update-vocabulary-for-draft-next 07b90e3b Merge pull request #544 from frawa/list-typed-json 365349ad list typed-json in new Scala section 9d1efc27 Update vocabulary tests for draft-next 89f59caa Update dynamicRef tests for bookenending removal 3731ed32 Merge pull request #541 from json-schema-org/unknown-formats 2f2234da unknown format requirement is in draft 4 also e12088db added tests for unknown formats 3998c852 Remove dead code from the sanity checker. b038102d Add some docstrings for the sanity checker. 20fb14bd Merge pull request #537 from jimmylewis/removeInvalidTest d07162bc Remove invalid draft6 test using draft7 constructs 26f74bef Add org badges 6e87b5bd Merge pull request #529 from yakimun/remove-non-canonical-uris c5ba7b28 Replace non-canonical URIs with canonical ones 8d96d15f Merge pull request #527 from johnnoone/patch-2 b7f657f7 Update vocabulary.json e82bfdfa s/future/next/ in schema reference 9263b525 Merge pull request #525 from DrGFreeman/524-uniqueItems-tests 2c536888 Add tests instead of modifying existing tests de84a59c Add and modify uniqueItems tests 329efe59 Update the language around coverage, draft2020-12 is just as usable :) 06813127 Ensure dependentSchemas also properly ignores non-object instances. ba3a9053 Merge pull request #523 from olegshtch/extendible-schema-test-suite 458e7ac1 Add test suite to test dynamic reference and anchor link and their independency of order fe405a11 draft/future -> draft/next in $refs also 3d9d35a2 Merge pull request #522 from json-schema-org/ether/draft-next 11b5076f rename draft-future to draft-next 0245dcc9 Merge pull request #521 from olegshtch/add-recursive-ref-test-suite e9fb9cf4 Merge pull request #517 from ChALkeR/chalker/date-time-leap f1b230c6 Add test from Appendix C. Example of recursive schema extension of the draft. bb2e3731 Test date-time with leap second on a wrong hour/minute 8b797cfe Merge pull request #520 from json-schema-org/ether/custom-dialect 5d23f311 Add tests for invalid date-time past leap second 63f8e93c Improve leap seconds test in optional/format/date-time 3d00f593 test the use of the $vocabulary keyword in a custom metaschema 54440eab Merge pull request #516 from ChALkeR/chalker/ipv6 e7b22e1c Fix the sanity check by pinning. 8891d810 Merge pull request #519 from json-schema-org/ether/custom-dialect 5f5fccda test the format-assertion vocabulary with a custom metaschema 3fcee386 Merge pull request #512 from json-schema-org/ether/formats-and-non-strings b349b879 test that format-assertions are valid with non-string types 8e5b2f10 fix needless inconsistencies in format tests between drafts 02d7cb59 Correct "ref with sibling id" tests 1649470b More ipv6 tests to increase coverage 7334b4c7 Merge pull request #505 from ChALkeR/chalker/fix-unicode 0fb2d278 Consolidate optional/unicode into optional/ecmascript-regex 4f8c6d7b unevaluatedProperties: deep dynamic + refs 9103f3b6 $ref wit id does not test what it is indented to do f300dd15 Add test "same $anchor with different base uri" d128f9d7 Add test to check that $id resolved against nearest parent, not just immediate parent 72e31dd2 Merge pull request #515 from json-schema-org/ether/fix-mandatory-format-tests 0173a083 Revert "by default, "format" only annotates, not validates" 66e813a9 Merge pull request #506 from json-schema-org/ether/formats-non-ascii 20c1bb1d test for non-ascii digits in various formats ab0b1ae7 fix draft4 schemas 0df96bc3 group tests to avoid duplicating test descriptions 93293efc fix indentation 9430972b fix unicode tests in accordance to pattern/patternProperties spec 76b529ff Merge pull request #482 from json-schema-org/ether/more-date-time-tests eb619047 Merge pull request #504 from json-schema-org/minContains-0-but-maxContains c41a68e8 Add tests for minContains = 0 but with maxContains 57f1d63d some more tests for "date" and "time" formats 878b0ad5 properly escape this newline character - thanks Srikrishnan Suresh! bb2a20d3 Merge pull request #503 from json-schema-org/uuid-dashes f9acc454 Backport #451 to draft 7. 8e746b3a Test that UUIDs have dashes in the right spots. fd0aa9f8 Merge pull request #500 from anexia-it/master d0107804 Extend if/then/else tests on unevaluated properties 017d4e56 Merge pull request #499 from json-schema-org/ether/dynamic-scope-enter-leave 6327a3bc Remove annotation-asserting tests from draft3's format as well. aa621ed4 test that dynamic scopes are not always in scope 35bab687 Merge pull request #497 from json-schema-org/ether/streamlined-format-tests 808c5d24 in #496 I neglected to update draft-future with the same $id fixes as in draft2020-12. ba1f1a77 normalize all format tests, adding consistent sample data b00ba577 fix use of boolean schemas in draft4 4ca4af27 Merge pull request #498 from json-schema-org/ether/2020-12-unicode-pattern c5f08e24 add tests for pattern matching with unicode semantics e7f8b3e8 Merge pull request #496 from json-schema-org/ether/missing-identifiers c8d79ee7 use unique identifiers so schemas do not conflict 17fa9589 Merge pull request #494 from anexia-it/master a0d28fdf Extend duration and uuid format tests for ignored values b6769f2b fix ids in older drafts 1326f36e Merge pull request #493 from json-schema-org/ether/id-sibling-to-ref b9bddc9c test that sibling $ids to $refs are ignored 2f6a498d Merge pull request #492 from json-schema-org/ether/fix-refRemote 61d03c0e fix buggy test with $ref in older drafts 0aefbb3d Merge pull request #491 from jdesrosiers/object-contains-tests 336ef8d2 Merge pull request #452 from LeifRilbe/rilbe/propertyNames-with-pattern 2dfbc79c Simplify the test case names as well. b6d0649d Add tests for contains with objects da687ca5 Enforce a consistent code style for contains tests b163efcf Merge pull request #490 from jdesrosiers/draft-future 7c8cb488 Initialize draft-future with 2020-12 tests 4d65d2df Merge pull request #483 from kylef/kylef/date ee9dcaa7 Merge pull request #485 from marksparkza/contains-with-false-if eaa5bffc Merge pull request #489 from json-schema-org/ether/more-recursiveRef 7c33b533 dynamic $recursiveRef test with cousin $recursiveAnchors 8a3a542b Fix invalid JSON error 8a89f58e Add tests combining remote refs and defs 3aec0d14 Add tests combining relative refs and defs a107d196 fix: $defs -> definitions in draft 6,7 tests 0c223de2 Remove a test for undefined $id behavior 4efec180 Test that "contains" does not fail due to false "if" subschema bf383b4c fix: make identifiers unique across tests 812f1f08 Merge pull request #484 from json-schema-org/ether/schemas-under-unknown-keywords 64f6b850 Test that identifiers are not found inside unrecognized keywords c69a89c6 Stricter date format constraints 09fd353f Merge pull request #481 from kylef/kylef/time 0ed2e79b Fix negative time test to only fail on a single rule 2edc74b1 Add valid time with different second fractions 7bde0bf7 Add valid time with leap second including offset ee83f464 Stricter time format constraints 5732904a Merge pull request #480 from json-schema-org/ether/better-test-names c2994271 better test names for schema-items + additionalItems 6bc53e60 Merge pull request #479 from json-schema-org/fix-non-id-in-enum-for-drafts-6-and-7 3f783d9c fixing draft 6 & 7 non-id tests 5768c68d Merge pull request #476 from json-schema-org/ether/readme-updates 0c8bfc06 add mention of JSON::Schema::Tiny e4c10c6b fix markdown for underscores in package names eeb4db18 mention draft2020-12 in readme dff69dcb Merge pull request #474 from marksparkza/unevaluatedItems-depends-on-contains 51b4977c Merge pull request #478 from sorinsarca/patch-1 dfcd4a19 fix bad comma 4cb100a5 Merge pull request #465 from json-schema-org/ether/more-naive-ref 31dc86bc add another test of naive $ref replacement f858c613 Merge pull request #477 from json-schema-org/ether/more-items-tests 4e266c34 test that array-items/prefixItems adjusts the starting position for schema-items/additionalItems b7fced33 Merge pull request #473 from json-schema-org/ether/more-default-tests eadb9be7 test that a missing property is not populated by the default in the actual instance data 839b95d8 Added opis/json-schema 7cf78800 Add missing comma 3390c871 Update tests/draft2020-12/unevaluatedItems.json 15ec577f Merge pull request #471 from json-schema-org/ether/id-anchor-in-enum 9f978651 test for confusing not-identifiers in enums d3b88001 Update tests/draft2020-12/unevaluatedItems.json 0f7ecd4a Merge pull request #475 from marksparkza/marksparkza-patch-1 84e1d5a9 Add another test case for unevaluatedItems-contains interaction 783d22a9 Add jschon f400802c Add tests for unevaluatedItems interaction with contains fc68499e Merge pull request #472 from json-schema-org/ether/unevaluatedProperties_uncles ed4cf5f8 more test cases for unevaluatedItems, unevaluatedProperties d0d814df Merge pull request #469 from json-schema-org/ether/ipv4-vulnerability 7ca5f36d reject ipv4 strings with an octet with a leading zero 8e1e1c18 fix spelling error in test descriptions 77f1d10c Merge pull request #462 from jdesrosiers/dynamic-ref-tests 72a32fe7 Merge pull request #468 from json-schema-org/ether/combine-test-cases 0c48ffba Merge pull request #453 from notEthan/float-overflow-d4-int 76a4ba0a these test cases can be combined since the schemas are the same cd73775f Merge pull request #464 from json-schema-org/ether/format-by-default-always-validates 043dc636 by default, "format" only annotates, not validates 3c45b816 Merge pull request #460 from amosonn/remove-remotes-from-script b09e48d0 Fix $ref with siblings in pre-2019-09 tests ff9f22e5 Add tests for $dynamicRef/$dynamicAnchor 0faaf097 Fix refs to Draft 2019-09 schema to be refs to 2020-12 ebbcbc82 Use flask to server remotes directly bb98b030 Remove remotes from bin/jsonschema_suite fcae732b Merge pull request #455 from jdesrosiers/bootstrap-202012 e0024097 Update tests for 2020-12 405b3fb4 Copy 2019-09 tests to bootstrap 2020-12 tests 93193442 Test cases for propertyNames with pattern - update after PR feedback. 1636a221 draft4 float-overflow instance may be considered not an integer 8e4aad95 Test cases for propertyNames with pattern. 8daea3f4 Merge pull request #451 from json-schema-org/ether/more-relative-json-pointer 69fe40f5 some more relative-json-pointer tests 6505944d Merge pull request #450 from json-schema-org/ether/recursiveRef-dynamic-path afd0cd31 Move content* keyword tests to non-optional e2b2a4b3 Change all content* keyword tests to always validate 8999eae1 $recursiveRef example demonstrating dynamic nature of the resolution scope f47003f1 fix duplicate test description bcf1dc81 Merge pull request #391 from ether/recursiveRef (rebased, squashed) 3d88f347 test $recursiveRef + $recursiveAnchor 3b79a452 Merge pull request #418 from ChALkeR/chalker/contentSchema 3627cc11 Fix draft3 as well, which didn't have allOf. eb1618b5 Fix misspelled reference in infinite-loop-detection tests d7821b62 remove duplicate files added by mistake in PR#446 a27c949b Merge pull request #446 from json-schema-org/ether/infinite-loop-detection 371fcaba Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm 45436c6c Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm 14cfcde1 Merge pull request #445 from json-schema-org/ether/naive-ref-replacement 128146da test that literal $refs are not evaluated as keywords 71ba357b Merge pull request #442 from jimblackler/master a6f759aa Update README.md 0f35b324 Merge pull request #441 from plxel/patch-1 d36b8b97 Update README.md d657d2b8 Update index.js 6a925b8d change folder to baseUriChange 96742ba3 Merge pull request #438 from Zac-HD/overflow-with-multipleOf c5ba4ba3 Check for multipleOf overflow c12b0db8 Merge pull request #437 from gregsdennis/if-then-else-sequencing bd148eb7 copy/paste error 3ca7c419 Added if/then/else sequencing tests; resolves #436 fa73bc8d Merge pull request #435 from jviotti/unevaluated-items-typo 2d6de7cb Fix "unevaluted" typos in "unevaluatedItems" suite 21555a85 Merge pull request #431 from ChALkeR/chalker/enum 87550ad6 Merge pull request #433 from notEthan/escaped_ref_in_def 57e31b49 refactor tests of escaped pointer refs to put ref'd schemas in definitions a21e4258 Add tests for objects in enum 2a9be81d Merge pull request #1 from json-schema-org/master 8a129948 Remove invalid format:regex test; the spec doesn't mandate parsing correctness fce9e9b3 Merge pull request #426 from helrond/padded-dates e61b6471 tests should invalidate 86f52b87 Fix a clear copy-paste error in the case names for tests from #394. df8f6bb9 add tests to date-time f137b811 add checks to draft3 3aa603fb adds tests for non zero-padded dates ec18a7d0 Merge pull request #360 from notEthan/duplicate_uris cd9a4b9d change schemas with duplicate URIs http://localhost:1234/folder/ 43e190e0 Merge pull request #394 from rjmill/rjmill/bools-and-1s-and-0s-inside-objects-and-arrays 85f0d459 Merge pull request #419 from ChALkeR/chalker/format-uri 54436216 Merge pull request #420 from ChALkeR/chalker/format/ip6 ad47b726 Add long valid and invalid ipv6 b2ab70ec More optional ipv6 tests 37189ae6 Test that uri format scheme is validated for allowed chars ea415537 Remove test that doesn't match RFC 3339 duration grammar 29f609b8 Add tests for contentSchema dee8ef7e Merge pull request #411 from ChALkeR/chalker/more-unevaluted cd88fb5c Add more nested and cousin unevaluatedProperties tests 5f3dc7e3 Merge pull request #415 from json-schema-org/ether/more-ipv6-tests 04ddab1a some more ipv6 tests acb45cd4 Merge pull request #417 from ChALkeR/chalker/patternProperties 0f4b73a0 One more patternProperties test with boolean schemas 8ccbfdc5 Merge pull request #412 from json-schema-org/ether/more-format-duration-2 1329dab9 some more tests for the "duration" format 1d5c3c0f Merge pull request #405 from ChALkeR/chalker/email-format 40601f62 Add idn-hostname validity and contextual rule tests fc05651c Merge pull request #409 from Stranger6667/dd/add-jsonschema-rs 5f1575a9 Add Rust `jsonschema` crate 2bf95bee Merge pull request #407 from fisxoj/master 9ae956b2 Add common lisp implementation to the list d4ffd569 Merge pull request #401 from json-schema-org/ether/format-uuid 2d6c4571 tests for the "uuid" format 08f6cdaf Merge pull request #400 from json-schema-org/ether/more-format-ipv6 d3064eb3 some more tests for the "ipv6" format 7ad74431 Extend email format tests 1f34d332 Merge pull request #399 from json-schema-org/ether/more-format-idn-email 22adda78 also test the "email" inputs against "idn-email" 25598a3b Merge pull request #392 from rjmill/rjmill/test-prop-named-ref-containing-a-ref 8dfa8adc Merge pull request #380 from ChALkeR/fix-ecmascript-regex d595dbf9 backport $ref cases, changing "$defs" to "definitions" 2106ed17 backport uniqueItems cases to draft3 57001d26 [294] Add tests for "additionalProperties" and "additionalItems" 49fc2a95 backport const test cases to draft6 27192102 Merge pull request #398 from ChALkeR/chalker/no-dec-ipv4 f5f481a6 Decimal IPs are also not dotted-quad ca8319c9 Fix \W test description 79fe60c0 more tests for true != 1 and false != 0 inside objects/arrays 452b5f8f Test property named $ref, containing an actual $ref a01ae540 Fix ECMA 262 regex whitespace tests. 817b724b add perl implementation and test suite to the user list ca14e010 Merge branch 'pull/382' 3dabf559 move non-format tests out of the format directory, while keeping all ECMA regex tests together 4121aa54 move format tests to their own directory 4bae8aa4 Add more idn-hostname tests to draft-2019-09 and draft-07 6d911588 [325] Add some more hostname tests e5930571 Merge pull request #389 from ssilverman/readme-drafts fb3766dc README: Improve issue/PR links 79bef228 README: Update language around drafts ade47e4c README: Add Snow to the list of supporting Java validators fc0c14ea README: Update simple JSON example 11676694 README: Update structure, consistency, spacing, and wrapping 9514122e Merge pull request #388 from json-schema-org/ether/maxProperties=0 76464907 test that maxProperties = 0 means the object is empty c3f43199 Merge pull request #384 from ChALkeR/chalker/unique 7766f486 Improve uniqueItems validation 7555d418 Add unnormalized $id tests 11f70eb4 [300] Add tests for valid use of empty fragments in "$id" b106ff04 [299] Add tests for invalid use of fragments in "$id" 4a74d455 Fix "tilde" spelling 3eca41b5 Merge pull request #379 from json-schema-org/ether/remove-wrapped-refs d61bae8f remove wrapped refs 536ec07d [359] Add unevaluatedProperties/unevaluatedItems cousin tests ac63eb75 Small README update that introduces the concept of directories 697944e9 Merge pull request #374 from karenetheridge/ether/allOf-anyOf-oneOf 33f85492 test all the *Of keywords together 44b99ed5 Merge pull request #373 from karenetheridge/ether/items-and-contains 4a2b52f5 some tests of items + contains 7f00cc82 add test that was present for other drafts but not 2019-09 a3f9e2e4 Merge pull request #371 from karenetheridge/ether/if-then-else-boolean aeeaeccb some tests with if/then/else and boolean schemas b8a083c2 Merge pull request #372 from nomnoms12/unique-false-and-zero 85728f1d Add tests for uniqueness [1] and [true] fd01a603 Add tests for uniqueness [1] and [true] 0a8823c4 Merge pull request #370 from karenetheridge/ether/nul-char fa6f4dd9 add tests for the NUL character in strings 8bf2f7f3 Merge pull request #369 from ssilverman/data-desc 2ba7a769 Add data description 4f660782 Merge pull request #367 from karenetheridge/ether/additionalItems 283da7c1 some more tests for additionalItems 7ba95f35 add tests for keywords maxContains, minContains 2f2e7cf8 Merge pull request #365 from karenetheridge/ether/move-ecma-regex 8388f27e move ECMA regex tests under format/ 9d0e0eb3 Merge pull request #362 from karenetheridge/ether/1.0-is-number fadab68f 1.0 is always a number (and an integer too for draft6+) 361620ec [355] Move non-BMP pattern tests to optional e1f870b1 Add "comment" to the tests bc68a6b8 Merge pull request #332 from jdesrosiers/unevaluated-tests ab9e3d5c 2 is more than 1. 846dd7ab Draft 4 isn't the most widely used anymore thankfully. 16191632 A bit less informal language in the README. 71f55b36 1.0 being an integer is not optional behavior. 240fbf6d Add a description to "schema" explaining it should be valid 8f8e9065 Update test schema to Draft 6 from Draft 4 2576db4d [350] Fix unmatched pattern-properties 0a0f0cd1 Move the "definitions" area below the main schema part bb80ebe5 Clean up some spacing 9ee9eff1 Add some description annotations 41732dbd Refactor a single test into the "definitions" area 2fc576e7 [53] Add test IDs c3731205 [264] Add pattern and patternProperties tests for non-BMP code points da35d880 [245] Add test for negative prefix in relative-json-pointer d17e1ba2 [242] Add pattern tests for numbers, objects, arrays, and null a5302a46 [329] Add tests for uniqueItems=false 0bf6358f [166] Add null-in-enum test 807591f0 Merge pull request #340 from karenetheridge/ether/markdown-conflict-markers e4c82f21 disambiguate underline from git conflict marker 6077b07e Update unevaluatedProperties and unevaluatedItems tests c4d3e0f9 Merge pull request #333 from zhxiaogg/tests-for-duration-format 618b30dc not all duration impl support year and month 926d0b3d tests for duration format 22eaffcd Merge pull request #331 from jdanyow/patch-2 b2e553e9 Merge pull request #330 from jdanyow/patch-1 9db34a17 remove unused constant cbf4654d fix typo in ref test description 44517887 Merge pull request #326 from awwright/master 8e2a05a9 Revert "HTTP -> HTTPS for specification URIs." f0594353 Merge pull request #327 from json-schema-org/ref-scoping 26933221 fixed test structure; had a think about the logic. 2d0ce046 added test to illustrate $ref defining a new scope 33791274 HTTP -> HTTPS for specification URIs. 0da2aaa1 Backport nested allOf/anyOf/oneOf tests 34a2dfa3 Add nested allOf, oneOf tests b70c5626 Merge remote-tracking branch 'origin/pr/323' 882688cb back out subSchemas.json changes, and instead add subSchemas-defs.json 0d6e1649 back out ref.json whitespace change and missing referant test 70ebd734 update subSchemas.json fixture in bin/jsonschema_suite b5123d1a In draft2019-09, you cannot reference arbitrary locations. 35041a34 Tests for unevaluatedItems. 8feb4292 More unevaluatedProperties tests. 960f519f Split dependencies.json into its 2 new keywords. d52866b3 This test duplicates 'dependentRequired with empty array' f7c851ff dependencies was split into dependentRequired and dependentSchemas. 47a5b018 Backport the new dependency test. 7a25f8b9 Another dependencies test, awaiting backport. 24940b2f Backport the new enum tests. 5d2afa8a More enum tests, awaiting backport. de713224 Missed one for draft3 minimum. 79833bbf More min and maximum tests, awaiting backport. 34efcdaf Backport the new const precision tests. 06a6295e More const tests, awaiting backport. 9a11d898 In draft2019-09, ref now does not ignore siblings. 7dc768a1 Backport eada031 to earlier drafts. 49c61979 Future-proof the sanity checker for #238. 39994975 Backport the additional min/max tests. 12b4a4c2 add optional test for $ref of an unknown keyword a863dbab Backport the additional const tests. 2e0e86e6 add more zero-valued types const tests e76e0294 2 is more than 1. 6c00de64 Run daily. 183d37fe Run on all branches. f865e88e Merge remote-tracking branch 'origin/Relequestual-fix-pr-ci' 777919bc Fix the contributor command info as well. e4e27709 Merge pull request #319 from json-schema-org/badge 5c7ac335 Fix the badge. 67f238bb Run CI for PRs bf2f2443 Merge pull request #315 from json-schema-org/gha 38c2e938 Travis CI -> GitHub Actions. 0f344a69 Merge pull request #313 from leadpony/issue309 46c44747 Replace the control escape \\a with \\t 1ffe03e5 Merge pull request #312 from gregsdennis/master de004798 better descripttions eea7f249 arrays have characters too 7c02d06d added unevaluatedProperties test file; resolves #310 1899a5aa Merge pull request #308 from aznan2/master 4a5010b3 Update the version list. 37569b13 issue #307 - made test compatible with draft4 e3087307 issue #307 - removed issue reference from description e13d3275 issue #307 - removed pound sign from description a3b9f723 issue #307 - test that oneOf handles missing optional property git-subtree-dir: JSON-Schema-Test-Suite git-subtree-split: 7950d9e0579382103031ef3cfcdc37e7c58b2d1f --- .editorconfig | 1 + .github/CODEOWNERS | 2 + .github/workflows/ci.yml | 25 + .gitignore | 161 +- .travis.yml | 8 - CONTRIBUTING.md | 87 + README.md | 325 +++- bin/jsonschema_suite | 772 ++++++-- index.js | 45 - output-test-schema.json | 70 + output-tests/README.md | 63 + output-tests/draft-next/content/general.json | 43 + output-tests/draft-next/content/readOnly.json | 41 + output-tests/draft-next/content/type.json | 39 + output-tests/draft-next/output-schema.json | 95 + output-tests/draft2019-09/content/escape.json | 38 + .../draft2019-09/content/general.json | 34 + .../draft2019-09/content/readOnly.json | 38 + output-tests/draft2019-09/content/type.json | 63 + output-tests/draft2019-09/output-schema.json | 96 + output-tests/draft2020-12/content/escape.json | 38 + .../draft2020-12/content/general.json | 34 + .../draft2020-12/content/readOnly.json | 37 + output-tests/draft2020-12/content/type.json | 63 + output-tests/draft2020-12/output-schema.json | 96 + package.json | 20 +- .../folderInteger.json | 0 .../baseUriChangeFolder/folderInteger.json | 3 + .../folderInteger.json | 3 + remotes/different-id-ref-string.json | 5 + .../baseUriChange/folderInteger.json | 4 + .../baseUriChangeFolder/folderInteger.json | 4 + .../folderInteger.json | 4 + .../draft-next/extendible-dynamic-ref.json | 21 + .../draft-next/format-assertion-false.json | 12 + remotes/draft-next/format-assertion-true.json | 12 + remotes/draft-next/integer.json | 4 + .../locationIndependentIdentifier.json | 12 + .../draft-next/metaschema-no-validation.json | 12 + .../metaschema-optional-vocabulary.json | 13 + remotes/draft-next/name-defs.json | 16 + remotes/draft-next/nested/foo-ref-string.json | 7 + remotes/draft-next/nested/string.json | 4 + remotes/draft-next/ref-and-defs.json | 12 + remotes/draft-next/subSchemas-defs.json | 11 + remotes/draft-next/subSchemas.json | 9 + remotes/draft-next/tree.json | 17 + .../baseUriChange/folderInteger.json | 4 + .../baseUriChangeFolder/folderInteger.json | 4 + .../folderInteger.json | 4 + remotes/draft2019-09/dependentRequired.json | 7 + .../draft2019-09/extendible-dynamic-ref.json | 21 + remotes/draft2019-09/ignore-prefixItems.json | 7 + remotes/draft2019-09/integer.json | 4 + .../locationIndependentIdentifier.json | 12 + .../metaschema-no-validation.json | 12 + .../metaschema-optional-vocabulary.json | 13 + remotes/draft2019-09/name-defs.json | 16 + .../draft2019-09/nested/foo-ref-string.json | 7 + remotes/draft2019-09/nested/string.json | 4 + remotes/draft2019-09/ref-and-defs.json | 12 + remotes/draft2019-09/subSchemas-defs.json | 11 + remotes/draft2019-09/subSchemas.json | 9 + remotes/draft2019-09/tree.json | 17 + .../baseUriChange/folderInteger.json | 4 + .../baseUriChangeFolder/folderInteger.json | 4 + .../folderInteger.json | 4 + .../draft2020-12/extendible-dynamic-ref.json | 21 + .../draft2020-12/format-assertion-false.json | 12 + .../draft2020-12/format-assertion-true.json | 12 + remotes/draft2020-12/integer.json | 4 + .../locationIndependentIdentifier.json | 12 + .../metaschema-no-validation.json | 12 + .../metaschema-optional-vocabulary.json | 13 + remotes/draft2020-12/name-defs.json | 16 + .../draft2020-12/nested/foo-ref-string.json | 7 + remotes/draft2020-12/nested/string.json | 4 + remotes/draft2020-12/prefixItems.json | 7 + remotes/draft2020-12/ref-and-defs.json | 12 + remotes/draft2020-12/subSchemas-defs.json | 11 + remotes/draft2020-12/subSchemas.json | 9 + remotes/draft2020-12/tree.json | 17 + remotes/draft7/ignore-dependentRequired.json | 7 + remotes/extendible-dynamic-ref.json | 20 + remotes/locationIndependentIdentifier.json | 11 + .../locationIndependentIdentifierDraft4.json | 11 + .../locationIndependentIdentifierPre2019.json | 11 + remotes/nested-absolute-ref-to-string.json | 9 + remotes/nested/foo-ref-string.json | 6 + remotes/nested/string.json | 3 + remotes/ref-and-definitions.json | 11 + remotes/ref-and-defs.json | 11 + remotes/subSchemas-defs.json | 10 + remotes/tree.json | 16 + remotes/urn-ref-string.json | 5 + test-schema.json | 96 +- tests/draft-next/additionalProperties.json | 156 ++ tests/draft-next/allOf.json | 312 ++++ tests/draft-next/anchor.json | 234 +++ tests/draft-next/anyOf.json | 203 +++ tests/draft-next/boolean_schema.json | 104 ++ tests/draft-next/const.json | 387 ++++ tests/draft-next/contains.json | 267 +++ tests/draft-next/content.json | 131 ++ tests/draft-next/default.json | 82 + tests/draft-next/defs.json | 21 + tests/draft-next/dependentRequired.json | 152 ++ tests/draft-next/dependentSchemas.json | 170 ++ tests/draft-next/dynamicRef.json | 568 ++++++ tests/draft-next/enum.json | 262 +++ tests/draft-next/exclusiveMaximum.json | 31 + tests/draft-next/exclusiveMinimum.json | 31 + tests/draft-next/format.json | 838 +++++++++ tests/draft-next/id.json | 294 +++ tests/draft-next/if-then-else.json | 268 +++ tests/draft-next/infinite-loop-detection.json | 37 + tests/draft-next/items.json | 284 +++ tests/draft-next/maxContains.json | 152 ++ tests/draft-next/maxItems.json | 50 + tests/draft-next/maxLength.json | 55 + tests/draft-next/maxProperties.json | 79 + tests/draft-next/maximum.json | 60 + tests/draft-next/minContains.json | 224 +++ tests/draft-next/minItems.json | 50 + tests/draft-next/minLength.json | 55 + tests/draft-next/minProperties.json | 60 + tests/draft-next/minimum.json | 75 + tests/draft-next/multipleOf.json | 98 + tests/draft-next/not.json | 153 ++ tests/draft-next/oneOf.json | 293 +++ tests/draft-next/optional/bignum.json | 110 ++ .../optional/dependencies-compatibility.json} | 152 +- .../draft-next/optional/ecmascript-regex.json | 596 +++++++ tests/draft-next/optional/float-overflow.json | 17 + .../draft-next/optional/format-assertion.json | 42 + .../draft-next/optional/format/date-time.json | 136 ++ tests/draft-next/optional/format/date.json | 246 +++ .../draft-next/optional/format/duration.json | 136 ++ tests/draft-next/optional/format/email.json | 121 ++ .../draft-next/optional/format/hostname.json | 101 ++ .../draft-next/optional/format/idn-email.json | 61 + .../optional/format/idn-hostname.json | 307 ++++ tests/draft-next/optional/format/ipv4.json | 87 + tests/draft-next/optional/format/ipv6.json | 211 +++ .../optional/format/iri-reference.json | 76 + tests/draft-next/optional/format/iri.json | 86 + .../optional/format/json-pointer.json | 201 +++ tests/draft-next/optional/format/regex.json | 51 + .../format/relative-json-pointer.json | 101 ++ tests/draft-next/optional/format/time.json | 236 +++ .../optional/format/uri-reference.json | 76 + .../optional/format/uri-template.json | 61 + tests/draft-next/optional/format/uri.json | 141 ++ tests/draft-next/optional/format/uuid.json | 116 ++ tests/draft-next/optional/non-bmp-regex.json | 86 + .../optional/refOfUnknownKeyword.json | 46 + tests/draft-next/pattern.json | 65 + tests/draft-next/patternProperties.json | 176 ++ tests/draft-next/prefixItems.json | 104 ++ tests/draft-next/properties.json | 242 +++ tests/draft-next/propertyDependencies.json | 161 ++ tests/draft-next/propertyNames.json | 85 + tests/draft-next/ref.json | 1059 +++++++++++ tests/draft-next/refRemote.json | 314 ++++ tests/draft-next/required.json | 158 ++ tests/draft-next/type.json | 501 ++++++ tests/draft-next/unevaluatedItems.json | 719 ++++++++ tests/draft-next/unevaluatedProperties.json | 1572 +++++++++++++++++ tests/draft-next/uniqueItems.json | 419 +++++ tests/draft-next/unknownKeyword.json | 57 + tests/draft-next/vocabulary.json | 57 + tests/draft2019-09/additionalItems.json | 124 +- tests/draft2019-09/additionalProperties.json | 33 +- tests/draft2019-09/allOf.json | 100 +- tests/draft2019-09/anchor.json | 170 +- tests/draft2019-09/anyOf.json | 20 +- tests/draft2019-09/const.json | 235 ++- tests/draft2019-09/contains.json | 85 +- tests/draft2019-09/content.json | 131 ++ tests/draft2019-09/default.json | 33 + tests/draft2019-09/defs.json | 15 +- tests/draft2019-09/dependentRequired.json | 152 ++ tests/draft2019-09/dependentSchemas.json | 170 ++ tests/draft2019-09/enum.json | 95 +- tests/draft2019-09/exclusiveMaximum.json | 1 + tests/draft2019-09/exclusiveMinimum.json | 1 + tests/draft2019-09/format.json | 401 +++-- tests/draft2019-09/id.json | 294 +++ tests/draft2019-09/if-then-else.json | 80 + .../draft2019-09/infinite-loop-detection.json | 37 + tests/draft2019-09/items.json | 49 +- tests/draft2019-09/maxContains.json | 102 ++ tests/draft2019-09/maxItems.json | 24 +- tests/draft2019-09/maxLength.json | 24 +- tests/draft2019-09/maxProperties.json | 43 +- tests/draft2019-09/maximum.json | 34 +- tests/draft2019-09/minContains.json | 224 +++ tests/draft2019-09/minItems.json | 24 +- tests/draft2019-09/minLength.json | 24 +- tests/draft2019-09/minProperties.json | 24 +- tests/draft2019-09/minimum.json | 22 +- tests/draft2019-09/multipleOf.json | 43 +- tests/draft2019-09/not.json | 42 +- tests/draft2019-09/oneOf.json | 95 +- tests/draft2019-09/optional/bignum.json | 55 +- tests/draft2019-09/optional/content.json | 77 - tests/draft2019-09/optional/cross-draft.json | 41 + .../optional/dependencies-compatibility.json | 282 +++ .../optional/ecmascript-regex.json | 415 ++++- .../draft2019-09/optional/float-overflow.json | 16 + .../optional/format/date-time.json | 91 +- tests/draft2019-09/optional/format/date.json | 227 ++- .../optional/format/duration.json | 136 ++ tests/draft2019-09/optional/format/email.json | 70 +- .../optional/format/hostname.json | 70 +- .../optional/format/idn-email.json | 45 +- .../optional/format/idn-hostname.json | 281 ++- tests/draft2019-09/optional/format/ipv4.json | 56 +- tests/draft2019-09/optional/format/ipv6.json | 185 +- .../optional/format/iri-reference.json | 35 +- tests/draft2019-09/optional/format/iri.json | 37 +- .../optional/format/json-pointer.json | 35 +- tests/draft2019-09/optional/format/regex.json | 35 +- .../format/relative-json-pointer.json | 72 +- tests/draft2019-09/optional/format/time.json | 217 ++- .../draft2019-09/optional/format/unknown.json | 46 + .../optional/format/uri-reference.json | 35 +- .../optional/format/uri-template.json | 35 +- tests/draft2019-09/optional/format/uri.json | 42 +- tests/draft2019-09/optional/format/uuid.json | 116 ++ tests/draft2019-09/optional/no-schema.json | 26 + .../draft2019-09/optional/non-bmp-regex.json | 86 + .../optional/refOfUnknownKeyword.json | 46 + .../optional/zeroTerminatedFloats.json | 15 - tests/draft2019-09/pattern.json | 37 +- tests/draft2019-09/patternProperties.json | 25 + tests/draft2019-09/properties.json | 75 + tests/draft2019-09/propertyNames.json | 41 +- tests/draft2019-09/recursiveRef.json | 408 +++++ tests/draft2019-09/ref.json | 742 +++++++- tests/draft2019-09/refRemote.json | 171 +- tests/draft2019-09/required.json | 53 + tests/draft2019-09/type.json | 53 +- tests/draft2019-09/unevaluatedItems.json | 627 +++++++ tests/draft2019-09/unevaluatedProperties.json | 1475 ++++++++++++++++ tests/draft2019-09/uniqueItems.json | 256 ++- tests/draft2019-09/unknownKeyword.json | 57 + tests/draft2019-09/vocabulary.json | 57 + tests/draft2020-12/additionalProperties.json | 156 ++ tests/draft2020-12/allOf.json | 312 ++++ tests/draft2020-12/anchor.json | 235 +++ tests/draft2020-12/anyOf.json | 203 +++ tests/draft2020-12/boolean_schema.json | 104 ++ tests/draft2020-12/const.json | 387 ++++ tests/draft2020-12/contains.json | 176 ++ tests/draft2020-12/content.json | 131 ++ tests/draft2020-12/default.json | 82 + tests/draft2020-12/defs.json | 21 + tests/draft2020-12/dependentRequired.json | 152 ++ tests/draft2020-12/dependentSchemas.json | 170 ++ tests/draft2020-12/dynamicRef.json | 673 +++++++ tests/draft2020-12/enum.json | 262 +++ tests/draft2020-12/exclusiveMaximum.json | 31 + tests/draft2020-12/exclusiveMinimum.json | 31 + tests/draft2020-12/format.json | 838 +++++++++ tests/draft2020-12/id.json | 294 +++ tests/draft2020-12/if-then-else.json | 268 +++ .../draft2020-12/infinite-loop-detection.json | 37 + tests/draft2020-12/items.json | 284 +++ tests/draft2020-12/maxContains.json | 102 ++ tests/draft2020-12/maxItems.json | 50 + tests/draft2020-12/maxLength.json | 55 + tests/draft2020-12/maxProperties.json | 79 + tests/draft2020-12/maximum.json | 60 + tests/draft2020-12/minContains.json | 224 +++ tests/draft2020-12/minItems.json | 50 + tests/draft2020-12/minLength.json | 55 + tests/draft2020-12/minProperties.json | 60 + tests/draft2020-12/minimum.json | 75 + tests/draft2020-12/multipleOf.json | 97 + tests/draft2020-12/not.json | 153 ++ tests/draft2020-12/oneOf.json | 293 +++ tests/draft2020-12/optional/bignum.json | 110 ++ tests/draft2020-12/optional/cross-draft.json | 18 + .../optional/dependencies-compatibility.json | 282 +++ .../optional/ecmascript-regex.json | 596 +++++++ .../draft2020-12/optional/float-overflow.json | 17 + .../optional/format-assertion.json | 42 + .../optional/format/date-time.json | 136 ++ tests/draft2020-12/optional/format/date.json | 246 +++ .../optional/format/duration.json | 136 ++ tests/draft2020-12/optional/format/email.json | 121 ++ .../optional/format/hostname.json | 101 ++ .../optional/format/idn-email.json | 61 + .../optional/format/idn-hostname.json | 307 ++++ tests/draft2020-12/optional/format/ipv4.json | 87 + tests/draft2020-12/optional/format/ipv6.json | 211 +++ .../optional/format/iri-reference.json | 76 + tests/draft2020-12/optional/format/iri.json | 86 + .../optional/format/json-pointer.json | 201 +++ tests/draft2020-12/optional/format/regex.json | 51 + .../format/relative-json-pointer.json | 101 ++ tests/draft2020-12/optional/format/time.json | 236 +++ .../draft2020-12/optional/format/unknown.json | 46 + .../optional/format/uri-reference.json | 76 + .../optional/format/uri-template.json | 61 + tests/draft2020-12/optional/format/uri.json | 141 ++ tests/draft2020-12/optional/format/uuid.json | 116 ++ tests/draft2020-12/optional/no-schema.json | 26 + .../draft2020-12/optional/non-bmp-regex.json | 86 + .../optional/refOfUnknownKeyword.json | 46 + tests/draft2020-12/pattern.json | 65 + tests/draft2020-12/patternProperties.json | 176 ++ tests/draft2020-12/prefixItems.json | 104 ++ tests/draft2020-12/properties.json | 242 +++ tests/draft2020-12/propertyNames.json | 85 + tests/draft2020-12/ref.json | 1059 +++++++++++ tests/draft2020-12/refRemote.json | 314 ++++ tests/draft2020-12/required.json | 158 ++ tests/draft2020-12/type.json | 501 ++++++ tests/draft2020-12/unevaluatedItems.json | 719 ++++++++ tests/draft2020-12/unevaluatedProperties.json | 1475 ++++++++++++++++ tests/draft2020-12/uniqueItems.json | 419 +++++ tests/draft2020-12/unknownKeyword.json | 57 + tests/draft2020-12/vocabulary.json | 57 + tests/draft3/additionalItems.json | 56 +- tests/draft3/additionalProperties.json | 22 +- tests/draft3/default.json | 30 + tests/draft3/dependencies.json | 5 + tests/draft3/enum.json | 47 + tests/draft3/format.json | 160 +- tests/draft3/infinite-loop-detection.json | 32 + tests/draft3/items.json | 32 + tests/draft3/maximum.json | 57 + tests/draft3/minimum.json | 17 +- tests/draft3/optional/bignum.json | 38 +- tests/draft3/optional/format.json | 227 --- tests/draft3/optional/format/color.json | 38 + tests/draft3/optional/format/date-time.json | 38 + tests/draft3/optional/format/date.json | 168 ++ tests/draft3/optional/format/email.json | 53 + tests/draft3/optional/format/host-name.json | 63 + tests/draft3/optional/format/ip-address.json | 23 + tests/draft3/optional/format/ipv6.json | 68 + tests/draft3/optional/format/regex.json | 18 + tests/draft3/optional/format/time.json | 18 + tests/draft3/optional/format/uri.json | 28 + tests/draft3/optional/non-bmp-regex.json | 82 + tests/draft3/pattern.json | 27 +- tests/draft3/patternProperties.json | 15 + tests/draft3/properties.json | 15 + tests/draft3/ref.json | 106 +- tests/draft3/refRemote.json | 2 +- tests/draft3/type.json | 8 +- tests/draft3/uniqueItems.json | 217 ++- tests/draft4/additionalItems.json | 83 +- tests/draft4/additionalProperties.json | 22 +- tests/draft4/allOf.json | 76 + tests/draft4/default.json | 30 + tests/draft4/definitions.json | 10 +- tests/draft4/dependencies.json | 38 + tests/draft4/enum.json | 57 + tests/draft4/format.json | 96 +- tests/draft4/id.json | 53 + tests/draft4/infinite-loop-detection.json | 36 + tests/draft4/items.json | 32 + tests/draft4/maxProperties.json | 16 + tests/draft4/maximum.json | 26 + tests/draft4/minimum.json | 12 +- tests/draft4/multipleOf.json | 22 + tests/draft4/oneOf.json | 68 + tests/draft4/optional/bignum.json | 38 +- tests/draft4/optional/ecmascript-regex.json | 385 +++- tests/draft4/optional/float-overflow.json | 13 + tests/draft4/optional/format.json | 253 --- tests/draft4/optional/format/date-time.json | 133 ++ tests/draft4/optional/format/email.json | 83 + tests/draft4/optional/format/hostname.json | 98 + tests/draft4/optional/format/ipv4.json | 84 + tests/draft4/optional/format/ipv6.json | 208 +++ tests/draft4/optional/format/unknown.json | 43 + tests/draft4/optional/format/uri.json | 138 ++ tests/draft4/optional/non-bmp-regex.json | 82 + tests/draft4/pattern.json | 27 +- tests/draft4/patternProperties.json | 15 + tests/draft4/properties.json | 69 + tests/draft4/ref.json | 237 ++- tests/draft4/refRemote.json | 24 +- tests/draft4/required.json | 46 + tests/draft4/type.json | 5 + tests/draft4/uniqueItems.json | 244 ++- tests/draft6/additionalItems.json | 106 +- tests/draft6/additionalProperties.json | 22 +- tests/draft6/allOf.json | 76 + tests/draft6/const.json | 174 +- tests/draft6/contains.json | 44 + tests/draft6/default.json | 30 + tests/draft6/definitions.json | 10 +- tests/draft6/dependencies.json | 68 +- tests/draft6/enum.json | 57 + tests/draft6/format.json | 144 +- tests/draft6/id.json | 134 ++ tests/draft6/infinite-loop-detection.json | 36 + tests/draft6/items.json | 32 + tests/draft6/maxItems.json | 16 + tests/draft6/maxLength.json | 16 + tests/draft6/maxProperties.json | 32 + tests/draft6/maximum.json | 26 + tests/draft6/minItems.json | 16 + tests/draft6/minLength.json | 16 + tests/draft6/minProperties.json | 16 + tests/draft6/minimum.json | 12 +- tests/draft6/multipleOf.json | 22 + tests/draft6/oneOf.json | 68 + tests/draft6/optional/bignum.json | 38 +- tests/draft6/optional/ecmascript-regex.json | 385 +++- tests/draft6/optional/float-overflow.json | 13 + tests/draft6/optional/format.json | 491 ----- tests/draft6/optional/format/date-time.json | 133 ++ tests/draft6/optional/format/email.json | 83 + tests/draft6/optional/format/hostname.json | 98 + tests/draft6/optional/format/ipv4.json | 84 + tests/draft6/optional/format/ipv6.json | 208 +++ .../draft6/optional/format/json-pointer.json | 198 +++ tests/draft6/optional/format/unknown.json | 43 + .../draft6/optional/format/uri-reference.json | 73 + .../draft6/optional/format/uri-template.json | 58 + tests/draft6/optional/format/uri.json | 138 ++ tests/draft6/optional/non-bmp-regex.json | 82 + .../draft6/optional/zeroTerminatedFloats.json | 15 - tests/draft6/pattern.json | 27 +- tests/draft6/patternProperties.json | 20 + tests/draft6/properties.json | 69 + tests/draft6/propertyNames.json | 29 + tests/draft6/ref.json | 525 +++++- tests/draft6/refRemote.json | 74 +- tests/draft6/required.json | 46 + tests/draft6/type.json | 10 + tests/draft6/uniqueItems.json | 244 ++- tests/draft6/unknownKeyword.json | 56 + tests/draft7/additionalItems.json | 106 +- tests/draft7/additionalProperties.json | 22 +- tests/draft7/allOf.json | 76 + tests/draft7/const.json | 174 +- tests/draft7/contains.json | 65 + tests/draft7/default.json | 30 + tests/draft7/definitions.json | 10 +- tests/draft7/dependencies.json | 68 +- tests/draft7/enum.json | 57 + tests/draft7/format.json | 272 +-- tests/draft7/id.json | 114 ++ tests/draft7/if-then-else.json | 70 + tests/draft7/infinite-loop-detection.json | 36 + tests/draft7/items.json | 32 + tests/draft7/maxItems.json | 16 + tests/draft7/maxLength.json | 16 + tests/draft7/maxProperties.json | 32 + tests/draft7/maximum.json | 26 + tests/draft7/minItems.json | 16 + tests/draft7/minLength.json | 16 + tests/draft7/minProperties.json | 16 + tests/draft7/minimum.json | 12 +- tests/draft7/multipleOf.json | 22 + tests/draft7/oneOf.json | 68 + tests/draft7/optional/bignum.json | 38 +- tests/draft7/optional/cross-draft.json | 25 + tests/draft7/optional/ecmascript-regex.json | 385 +++- tests/draft7/optional/float-overflow.json | 13 + tests/draft7/optional/format/date-time.json | 88 +- tests/draft7/optional/format/date.json | 224 ++- tests/draft7/optional/format/email.json | 67 +- tests/draft7/optional/format/hostname.json | 67 +- tests/draft7/optional/format/idn-email.json | 42 +- .../draft7/optional/format/idn-hostname.json | 278 ++- tests/draft7/optional/format/ipv4.json | 53 +- tests/draft7/optional/format/ipv6.json | 182 +- .../draft7/optional/format/iri-reference.json | 32 +- tests/draft7/optional/format/iri.json | 34 +- .../draft7/optional/format/json-pointer.json | 32 +- tests/draft7/optional/format/regex.json | 32 +- .../format/relative-json-pointer.json | 69 +- tests/draft7/optional/format/time.json | 214 ++- tests/draft7/optional/format/unknown.json | 43 + .../draft7/optional/format/uri-reference.json | 32 +- .../draft7/optional/format/uri-template.json | 32 +- tests/draft7/optional/format/uri.json | 39 +- tests/draft7/optional/non-bmp-regex.json | 82 + .../draft7/optional/zeroTerminatedFloats.json | 15 - tests/draft7/pattern.json | 27 +- tests/draft7/patternProperties.json | 20 + tests/draft7/properties.json | 69 + tests/draft7/propertyNames.json | 29 + tests/draft7/ref.json | 631 ++++++- tests/draft7/refRemote.json | 74 +- tests/draft7/required.json | 46 + tests/draft7/type.json | 10 + tests/draft7/uniqueItems.json | 238 ++- tests/draft7/unknownKeyword.json | 56 + tests/latest | 2 +- tox.ini | 2 +- 500 files changed, 55106 insertions(+), 2633 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 CONTRIBUTING.md delete mode 100644 index.js create mode 100644 output-test-schema.json create mode 100644 output-tests/README.md create mode 100644 output-tests/draft-next/content/general.json create mode 100644 output-tests/draft-next/content/readOnly.json create mode 100644 output-tests/draft-next/content/type.json create mode 100644 output-tests/draft-next/output-schema.json create mode 100644 output-tests/draft2019-09/content/escape.json create mode 100644 output-tests/draft2019-09/content/general.json create mode 100644 output-tests/draft2019-09/content/readOnly.json create mode 100644 output-tests/draft2019-09/content/type.json create mode 100644 output-tests/draft2019-09/output-schema.json create mode 100644 output-tests/draft2020-12/content/escape.json create mode 100644 output-tests/draft2020-12/content/general.json create mode 100644 output-tests/draft2020-12/content/readOnly.json create mode 100644 output-tests/draft2020-12/content/type.json create mode 100644 output-tests/draft2020-12/output-schema.json rename remotes/{folder => baseUriChange}/folderInteger.json (100%) create mode 100644 remotes/baseUriChangeFolder/folderInteger.json create mode 100644 remotes/baseUriChangeFolderInSubschema/folderInteger.json create mode 100644 remotes/different-id-ref-string.json create mode 100644 remotes/draft-next/baseUriChange/folderInteger.json create mode 100644 remotes/draft-next/baseUriChangeFolder/folderInteger.json create mode 100644 remotes/draft-next/baseUriChangeFolderInSubschema/folderInteger.json create mode 100644 remotes/draft-next/extendible-dynamic-ref.json create mode 100644 remotes/draft-next/format-assertion-false.json create mode 100644 remotes/draft-next/format-assertion-true.json create mode 100644 remotes/draft-next/integer.json create mode 100644 remotes/draft-next/locationIndependentIdentifier.json create mode 100644 remotes/draft-next/metaschema-no-validation.json create mode 100644 remotes/draft-next/metaschema-optional-vocabulary.json create mode 100644 remotes/draft-next/name-defs.json create mode 100644 remotes/draft-next/nested/foo-ref-string.json create mode 100644 remotes/draft-next/nested/string.json create mode 100644 remotes/draft-next/ref-and-defs.json create mode 100644 remotes/draft-next/subSchemas-defs.json create mode 100644 remotes/draft-next/subSchemas.json create mode 100644 remotes/draft-next/tree.json create mode 100644 remotes/draft2019-09/baseUriChange/folderInteger.json create mode 100644 remotes/draft2019-09/baseUriChangeFolder/folderInteger.json create mode 100644 remotes/draft2019-09/baseUriChangeFolderInSubschema/folderInteger.json create mode 100644 remotes/draft2019-09/dependentRequired.json create mode 100644 remotes/draft2019-09/extendible-dynamic-ref.json create mode 100644 remotes/draft2019-09/ignore-prefixItems.json create mode 100644 remotes/draft2019-09/integer.json create mode 100644 remotes/draft2019-09/locationIndependentIdentifier.json create mode 100644 remotes/draft2019-09/metaschema-no-validation.json create mode 100644 remotes/draft2019-09/metaschema-optional-vocabulary.json create mode 100644 remotes/draft2019-09/name-defs.json create mode 100644 remotes/draft2019-09/nested/foo-ref-string.json create mode 100644 remotes/draft2019-09/nested/string.json create mode 100644 remotes/draft2019-09/ref-and-defs.json create mode 100644 remotes/draft2019-09/subSchemas-defs.json create mode 100644 remotes/draft2019-09/subSchemas.json create mode 100644 remotes/draft2019-09/tree.json create mode 100644 remotes/draft2020-12/baseUriChange/folderInteger.json create mode 100644 remotes/draft2020-12/baseUriChangeFolder/folderInteger.json create mode 100644 remotes/draft2020-12/baseUriChangeFolderInSubschema/folderInteger.json create mode 100644 remotes/draft2020-12/extendible-dynamic-ref.json create mode 100644 remotes/draft2020-12/format-assertion-false.json create mode 100644 remotes/draft2020-12/format-assertion-true.json create mode 100644 remotes/draft2020-12/integer.json create mode 100644 remotes/draft2020-12/locationIndependentIdentifier.json create mode 100644 remotes/draft2020-12/metaschema-no-validation.json create mode 100644 remotes/draft2020-12/metaschema-optional-vocabulary.json create mode 100644 remotes/draft2020-12/name-defs.json create mode 100644 remotes/draft2020-12/nested/foo-ref-string.json create mode 100644 remotes/draft2020-12/nested/string.json create mode 100644 remotes/draft2020-12/prefixItems.json create mode 100644 remotes/draft2020-12/ref-and-defs.json create mode 100644 remotes/draft2020-12/subSchemas-defs.json create mode 100644 remotes/draft2020-12/subSchemas.json create mode 100644 remotes/draft2020-12/tree.json create mode 100644 remotes/draft7/ignore-dependentRequired.json create mode 100644 remotes/extendible-dynamic-ref.json create mode 100644 remotes/locationIndependentIdentifier.json create mode 100644 remotes/locationIndependentIdentifierDraft4.json create mode 100644 remotes/locationIndependentIdentifierPre2019.json create mode 100644 remotes/nested-absolute-ref-to-string.json create mode 100644 remotes/nested/foo-ref-string.json create mode 100644 remotes/nested/string.json create mode 100644 remotes/ref-and-definitions.json create mode 100644 remotes/ref-and-defs.json create mode 100644 remotes/subSchemas-defs.json create mode 100644 remotes/tree.json create mode 100644 remotes/urn-ref-string.json create mode 100644 tests/draft-next/additionalProperties.json create mode 100644 tests/draft-next/allOf.json create mode 100644 tests/draft-next/anchor.json create mode 100644 tests/draft-next/anyOf.json create mode 100644 tests/draft-next/boolean_schema.json create mode 100644 tests/draft-next/const.json create mode 100644 tests/draft-next/contains.json create mode 100644 tests/draft-next/content.json create mode 100644 tests/draft-next/default.json create mode 100644 tests/draft-next/defs.json create mode 100644 tests/draft-next/dependentRequired.json create mode 100644 tests/draft-next/dependentSchemas.json create mode 100644 tests/draft-next/dynamicRef.json create mode 100644 tests/draft-next/enum.json create mode 100644 tests/draft-next/exclusiveMaximum.json create mode 100644 tests/draft-next/exclusiveMinimum.json create mode 100644 tests/draft-next/format.json create mode 100644 tests/draft-next/id.json create mode 100644 tests/draft-next/if-then-else.json create mode 100644 tests/draft-next/infinite-loop-detection.json create mode 100644 tests/draft-next/items.json create mode 100644 tests/draft-next/maxContains.json create mode 100644 tests/draft-next/maxItems.json create mode 100644 tests/draft-next/maxLength.json create mode 100644 tests/draft-next/maxProperties.json create mode 100644 tests/draft-next/maximum.json create mode 100644 tests/draft-next/minContains.json create mode 100644 tests/draft-next/minItems.json create mode 100644 tests/draft-next/minLength.json create mode 100644 tests/draft-next/minProperties.json create mode 100644 tests/draft-next/minimum.json create mode 100644 tests/draft-next/multipleOf.json create mode 100644 tests/draft-next/not.json create mode 100644 tests/draft-next/oneOf.json create mode 100644 tests/draft-next/optional/bignum.json rename tests/{draft2019-09/dependencies.json => draft-next/optional/dependencies-compatibility.json} (77%) create mode 100644 tests/draft-next/optional/ecmascript-regex.json create mode 100644 tests/draft-next/optional/float-overflow.json create mode 100644 tests/draft-next/optional/format-assertion.json create mode 100644 tests/draft-next/optional/format/date-time.json create mode 100644 tests/draft-next/optional/format/date.json create mode 100644 tests/draft-next/optional/format/duration.json create mode 100644 tests/draft-next/optional/format/email.json create mode 100644 tests/draft-next/optional/format/hostname.json create mode 100644 tests/draft-next/optional/format/idn-email.json create mode 100644 tests/draft-next/optional/format/idn-hostname.json create mode 100644 tests/draft-next/optional/format/ipv4.json create mode 100644 tests/draft-next/optional/format/ipv6.json create mode 100644 tests/draft-next/optional/format/iri-reference.json create mode 100644 tests/draft-next/optional/format/iri.json create mode 100644 tests/draft-next/optional/format/json-pointer.json create mode 100644 tests/draft-next/optional/format/regex.json create mode 100644 tests/draft-next/optional/format/relative-json-pointer.json create mode 100644 tests/draft-next/optional/format/time.json create mode 100644 tests/draft-next/optional/format/uri-reference.json create mode 100644 tests/draft-next/optional/format/uri-template.json create mode 100644 tests/draft-next/optional/format/uri.json create mode 100644 tests/draft-next/optional/format/uuid.json create mode 100644 tests/draft-next/optional/non-bmp-regex.json create mode 100644 tests/draft-next/optional/refOfUnknownKeyword.json create mode 100644 tests/draft-next/pattern.json create mode 100644 tests/draft-next/patternProperties.json create mode 100644 tests/draft-next/prefixItems.json create mode 100644 tests/draft-next/properties.json create mode 100644 tests/draft-next/propertyDependencies.json create mode 100644 tests/draft-next/propertyNames.json create mode 100644 tests/draft-next/ref.json create mode 100644 tests/draft-next/refRemote.json create mode 100644 tests/draft-next/required.json create mode 100644 tests/draft-next/type.json create mode 100644 tests/draft-next/unevaluatedItems.json create mode 100644 tests/draft-next/unevaluatedProperties.json create mode 100644 tests/draft-next/uniqueItems.json create mode 100644 tests/draft-next/unknownKeyword.json create mode 100644 tests/draft-next/vocabulary.json create mode 100644 tests/draft2019-09/content.json create mode 100644 tests/draft2019-09/dependentRequired.json create mode 100644 tests/draft2019-09/dependentSchemas.json create mode 100644 tests/draft2019-09/id.json create mode 100644 tests/draft2019-09/infinite-loop-detection.json create mode 100644 tests/draft2019-09/maxContains.json create mode 100644 tests/draft2019-09/minContains.json delete mode 100644 tests/draft2019-09/optional/content.json create mode 100644 tests/draft2019-09/optional/cross-draft.json create mode 100644 tests/draft2019-09/optional/dependencies-compatibility.json create mode 100644 tests/draft2019-09/optional/float-overflow.json create mode 100644 tests/draft2019-09/optional/format/duration.json create mode 100644 tests/draft2019-09/optional/format/unknown.json create mode 100644 tests/draft2019-09/optional/format/uuid.json create mode 100644 tests/draft2019-09/optional/no-schema.json create mode 100644 tests/draft2019-09/optional/non-bmp-regex.json create mode 100644 tests/draft2019-09/optional/refOfUnknownKeyword.json delete mode 100644 tests/draft2019-09/optional/zeroTerminatedFloats.json create mode 100644 tests/draft2019-09/recursiveRef.json create mode 100644 tests/draft2019-09/unevaluatedItems.json create mode 100644 tests/draft2019-09/unevaluatedProperties.json create mode 100644 tests/draft2019-09/unknownKeyword.json create mode 100644 tests/draft2019-09/vocabulary.json create mode 100644 tests/draft2020-12/additionalProperties.json create mode 100644 tests/draft2020-12/allOf.json create mode 100644 tests/draft2020-12/anchor.json create mode 100644 tests/draft2020-12/anyOf.json create mode 100644 tests/draft2020-12/boolean_schema.json create mode 100644 tests/draft2020-12/const.json create mode 100644 tests/draft2020-12/contains.json create mode 100644 tests/draft2020-12/content.json create mode 100644 tests/draft2020-12/default.json create mode 100644 tests/draft2020-12/defs.json create mode 100644 tests/draft2020-12/dependentRequired.json create mode 100644 tests/draft2020-12/dependentSchemas.json create mode 100644 tests/draft2020-12/dynamicRef.json create mode 100644 tests/draft2020-12/enum.json create mode 100644 tests/draft2020-12/exclusiveMaximum.json create mode 100644 tests/draft2020-12/exclusiveMinimum.json create mode 100644 tests/draft2020-12/format.json create mode 100644 tests/draft2020-12/id.json create mode 100644 tests/draft2020-12/if-then-else.json create mode 100644 tests/draft2020-12/infinite-loop-detection.json create mode 100644 tests/draft2020-12/items.json create mode 100644 tests/draft2020-12/maxContains.json create mode 100644 tests/draft2020-12/maxItems.json create mode 100644 tests/draft2020-12/maxLength.json create mode 100644 tests/draft2020-12/maxProperties.json create mode 100644 tests/draft2020-12/maximum.json create mode 100644 tests/draft2020-12/minContains.json create mode 100644 tests/draft2020-12/minItems.json create mode 100644 tests/draft2020-12/minLength.json create mode 100644 tests/draft2020-12/minProperties.json create mode 100644 tests/draft2020-12/minimum.json create mode 100644 tests/draft2020-12/multipleOf.json create mode 100644 tests/draft2020-12/not.json create mode 100644 tests/draft2020-12/oneOf.json create mode 100644 tests/draft2020-12/optional/bignum.json create mode 100644 tests/draft2020-12/optional/cross-draft.json create mode 100644 tests/draft2020-12/optional/dependencies-compatibility.json create mode 100644 tests/draft2020-12/optional/ecmascript-regex.json create mode 100644 tests/draft2020-12/optional/float-overflow.json create mode 100644 tests/draft2020-12/optional/format-assertion.json create mode 100644 tests/draft2020-12/optional/format/date-time.json create mode 100644 tests/draft2020-12/optional/format/date.json create mode 100644 tests/draft2020-12/optional/format/duration.json create mode 100644 tests/draft2020-12/optional/format/email.json create mode 100644 tests/draft2020-12/optional/format/hostname.json create mode 100644 tests/draft2020-12/optional/format/idn-email.json create mode 100644 tests/draft2020-12/optional/format/idn-hostname.json create mode 100644 tests/draft2020-12/optional/format/ipv4.json create mode 100644 tests/draft2020-12/optional/format/ipv6.json create mode 100644 tests/draft2020-12/optional/format/iri-reference.json create mode 100644 tests/draft2020-12/optional/format/iri.json create mode 100644 tests/draft2020-12/optional/format/json-pointer.json create mode 100644 tests/draft2020-12/optional/format/regex.json create mode 100644 tests/draft2020-12/optional/format/relative-json-pointer.json create mode 100644 tests/draft2020-12/optional/format/time.json create mode 100644 tests/draft2020-12/optional/format/unknown.json create mode 100644 tests/draft2020-12/optional/format/uri-reference.json create mode 100644 tests/draft2020-12/optional/format/uri-template.json create mode 100644 tests/draft2020-12/optional/format/uri.json create mode 100644 tests/draft2020-12/optional/format/uuid.json create mode 100644 tests/draft2020-12/optional/no-schema.json create mode 100644 tests/draft2020-12/optional/non-bmp-regex.json create mode 100644 tests/draft2020-12/optional/refOfUnknownKeyword.json create mode 100644 tests/draft2020-12/pattern.json create mode 100644 tests/draft2020-12/patternProperties.json create mode 100644 tests/draft2020-12/prefixItems.json create mode 100644 tests/draft2020-12/properties.json create mode 100644 tests/draft2020-12/propertyNames.json create mode 100644 tests/draft2020-12/ref.json create mode 100644 tests/draft2020-12/refRemote.json create mode 100644 tests/draft2020-12/required.json create mode 100644 tests/draft2020-12/type.json create mode 100644 tests/draft2020-12/unevaluatedItems.json create mode 100644 tests/draft2020-12/unevaluatedProperties.json create mode 100644 tests/draft2020-12/uniqueItems.json create mode 100644 tests/draft2020-12/unknownKeyword.json create mode 100644 tests/draft2020-12/vocabulary.json create mode 100644 tests/draft3/infinite-loop-detection.json delete mode 100644 tests/draft3/optional/format.json create mode 100644 tests/draft3/optional/format/color.json create mode 100644 tests/draft3/optional/format/date-time.json create mode 100644 tests/draft3/optional/format/date.json create mode 100644 tests/draft3/optional/format/email.json create mode 100644 tests/draft3/optional/format/host-name.json create mode 100644 tests/draft3/optional/format/ip-address.json create mode 100644 tests/draft3/optional/format/ipv6.json create mode 100644 tests/draft3/optional/format/regex.json create mode 100644 tests/draft3/optional/format/time.json create mode 100644 tests/draft3/optional/format/uri.json create mode 100644 tests/draft3/optional/non-bmp-regex.json create mode 100644 tests/draft4/id.json create mode 100644 tests/draft4/infinite-loop-detection.json create mode 100644 tests/draft4/optional/float-overflow.json delete mode 100644 tests/draft4/optional/format.json create mode 100644 tests/draft4/optional/format/date-time.json create mode 100644 tests/draft4/optional/format/email.json create mode 100644 tests/draft4/optional/format/hostname.json create mode 100644 tests/draft4/optional/format/ipv4.json create mode 100644 tests/draft4/optional/format/ipv6.json create mode 100644 tests/draft4/optional/format/unknown.json create mode 100644 tests/draft4/optional/format/uri.json create mode 100644 tests/draft4/optional/non-bmp-regex.json create mode 100644 tests/draft6/id.json create mode 100644 tests/draft6/infinite-loop-detection.json create mode 100644 tests/draft6/optional/float-overflow.json delete mode 100644 tests/draft6/optional/format.json create mode 100644 tests/draft6/optional/format/date-time.json create mode 100644 tests/draft6/optional/format/email.json create mode 100644 tests/draft6/optional/format/hostname.json create mode 100644 tests/draft6/optional/format/ipv4.json create mode 100644 tests/draft6/optional/format/ipv6.json create mode 100644 tests/draft6/optional/format/json-pointer.json create mode 100644 tests/draft6/optional/format/unknown.json create mode 100644 tests/draft6/optional/format/uri-reference.json create mode 100644 tests/draft6/optional/format/uri-template.json create mode 100644 tests/draft6/optional/format/uri.json create mode 100644 tests/draft6/optional/non-bmp-regex.json delete mode 100644 tests/draft6/optional/zeroTerminatedFloats.json create mode 100644 tests/draft6/unknownKeyword.json create mode 100644 tests/draft7/id.json create mode 100644 tests/draft7/infinite-loop-detection.json create mode 100644 tests/draft7/optional/cross-draft.json create mode 100644 tests/draft7/optional/float-overflow.json create mode 100644 tests/draft7/optional/format/unknown.json create mode 100644 tests/draft7/optional/non-bmp-regex.json delete mode 100644 tests/draft7/optional/zeroTerminatedFloats.json create mode 100644 tests/draft7/unknownKeyword.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..6db6a5bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1 @@ +insert_final_newline = true diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..15f4a2db --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Ping the entire test suite team by default. +* @json-schema-org/test-suite-team diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a826069b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: Test Suite Sanity Checking + +on: + push: + pull_request: + release: + types: [published] + schedule: + # Daily at 6:42, arbitrarily as a time that's possibly non-busy + - cron: '42 6 * * *' + +jobs: + ci: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - name: Install tox + run: python -m pip install tox + - name: Run the sanity checks + run: python -m tox diff --git a/.gitignore b/.gitignore index 1333ed77..68bc17f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,160 @@ -TODO +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f65e40bb..00000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: python -python: "3.7" -node_js: "9" -install: - - pip install tox -script: - - tox - - npm install && npm test || true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..8dab09e6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,87 @@ +# Contributing to the Suite + +All contributors to the test suite should familiarize themselves with this document. + +Both pull requests *and* reviews are welcome from any and all, regardless of their "formal" relationship (or lack thereof) with the JSON Schema organization. + +## Commit Access + +Any existing members with commit access to the repository may nominate new members to get access, or a contributor may request access for themselves. +Access generally should be granted liberally to anyone who has shown positive contributions to the repository or organization. +All who are active in other parts of the JSON Schema organization should get access to this repository as well. +Access for a former contributor may be removed after long periods of inactivity. + +## Reviewing a Pull Request + +Pull requests may (and often should) be reviewed for approval by a single reviewer whose job it is to confirm the change is specified, correct, minimal and follows general style in the repository. +A reviewer who does not feel comfortable signing off on the correctness of a change is free to comment without explicit approval. +Other contributors are also encouraged to comment on pull requests whenever they have feedback, even if another contributor has submitted review comments. +A submitter may also choose to request additional feedback if they feel the change is particularly technical or complex, or requires expertise in a particular area of the specification. +If additional reviewers have participated in a pull request, the submitter should not rely on a single reviewer's approval without some form of confirmation that all participating reviewers are satisfied. +On the other hand, whenever possible, reviewers who have minor comments should explicitly mention that they are OK with the PR being merged after or potentially *without* addressing them. + +When submitting a change, explicitly soliciting a specific reviewer explicitly is currently not needed, as the entire review team is generally pinged for pull requests. +Nevertheless, submitters may choose to do so if they want specific review from an individual, or if a pull request is sitting without review for a period of time. +For the latter scenario, leaving a comment on the pull request or in Slack is also reasonable. + +Confirming that a pull request runs successfully on an implementation is *not* generally sufficient to merge, though it is helpful evidence, and highly encouraged. +Proposed changes should be confirmed by reading the specification and ensuring the behavior is specified and correct. +Submitters are encouraged to link to the specification whenever doing so will be helpful to a reviewer. + +A reviewer may indicate that the proposed changes are too large for them to review. +In such cases the submitter may wait for another reviewer who is comfortable reviewing the changes, but is generally strongly encouraged to split up the changes into multiple smaller ones. + +Reviewing pull requests is an extremely valuable contribution! +New reviewers are highly encouraged to attempt to review pull requests even if they do not have experience doing so, and to themselves expect feedback from the submitter or from other reviewers on improving the quality of their reviews. +In such cases the submitter should use their judgement to decide whether the new contributor's review is sufficient for merging, or whether they should wait for further feedback. + +## Merging Changes + +Approval of a change may be given using the GitHub UI or via a comment reply. +Once it has been given, the pull request may be merged at any point. + +To merge a pull request, *either* the submitter or reviewer must have commit access to the repo (though this is also partially simply because that party's access is needed to merge). + +*Either* the submitter or reviewer may be the one to do the actual merge (whether via hitting the merge button or externally to the GitHub UI). +If the submitter wishes to make final changes after a review they should attempt to say so (and thereby take responsibility for merging themselves). +Contributors *should not* leave pull requests stagnant whenever possible, and particularly after they have been reviewed and approved. + +Changes should not be merged while continuous integration is failing. +Failures typically are not spurious and indicate issues with the changes. +In the event the change is indeed correct and CI is flaky or itself incorrect, effort should be made by the submitter, reviewer, or a solicited other contributor to fix the CI before the change is made. +Improvements to CI itself are very valuable as well, and reviewers who find repeated issues with proposed changes are highly encouraged to improve CI for any changes which may be automatically detected. + +Changes should be merged *as-is* and not squashed into single commits. +Submitters are free to structure their commits as they wish throughout the review process, or in some cases to restructure the commits after a review is finished and they are merging the branch, but are not required to do so, and reviewers should not do so on behalf of the submitter without being requested to do so. + +Contributors with commit access may choose to merge pull requests (or commit directly) to the repository for trivial changes. +The definition of "trivial" is intentionally slightly ambiguous, and intended to be followed by good-faith contributors. +An example of a trivial change is fixing a typo in the README, or bumping a version of a dependency used by the continuous integration suite. +If another contributor takes issue with a change merged in this fashion, simply commenting politely that they have concerns about the change (either in an issue or directly) is the right remedy. + +## Writing Good Tests + +Be familiar with the test structure and assumptions documented in the [README](README.md). + +Test cases should include both valid and invalid instances which exercise the test case schema whenever possible. +Exceptions include schemas where only one result is ever possible (such as the `false` schema, or ones using keywords which only produce annotations). + +Schemas should be *minimal*, by which we mean that they should contain only those keywords which are being tested by the specific test case, and should not contain complex values when simpler ones would do. +The same applies to instances -- prefer simpler instances to more complex ones, and when testing string instances, consider using ones which are self-descriptive whenever it aids readability. + +Comments can and should be used to explain tests which are unclear or complex. +The `comment` field is present both for test cases and individual tests for this purpose. +Links to the relevant specification sections are also encouraged, though they can be tedious to maintain from one version to the next. + +When adding test cases, they should be added to all past (and future) versions of the specification which they apply to, potentially with minor modifications (e.g. changing `$id` to `id` or accounting for `$ref` not allowing siblings on older drafts). + +Changing the schema used in a particular test case should be done with extra caution, though it is not formally discouraged if the change simplifies the schema. +Contributors should not generally append *additional* behavior to existing test case schemas, unless doing so has specific justification. +Instead, new cases should be added, as it can often be subtle to predict which precise parts of a test case are unique. +Adding additional *tests* however (instances) is of course safe and encouraged if gaps are found. + +Tests which are *incorrect* (against the specification) should be prioritized for fixing or removal whenever possible, as their continued presence in the suite can create confusion for downstream users of the suite. + +## Proposing Changes to the Policy + +This policy itself is of course changeable, and changes to it may be proposed in a discussion. diff --git a/README.md b/README.md index f65934c4..cdd5dc8a 100644 --- a/README.md +++ b/README.md @@ -1,113 +1,267 @@ -JSON Schema Test Suite [![Build Status](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite.svg?branch=master)](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite) -====================== +# JSON Schema Test Suite -This repository contains a set of JSON objects that implementors of JSON Schema -validation libraries can use to test their validators. +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md) +[![Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![Financial Contributors on Open Collective](https://opencollective.com/json-schema/all/badge.svg?label=financial+contributors)](https://opencollective.com/json-schema) + +[![DOI](https://zenodo.org/badge/5952934.svg)](https://zenodo.org/badge/latestdoi/5952934) +[![Build Status](https://github.com/json-schema-org/JSON-Schema-Test-Suite/workflows/Test%20Suite%20Sanity%20Checking/badge.svg)](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22) + +This repository contains a set of JSON objects that implementers of JSON Schema validation libraries can use to test their validators. It is meant to be language agnostic and should require only a JSON parser. +The conversion of the JSON objects into tests within a specific language and test framework of choice is left to be done by the validator implementer. + +The recommended workflow of this test suite is to clone the `main` branch of this repository as a `git submodule` or `git subtree`. The `main` branch is always stable. + +## Coverage + +All JSON Schema specification releases should be well covered by this suite, including drafts 2020-12, 2019-09, 07, 06, 04 and 03. +Drafts 04 and 03 are considered "frozen" in that less effort is put in to backport new tests to these versions. + +Additional coverage is always welcome, particularly for bugs encountered in real-world implementations. +If you see anything missing or incorrect, please feel free to [file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues) or [submit a PR](https://github.com/json-schema-org/JSON-Schema-Test-Suite). + +@gregsdennis has also started a separate [test suite](https://github.com/gregsdennis/json-schema-vocab-test-suites) that is modelled after this suite to cover third-party vocabularies. + +## Introduction to the Test Suite Structure + +The tests in this suite are contained in the `tests` directory at the root of this repository. +Inside that directory is a subdirectory for each released version of the specification. + +The structure and contents of each file in these directories is described below. + +In addition to the version-specific subdirectories, two additional directories are present: + +1. `draft-next/`: containing tests for the next version of the specification whilst it is in development +2. `latest/`: a symbolic link which points to the directory which is the most recent release (which may be useful for implementations providing specific entry points for validating against the latest version of the specification) -The conversion of the JSON objects into tests within your test framework of -choice is still the job of the validator implementor. +Inside each version directory there are a number of `.json` files each containing a collection of related tests. +Often the grouping is by property under test, but not always. +In addition to the `.json` files, each version directory contains one or more special subdirectories whose purpose is [described below](#subdirectories-within-each-draft), and which contain additional `.json` files. -Structure of a Test -------------------- +Each `.json` file consists of a single JSON array of test cases. -If you're going to use this suite, you need to know how tests are laid out. The -tests are contained in the `tests` directory at the root of this repository. +### Terminology -Inside that directory is a subdirectory for each draft or version of the -schema. +For clarity, we first define this document's usage of some testing terminology: -If you look inside the draft directory, there are a number of `.json` files, -which logically group a set of test cases together. Often the grouping is by -property under test, but not always, especially within optional test files -(discussed below). +| term | definition | +|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **test suite** | the entirety of the contents of this repository, containing tests for multiple different releases of the JSON Schema specification | +| **test case** | a single schema, along with a description and an array of *test*s | +| **test** | within a *test case*, a single test example, containing a description, instance and a boolean indicating whether the instance is valid under the test case schema | +| **test runner** | a program, external to this repository and authored by a user of this suite, which is executing each of the tests in the suite | -Inside each `.json` file is a single array containing objects. It's easiest to -illustrate the structure of these with an example: +An example illustrating this structure is immediately below, and a JSON Schema containing a formal definition of the contents of test cases can be found [alongside this README](./test-schema.json). + +### Sample Test Case + +Here is a single *test case*, containing one or more tests: ```json - { - "description": "the description of the test case", - "schema": {"the schema that should" : "be validated against"}, - "tests": [ - { - "description": "a specific test of a valid instance", - "data": "the instance", - "valid": true - }, - { - "description": "another specific test this time, invalid", - "data": 15, - "valid": false - } - ] - } +{ + "description": "The test case description", + "schema": { "type": "string" }, + "tests": [ + { + "description": "a test with a valid instance", + "data": "a string", + "valid": true + }, + { + "description": "a test with an invalid instance", + "data": 15, + "valid": false + } + ] +} ``` -So a description, a schema, and some tests, where tests is an array containing -one or more objects with descriptions, data, and a boolean indicating whether -they should be valid or invalid. +### Subdirectories Within Each Draft + +There is currently only one additional subdirectory that may exist within each draft test directory. + +This is: + +1. `optional/`: Contains tests that are considered optional. + +Note, the `optional/` subdirectory today conflates many reasons why a test may be optional -- it may be because tests within a particular file are indeed not required by the specification but still potentially useful to an implementer, or it may be because tests within it only apply to programming languages with particular functionality (in +which case they are not truly optional in such a language). +In the future this directory structure will be made richer to reflect these differences more clearly. + +## Using the Suite to Test a Validator Implementation + +The test suite structure was described [above](#introduction-to-the-test-suite-structure). + +If you are authoring a new validator implementation, or adding support for an additional version of the specification, this section describes: + +1. How to implement a test runner which passes tests to your validator +2. Assumptions the suite makes about how the test runner will configure your validator +3. Invariants the test suite claims to hold for its tests -Coverage --------- +### How to Implement a Test Runner -Drafts 03, 04, 06, and 07 should have full coverage, with drafts 06 and 07 -being considered current and actively supported. Bug fixes will be made as -needed for draft-04 as it is still the most widely used, while draft-03 -is long since deprecated. +Presented here is a possible implementation of a test runner. +The precise steps described do not need to be followed exactly, but the results of your own procedure should produce the same effects. -If you see anything missing from the current supported drafts, or incorrect -on any draft still accepting bug fixes, please file an issue or submit a PR. +To test a specific version: -Who Uses the Test Suite ------------------------ +* 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 +* Walk the filesystem tree for that version's subdirectory and for each `.json` file found: + + * if the file is located in the root of the version directory: + + * for each test case present in the file: + + * load the schema from the `"schema"` property + * load (or log) the test case description from the `"description"` property for debugging or outputting + * for each test in the `"tests"` property: + + * load the instance to be tested from the `"data"` property + * load (or log) the individual test description from the `"description"` property for debugging or outputting + + * use the schema loaded above to validate whether the instance is considered valid under your implementation + + * if the result from your implementation matches the value found in the `"valid"` property, your implementation correctly implements the specific example + * if the result does not match, or your implementation errors or crashes, your implementation does not correctly implement the specific example + + * otherwise it is located in a special subdirectory as described above. + Follow the additional assumptions and restrictions for the containing subdirectory, then run the test case as above. + +If your implementation supports multiple versions, run the above procedure for each version supported, configuring your implementation as appropriate to call each version individually. + +### Additional Assumptions + +1. The suite, notably in its `refRemote.json` file in each draft, expects a number of remote references to be configured. + These are JSON documents, identified by URI, which are used by the suite to test the behavior of the `$ref` keyword (and related keywords). + Depending on your implementation, you may configure how to "register" these *either*: + + * by directly retrieving them off the filesystem from the `remotes/` directory, in which case you should load each schema with a retrieval URI of `http://localhost:1234` followed by the relative path from the remotes directory -- e.g. a `$ref` to `http://localhost:1234/foo/bar/baz.json` is expected to resolve to the contents of the file at `remotes/foo/bar/baz.json` + + * or alternatively, by executing `bin/jsonschema_suite remotes` using the executable in the `bin/` directory, which will output a JSON object containing all of the remotes combined, e.g.: + + ``` + + $ bin/jsonschema_suite remotes + ``` + ```json + { + "http://localhost:1234/baseUriChange/folderInteger.json": { + "type": "integer" + }, + "http://localhost:1234/baseUriChangeFolder/folderInteger.json": { + "type": "integer" + } + } + ``` + +2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run. + In particular, tests within the `optional/format` subdirectory may require implementations to change the way they treat the `"format"`keyword (particularly on older drafts which did not have a notion of vocabularies). + +### Invariants & Guarantees + +The test suite guarantees a number of things about tests it defines. +Any deviation from the below is generally considered a bug. +If you suspect one, please [file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/new): + +1. All files containing test cases are valid JSON. +2. The contents of the `"schema"` property in a test case are always valid + JSON Schemas under the corresponding specification. + + The rationale behind this is that we are testing instances in a test's `"data"` element, and not the schema itself. + A number of tests *do* test the validity of a schema itself, but do so by representing the schema as an instance inside a test, with the associated meta-schema in the `"schema"` property (via the `"$ref"` keyword): + + ```json + { + "description": "Test the \"type\" schema keyword", + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Valid: string", + "data": { + "type": "string" + }, + "valid": true + }, + { + "description": "Invalid: null", + "data": { + "type": null + }, + "valid": false + } + ] + } + ``` + See below for some [known limitations](#known-limitations). + +## Known Limitations + +This suite expresses its assertions about the behavior of an implementation *within* JSON Schema itself. +Each test is the application of a schema to a particular instance. +This means that the suite of tests can test against any behavior a schema can describe, and conversely cannot test against any behavior which a schema is incapable of representing, even if the behavior is mandated by the specification. + +For example, a schema can require that a string is a _URI-reference_ and even that it matches a certain pattern, but even though the specification contains [recommendations about URIs being normalized](https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-id-keyword), a JSON schema cannot today represent this assertion within the core vocabularies of the specifications, so no test covers this behavior. + +## Who Uses the Test Suite This suite is being used by: -### Clojure ### +### Clojure * [jinx](https://github.com/juxt/jinx) * [json-schema](https://github.com/tatut/json-schema) -### Coffeescript ### +### Coffeescript * [jsck](https://github.com/pandastrike/jsck) -### C++ ### +### Common Lisp + +* [json-schema](https://github.com/fisxoj/json-schema) + +### C++ * [Modern C++ JSON schema validator](https://github.com/pboettch/json-schema-validator) +* [Valijson](https://github.com/tristanpenman/valijson) -### Dart ### +### Dart -* [json_schema](https://github.com/patefacio/json_schema) +* [json\_schema](https://github.com/patefacio/json_schema) -### Elixir ### +### Elixir -* [ex_json_schema](https://github.com/jonasschmidt/ex_json_schema) +* [ex\_json\_schema](https://github.com/jonasschmidt/ex_json_schema) -### Erlang ### +### Erlang * [jesse](https://github.com/for-GET/jesse) -### Go ### +### Go * [gojsonschema](https://github.com/sigu-399/gojsonschema) * [validate-json](https://github.com/cesanta/validate-json) -### Haskell ### +### Haskell * [aeson-schema](https://github.com/timjb/aeson-schema) * [hjsonschema](https://github.com/seagreen/hjsonschema) -### Java ### +### Java * [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) -### JavaScript ### +### JavaScript * [json-schema-benchmark](https://github.com/Muscula/json-schema-benchmark) * [direct-schema](https://github.com/IreneKnapp/direct-schema) @@ -125,57 +279,70 @@ This suite is being used by: * [ajv](https://github.com/epoberezkin/ajv) * [djv](https://github.com/korzio/djv) -### Node.js ### +### Node.js -For node.js developers, the suite is also available as an -[npm](https://www.npmjs.com/package/@json-schema-org/tests) package. +For node.js developers, the suite is also available as an [npm](https://www.npmjs.com/package/@json-schema-org/tests) package. -Node-specific support is maintained in a [separate -repository](https://github.com/json-schema-org/json-schema-test-suite-npm) -which also welcomes your contributions! +Node-specific support is maintained in a [separate repository](https://github.com/json-schema-org/json-schema-test-suite-npm) which also welcomes your contributions! -### .NET ### +### .NET +* [JsonSchema.Net](https://github.com/gregsdennis/json-everything) * [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema) -* [Manatee.Json](https://github.com/gregsdennis/Manatee.Json) -### PHP ### +### Perl +* [Test::JSON::Schema::Acceptance](https://github.com/karenetheridge/Test-JSON-Schema-Acceptance) (a wrapper of this test suite) +* [JSON::Schema::Modern](https://github.com/karenetheridge/JSON-Schema-Modern) +* [JSON::Schema::Tiny](https://github.com/karenetheridge/JSON-Schema-Tiny) + +### PHP + +* [opis/json-schema](https://github.com/opis/json-schema) * [json-schema](https://github.com/justinrainbow/json-schema) * [json-guard](https://github.com/thephpleague/json-guard) -### PostgreSQL ### +### PostgreSQL * [postgres-json-schema](https://github.com/gavinwahl/postgres-json-schema) -* [is_jsonb_valid](https://github.com/furstenheim/is_jsonb_valid) +* [is\_jsonb\_valid](https://github.com/furstenheim/is_jsonb_valid) -### Python ### +### Python * [jsonschema](https://github.com/Julian/jsonschema) * [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) -### Ruby ### +### Ruby * [json-schema](https://github.com/hoxworth/json-schema) -* [json_schemer](https://github.com/davishmcclurg/json_schemer) +* [json\_schemer](https://github.com/davishmcclurg/json_schemer) -### Rust ### +### Rust +* [jsonschema](https://github.com/Stranger6667/jsonschema-rs) * [valico](https://github.com/rustless/valico) -### Swift ### +### Scala + +* [typed-json](https://github.com/frawa/typed-json) + +### Swift * [JSONSchema](https://github.com/kylef/JSONSchema.swift) If you use it as well, please fork and send a pull request adding yourself to the list :). -Contributing ------------- +## Contributing If you see something missing or incorrect, a pull request is most welcome! There are some sanity checks in place for testing the test suite. You can run -them with `bin/jsonschema_suite check && npm test` or `tox && npm test`. They will be run automatically by -[Travis CI](https://travis-ci.org/) as well. +them with `bin/jsonschema_suite check` or `tox`. They will be run automatically +by [GitHub Actions](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22) +as well. + +This repository is maintained by the JSON Schema organization, and will be governed by the JSON Schema steering committee (once it exists). diff --git a/bin/jsonschema_suite b/bin/jsonschema_suite index 6b1c4864..9fee8d7b 100755 --- a/bin/jsonschema_suite +++ b/bin/jsonschema_suite @@ -1,9 +1,7 @@ #! /usr/bin/env python3 -from __future__ import print_function -from pprint import pformat +from pathlib import Path +from urllib.parse import urljoin import argparse -import errno -import fnmatch import json import os import random @@ -13,181 +11,621 @@ import textwrap import unittest import warnings -if getattr(unittest, "skipIf", None) is None: - unittest.skipIf = lambda cond, msg : lambda fn : fn - try: - import jsonschema + import jsonschema.validators except ImportError: jsonschema = None + VALIDATORS = {} else: - validators = getattr( - jsonschema.validators, "validators", jsonschema.validators - ) - - -ROOT_DIR = os.path.abspath( - os.path.join(os.path.dirname(__file__), os.pardir).rstrip("__pycache__"), + VALIDATORS = { + "draft3": jsonschema.validators.Draft3Validator, + "draft4": jsonschema.validators.Draft4Validator, + "draft6": jsonschema.validators.Draft6Validator, + "draft7": jsonschema.validators.Draft7Validator, + "draft2019-09": jsonschema.validators.Draft201909Validator, + "draft2020-12": jsonschema.validators.Draft202012Validator, + "latest": jsonschema.validators.Draft202012Validator, + } + + +ROOT_DIR = Path(__file__).parent.parent +SUITE_ROOT_DIR = ROOT_DIR / "tests" +OUTPUT_ROOT_DIR = ROOT_DIR / "output-tests" + +REMOTES_DIR = ROOT_DIR / "remotes" +REMOTES_BASE_URL = "http://localhost:1234/" + +TEST_SCHEMA = json.loads(ROOT_DIR.joinpath("test-schema.json").read_text()) +OUTPUT_TEST_SCHEMA = json.loads( + ROOT_DIR.joinpath("output-test-schema.json").read_text(), ) -SUITE_ROOT_DIR = os.path.join(ROOT_DIR, "tests") - -REMOTES = { - "integer.json": {u"type": u"integer"}, - "name.json": { - u"type": "string", - u"definitions": { - u"orNull": {u"anyOf": [{u"type": u"null"}, {u"$ref": u"#"}]}, - }, - }, - "name-defs.json": { - u"type": "string", - u"$defs": { - u"orNull": {u"anyOf": [{u"type": u"null"}, {u"$ref": u"#"}]}, - }, - }, - "subSchemas.json": { - u"integer": {u"type": u"integer"}, - u"refToInteger": {u"$ref": u"#/integer"}, - }, - "folder/folderInteger.json": {u"type": u"integer"} -} -REMOTES_DIR = os.path.join(ROOT_DIR, "remotes") - -with open(os.path.join(ROOT_DIR, "test-schema.json")) as schema: - TESTSUITE_SCHEMA = json.load(schema) + def files(paths): + """ + Each test file in the provided paths, as an array of test cases. + """ for path in paths: - with open(path) as test_file: - yield json.load(test_file) - - -def groups(paths): - for test_file in files(paths): - for group in test_file: - yield group + yield path, json.loads(path.read_text()) def cases(paths): - for test_group in groups(paths): - for test in test_group["tests"]: - test["schema"] = test_group["schema"] + """ + Each test case within each file in the provided paths. + """ + for _, test_file in files(paths): + yield from test_file + + +def tests(paths): + """ + Each individual test within all cases within the provided paths. + """ + for case in cases(paths): + for test in case["tests"]: + test["schema"] = case["schema"] yield test def collect(root_dir): - for root, dirs, files in os.walk(root_dir): - for filename in fnmatch.filter(files, "*.json"): - yield os.path.join(root, filename) + """ + All of the test file paths within the given root directory, recursively. + """ + return root_dir.rglob("*.json") + + +def url_for_path(path): + """ + Return the assumed remote URL for a file in the remotes/ directory. + + Tests in the refRemote.json file reference this URL, and assume the + corresponding contents are available at the URL. + """ + + return urljoin( + REMOTES_BASE_URL, + str(path.relative_to(REMOTES_DIR)).replace("\\", "/"), # Windows... + ) + + +def versions_and_validators(): + """ + All versions we can validate schemas from. + """ + + for version in SUITE_ROOT_DIR.iterdir(): + if not version.is_dir(): + continue + + Validator = VALIDATORS.get(version.name) + if Validator is None: + warnings.warn(f"No schema validator for {version.name}") + continue + + yield version, Validator class SanityTests(unittest.TestCase): @classmethod def setUpClass(cls): - print("Looking for tests in %s" % SUITE_ROOT_DIR) + print(f"Looking for tests in {SUITE_ROOT_DIR}") + print(f"Looking for output tests in {OUTPUT_ROOT_DIR}") + print(f"Looking for remotes in {REMOTES_DIR}") + cls.test_files = list(collect(SUITE_ROOT_DIR)) - print("Found %s test files" % len(cls.test_files)) assert cls.test_files, "Didn't find the test files!" - - def test_all_files_are_valid_json(self): - for path in self.test_files: - with open(path) as test_file: + print(f"Found {len(cls.test_files)} test files") + + cls.output_test_files = [ + each + for each in collect(OUTPUT_ROOT_DIR) + if each.name != "output-schema.json" + ] + assert cls.output_test_files, "Didn't find the output test files!" + print(f"Found {len(cls.output_test_files)} output test files") + + cls.remote_files = list(collect(REMOTES_DIR)) + assert cls.remote_files, "Didn't find the remote files!" + print(f"Found {len(cls.remote_files)} remote files") + + def assertUnique(self, iterable): + """ + Assert that the elements of an iterable are unique. + """ + + seen, duplicated = set(), set() + for each in iterable: + if each in seen: + duplicated.add(each) + seen.add(each) + self.assertFalse(duplicated, "Elements are not unique.") + + def assertFollowsDescriptionStyle(self, description): + """ + Instead of saying "test that X frobs" or "X should frob" use "X frobs". + + See e.g. https://jml.io/pages/test-docstrings.html + + This test isn't comprehensive (it doesn't catch all the extra + verbiage there), but it's just to catch whatever it manages to + cover. + """ + + message = ( + "In descriptions, don't say 'Test that X frobs' or 'X should " + "frob' or 'X should be valid'. Just say 'X frobs' or 'X is " + "valid'. It's shorter, and the test suite is entirely about " + "what *should* be already. " + "See https://jml.io/pages/test-docstrings.html for help." + ) + self.assertNotRegex(description, r"\bshould\b", message) + self.assertNotRegex(description, r"(?i)\btest(s)? that\b", message) + + def test_all_json_files_are_valid(self): + """ + All files (tests, output tests, remotes, etc.) contain valid JSON. + """ + for path in collect(ROOT_DIR): + with self.subTest(path=path): try: - json.load(test_file) + json.loads(path.read_text()) except ValueError as error: - self.fail("%s contains invalid JSON (%s)" % (path, error)) - - def test_all_descriptions_have_reasonable_length(self): - for case in cases(self.test_files): - description = case["description"] - self.assertLess( - len(description), - 70, - "%r is too long! (keep it to less than 70 chars)" % ( - description, - ), - ) - - def test_all_descriptions_are_unique(self): - for group in groups(self.test_files): - descriptions = set(test["description"] for test in group["tests"]) - self.assertEqual( - len(descriptions), - len(group["tests"]), - "%r contains a duplicate description" % (group,) - ) + self.fail(f"{path} contains invalid JSON ({error})") + + def test_all_case_descriptions_have_reasonable_length(self): + """ + All cases have reasonably long descriptions. + """ + for case in cases(self.test_files + self.output_test_files): + with self.subTest(description=case["description"]): + self.assertLess( + len(case["description"]), + 150, + "Description is too long (keep it to less than 150 chars).", + ) + + def test_all_test_descriptions_have_reasonable_length(self): + """ + All tests have reasonably long descriptions. + """ + for count, test in enumerate( + tests(self.test_files + self.output_test_files) + ): + with self.subTest(description=test["description"]): + self.assertLess( + len(test["description"]), + 70, + "Description is too long (keep it to less than 70 chars).", + ) + print(f"Found {count} tests.") + + def test_all_case_descriptions_are_unique(self): + """ + All cases have unique descriptions in their files. + """ + for path, cases in files(self.test_files + self.output_test_files): + with self.subTest(path=path): + self.assertUnique(case["description"] for case in cases) + + def test_all_test_descriptions_are_unique(self): + """ + All test cases have unique test descriptions in their tests. + """ + for count, case in enumerate( + cases(self.test_files + self.output_test_files) + ): + with self.subTest(description=case["description"]): + self.assertUnique( + test["description"] for test in case["tests"] + ) + print(f"Found {count} test cases.") + + def test_case_descriptions_do_not_use_modal_verbs(self): + for case in cases(self.test_files + self.output_test_files): + with self.subTest(description=case["description"]): + self.assertFollowsDescriptionStyle(case["description"]) + + def test_test_descriptions_do_not_use_modal_verbs(self): + for test in tests(self.test_files + self.output_test_files): + with self.subTest(description=test["description"]): + self.assertFollowsDescriptionStyle(test["description"]) @unittest.skipIf(jsonschema is None, "Validation library not present!") def test_all_schemas_are_valid(self): - for schema in os.listdir(SUITE_ROOT_DIR): - schema_validator = validators.get(schema) - if schema_validator is not None: - test_files = collect(os.path.join(SUITE_ROOT_DIR, schema)) - for case in cases(test_files): + """ + All schemas are valid under their metaschemas. + """ + for version, Validator in versions_and_validators(): + # Valid (optional test) schemas contain regexes which + # aren't valid Python regexes, so skip checking it + Validator.FORMAT_CHECKER.checkers.pop("regex", None) + + test_files = collect(version) + for case in cases(test_files): + with self.subTest(case=case): try: - schema_validator.check_schema(case["schema"]) - except jsonschema.SchemaError as error: - self.fail("%s contains an invalid schema (%s)" % - (case, error)) - else: - warnings.warn("No schema validator for %s" % schema) + Validator.check_schema( + case["schema"], + format_checker=Validator.FORMAT_CHECKER, + ) + except jsonschema.SchemaError: + self.fail( + "Found an invalid schema. " + "See the traceback for details on why." + ) @unittest.skipIf(jsonschema is None, "Validation library not present!") - def test_suites_are_valid(self): - validator = jsonschema.Draft4Validator(TESTSUITE_SCHEMA) - for tests in files(self.test_files): - try: - validator.validate(tests) - except jsonschema.ValidationError as error: - self.fail(str(error)) - - def test_remote_schemas_are_updated(self): - files = {} - for parent, _, paths in os.walk(REMOTES_DIR): - for path in paths: - absolute_path = os.path.join(parent, path) - with open(absolute_path) as schema_file: - files[absolute_path] = json.load(schema_file) - - expected = { - os.path.join(REMOTES_DIR, path): contents - for path, contents in REMOTES.items() + def test_arbitrary_schemas_do_not_use_unknown_keywords(self): + """ + Test cases do not use unknown keywords. + + (Unless they specifically are testing the specified behavior for + unknown keywords). + + This helps prevent accidental leakage of newer keywords into older + drafts where they didn't exist. + """ + + KNOWN = { + "draft2020-12": { + "$anchor", + "$comment", + "$defs", + "$dynamicAnchor", + "$dynamicRef", + "$id", + "$ref", + "$schema", + "$vocabulary", + "additionalProperties", + "allOf", + "allOf", + "anyOf", + "const", + "contains", + "contentEncoding", + "contentMediaType", + "contentSchema", + "dependencies", + "dependentRequired", + "dependentSchemas", + "description", + "else", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "format", + "if", + "items", + "maxContains", + "maxItems", + "maxItems", + "maxLength", + "maxProperties", + "maximum", + "minContains", + "minItems", + "minLength", + "minProperties", + "minimum", + "multipleOf", + "not", + "oneOf", + "pattern", + "patternProperties", + "prefixItems", + "properties", + "propertyNames", + "required", + "then", + "title", + "type", + "unevaluatedItems", + "unevaluatedProperties", + "uniqueItems", + }, + "draft2019-09": { + "$anchor", + "$comment", + "$defs", + "$id", + "$recursiveAnchor", + "$recursiveRef", + "$ref", + "$schema", + "$vocabulary", + "additionalItems", + "additionalProperties", + "allOf", + "anyOf", + "const", + "contains", + "contentEncoding", + "contentMediaType", + "contentSchema", + "dependencies", + "dependentRequired", + "dependentSchemas", + "description", + "else", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "format", + "if", + "items", + "maxContains", + "maxItems", + "maxLength", + "maxProperties", + "maximum", + "minContains", + "minItems", + "minLength", + "minProperties", + "minimum", + "multipleOf", + "not", + "oneOf", + "pattern", + "patternProperties", + "properties", + "propertyNames", + "required", + "then", + "title", + "type", + "unevaluatedItems", + "unevaluatedProperties", + "uniqueItems", + }, + "draft7": { + "$comment", + "$id", + "$ref", + "$schema", + "additionalItems", + "additionalProperties", + "allOf", + "anyOf", + "const", + "contains", + "contentEncoding", + "contentMediaType", + "definitions", + "dependencies", + "description", + "else", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "format", + "if", + "items", + "maxItems", + "maxLength", + "maxProperties", + "maximum", + "minItems", + "minLength", + "minProperties", + "minimum", + "multipleOf", + "not", + "oneOf", + "pattern", + "patternProperties", + "properties", + "propertyNames", + "required", + "then", + "title", + "type", + "type", + "uniqueItems", + }, + "draft6": { + "$comment", + "$id", + "$ref", + "$schema", + "additionalItems", + "additionalProperties", + "allOf", + "anyOf", + "const", + "contains", + "definitions", + "dependencies", + "description", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "format", + "items", + "maxItems", + "maxLength", + "maxProperties", + "maximum", + "minItems", + "minLength", + "minProperties", + "minimum", + "multipleOf", + "not", + "oneOf", + "pattern", + "patternProperties", + "properties", + "propertyNames", + "required", + "title", + "type", + "uniqueItems", + }, + "draft4": { + "$ref", + "$schema", + "additionalItems", + "additionalItems", + "additionalProperties", + "allOf", + "anyOf", + "definitions", + "dependencies", + "description", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "format", + "id", + "items", + "maxItems", + "maxLength", + "maxProperties", + "maximum", + "minItems", + "minLength", + "minProperties", + "minimum", + "multipleOf", + "not", + "oneOf", + "pattern", + "patternProperties", + "properties", + "required", + "title", + "type", + "uniqueItems", + + # Technically this is wrong, $comment doesn't exist in this + # draft, but the point of this test is to detect mistakes by, + # test authors, whereas the point of the $comment keyword is + # to just standardize a place for a comment, so it's not a + # mistake to use it in earlier drafts in tests per se. + "$comment", + }, + "draft3": { + "$ref", + "$schema", + "additionalItems", + "additionalProperties", + "definitions", + "dependencies", + "description", + "disallow", + "divisibleBy", + "enum", + "exclusiveMaximum", + "exclusiveMinimum", + "extends", + "format", + "id", + "items", + "maxItems", + "maxLength", + "maximum", + "minItems", + "minLength", + "minimum", + "pattern", + "patternProperties", + "properties", + "title", + "type", + "uniqueItems", + + # Technically this is wrong, $comment doesn't exist in this + # draft, but the point of this test is to detect mistakes by, + # test authors, whereas the point of the $comment keyword is + # to just standardize a place for a comment, so it's not a + # mistake to use it in earlier drafts in tests per se. + "$comment", + }, } - missing = set(files).symmetric_difference(expected) - changed = { - path - for path, contents in expected.items() - if path in files - and contents != files[path] - } + def missing(d): + from collections.abc import Mapping - self.assertEqual( - files, - expected, - msg=textwrap.dedent( - """ - Remotes in the remotes/ directory do not match those in the - ``jsonschema_suite`` Python script. + class BlowUpForUnknownProperties(Mapping): + def __iter__(this): + return iter(d) - Unfortunately for the minute, each remote file is duplicated in - two places.""" + (""" + def __getitem__(this, k): + if k not in KNOWN[version.name]: + self.fail( + f"{k} is not a known keyword for {version.name}. " + "If this test is testing behavior related to " + "unknown keywords you may need to add it to the " + "allowlist in the jsonschema_suite checker. " + "Otherwise it may contain a typo!" + ) + return d[k] - Only present in one location: + def __len__(this): + return len(d) - {}""".format("\n".join(missing)) if missing else "") + (""" + return BlowUpForUnknownProperties() - Conflicting between the two: + for version, Validator in versions_and_validators(): + if version.name == "latest": + continue - {}""".format("\n".join(changed)) if changed else "") + self.addCleanup( + setattr, Validator, "VALIDATORS", Validator.VALIDATORS, ) - ) + Validator.VALIDATORS = missing(dict(Validator.VALIDATORS)) + + test_files = [ + each for each in collect(version) + if each.stem != "refOfUnknownKeyword" + ] + for case in cases(test_files): + if "unknown keyword" in case["description"]: + continue + with self.subTest(case=case, version=version.name): + try: + Validator(case["schema"]).is_valid(12) + except jsonschema.exceptions.RefResolutionError: + pass + + @unittest.skipIf(jsonschema is None, "Validation library not present!") + def test_suites_are_valid(self): + """ + All test files are valid under test-schema.json. + """ + Validator = jsonschema.validators.validator_for(TEST_SCHEMA) + validator = Validator(TEST_SCHEMA) + for path, cases in files(self.test_files): + with self.subTest(path=path): + try: + validator.validate(cases) + except jsonschema.ValidationError as error: + self.fail(str(error)) + + @unittest.skipIf(jsonschema is None, "Validation library not present!") + def test_output_suites_are_valid(self): + """ + All output test files are valid under output-test-schema.json. + """ + Validator = jsonschema.validators.validator_for(OUTPUT_TEST_SCHEMA) + validator = Validator(OUTPUT_TEST_SCHEMA) + for path, cases in files(self.output_test_files): + with self.subTest(path=path): + try: + validator.validate(cases) + except jsonschema.exceptions.RefResolutionError: + # python-jsonschema/jsonschema#884 + pass + except jsonschema.ValidationError as error: + self.fail(str(error)) def main(arguments): if arguments.command == "check": suite = unittest.TestLoader().loadTestsFromTestCase(SanityTests) - result = unittest.TextTestRunner(verbosity=2).run(suite) + result = unittest.TextTestRunner().run(suite) sys.exit(not result.wasSuccessful()) elif arguments.command == "flatten": selected_cases = [case for case in cases(collect(arguments.version))] @@ -197,36 +635,27 @@ def main(arguments): json.dump(selected_cases, sys.stdout, indent=4, sort_keys=True) elif arguments.command == "remotes": - json.dump(REMOTES, sys.stdout, indent=4, sort_keys=True) + remotes = { + url_for_path(path): json.loads(path.read_text()) + for path in collect(REMOTES_DIR) + } + json.dump(remotes, sys.stdout, indent=4, sort_keys=True) elif arguments.command == "dump_remotes": if arguments.update: shutil.rmtree(arguments.out_dir, ignore_errors=True) try: - os.makedirs(arguments.out_dir) - except OSError as e: - if e.errno == errno.EEXIST: - print("%s already exists. Aborting." % arguments.out_dir) - sys.exit(1) - raise - - for url, schema in REMOTES.items(): - filepath = os.path.join(arguments.out_dir, url) - - try: - os.makedirs(os.path.dirname(filepath)) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - with open(filepath, "w") as out_file: - json.dump(schema, out_file, indent=4, sort_keys=True) - out_file.write("\n") + shutil.copytree(REMOTES_DIR, arguments.out_dir) + except FileExistsError: + print(f"{arguments.out_dir} already exists. Aborting.") + sys.exit(1) elif arguments.command == "serve": try: - from flask import Flask, jsonify + import flask except ImportError: - print(textwrap.dedent(""" + print( + textwrap.dedent( + """ The Flask library is required to serve the remote schemas. You can install it by running `pip install Flask`. @@ -234,16 +663,18 @@ def main(arguments): Alternatively, see the `jsonschema_suite remotes` or `jsonschema_suite dump_remotes` commands to create static files that can be served with your own web server. - """.strip("\n"))) + """.strip( + "\n" + ) + ) + ) sys.exit(1) - app = Flask(__name__) + app = flask.Flask(__name__) @app.route("/") def serve_path(path): - if path in REMOTES: - return jsonify(REMOTES[path]) - return "Document does not exist.", 404 + return flask.send_from_directory(REMOTES_DIR, path) app.run(port=1234) @@ -251,13 +682,16 @@ def main(arguments): parser = argparse.ArgumentParser( description="JSON Schema Test Suite utilities", ) -subparsers = parser.add_subparsers(help="utility commands", dest="command") +subparsers = parser.add_subparsers( + help="utility commands", dest="command", metavar="COMMAND" +) +subparsers.required = True check = subparsers.add_parser("check", help="Sanity check the test suite.") flatten = subparsers.add_parser( "flatten", - help="Output a flattened file containing a selected version's test cases." + help="Output a flattened file containing a selected version's test cases.", ) flatten.add_argument( "--randomize", @@ -265,17 +699,19 @@ flatten.add_argument( help="Randomize the order of the outputted cases.", ) flatten.add_argument( - "version", help="The directory containing the version to output", + "version", + help="The directory containing the version to output", ) remotes = subparsers.add_parser( "remotes", help="Output the expected URLs and their associated schemas for remote " - "ref tests as a JSON object." + "ref tests as a JSON object.", ) dump_remotes = subparsers.add_parser( - "dump_remotes", help="Dump the remote ref schemas into a file tree", + "dump_remotes", + help="Dump the remote ref schemas into a file tree", ) dump_remotes.add_argument( "--update", @@ -291,7 +727,7 @@ dump_remotes.add_argument( serve = subparsers.add_parser( "serve", - help="Start a webserver to serve schemas used by remote ref tests." + help="Start a webserver to serve schemas used by remote ref tests.", ) if __name__ == "__main__": diff --git a/index.js b/index.js deleted file mode 100644 index b138226b..00000000 --- a/index.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -const Ajv = require('ajv'); -const jsonSchemaTest = require('json-schema-test'); -const assert = require('assert'); - -const refs = { - 'http://localhost:1234/integer.json': require('./remotes/integer.json'), - 'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'), - 'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'), - 'http://localhost:1234/name.json': require('./remotes/name.json'), - 'http://localhost:1234/name-defs.json': require('./remotes/name-defs.json') -}; - -const SKIP = { - 4: ['optional/zeroTerminatedFloats'], - 7: [ - 'format/idn-email', - 'format/idn-hostname', - 'format/iri', - 'format/iri-reference', - 'optional/content' - ] -}; - -[4, 6, 7].forEach((draft) => { - let ajv; - if (draft == 7) { - ajv = new Ajv({format: 'full'}); - } else { - const schemaId = draft == 4 ? 'id' : '$id'; - ajv = new Ajv({format: 'full', meta: false, schemaId}); - ajv.addMetaSchema(require(`ajv/lib/refs/json-schema-draft-0${draft}.json`)); - ajv._opts.defaultMeta = `http://json-schema.org/draft-0${draft}/schema#`; - } - for (const uri in refs) ajv.addSchema(refs[uri], uri); - - jsonSchemaTest(ajv, { - description: `Test suite draft-0${draft}`, - suites: {tests: `./tests/draft${draft}/{**/,}*.json`}, - skip: SKIP[draft], - cwd: __dirname, - hideFolder: 'tests/' - }); -}); diff --git a/output-test-schema.json b/output-test-schema.json new file mode 100644 index 00000000..02c51ef5 --- /dev/null +++ b/output-test-schema.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/output-test-schema", + "description": "A schema for files contained within this suite", + + "type": "array", + "minItems": 1, + "items": { + "description": "An individual test case, containing multiple tests of a single schema's behavior", + + "type": "object", + "required": [ "description", "schema", "tests" ], + "properties": { + "description": { + "description": "The test case description", + "type": "string" + }, + "comment": { + "description": "Any additional comments about the test case", + "type": "string" + }, + "schema": { + "description": "A valid JSON Schema (one written for the corresponding version directory that the file sits within)." + }, + "tests": { + "description": "A set of related tests all using the same schema", + "type": "array", + "items": { "$ref": "#/$defs/test" }, + "minItems": 1 + } + }, + "additionalProperties": false + }, + + "$defs": { + "test": { + "description": "A single output test", + + "type": "object", + "required": [ "description", "data", "output" ], + "properties": { + "description": { + "description": "The test description, briefly explaining which behavior it exercises", + "type": "string" + }, + "comment": { + "description": "Any additional comments about the test", + "type": "string" + }, + "data": { + "description": "The instance which should be validated against the schema in \"schema\"." + }, + "output": { + "description": "schemas that are used to verify output", + "type": "object", + "properties": { + "flag": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "basic": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "detailed": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "verbose": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "list": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "hierarchy": { "$ref": "https://json-schema.org/draft/2020-12/schema" } + }, + "minProperties": 1, + "additionalProperties": false + } + } + } + } +} diff --git a/output-tests/README.md b/output-tests/README.md new file mode 100644 index 00000000..d209bdb2 --- /dev/null +++ b/output-tests/README.md @@ -0,0 +1,63 @@ +These tests are intended to validate that implementations are correctly generating output in accordance with the specification. + +Output was initially specified with draft 2019-09. It remained largely unchanged for draft 2020-12, but will receive an update with the next release. + +_**NOTE** Although the formats didn't change much between 2019-09 and 2020-12, the tests are copied for 2020-12 because the `$schema` is different and implementations may (but shouldn't) produce different output._ + +## Organization + +The tests are organized by specification release and then into two categories: content and structure. + +Content tests verify that the keywords are producing the correct annotations and/or error messages. Since there are no requirements on the content of error messages, there's not much that can be verified for them, but it is possible to identify when a error message _could_ be present. Primarily, these tests need to extensively cover the annotation behaviors of each keyword. The only output format needed for these tests is `basic` for 2019-09/2020-12 and `list` for later versions. + +Structure tests verify that the structures of the various formats (i.e. `flag`, `basic`, `detailed`, `verbose` for 2019-09/2020-12 and `flag`, `list`, `hierarchical` for later versions) are correct. These tests don't need to cover each keyword; rather they need to sufficiently cover the various aspects of building the output structures by using whatever keywords are necessary to do so. + +In each release folder, you'll also find an _output-schema.json_ file that contains the schema from the specification repo that describes output for that release. This schema will need to be loaded as the tests reference it. + +## Test Files + +The content of a test file is similar to the validation tests in `tests/`: for each test case, the `valid` property has been removed, and an `output` property has been added. + +The `output` property itself has a property for each of the output formats where the value is a schema that will successfully validate for compliant output. For the content tests, only `basic`/`list` needs to be present. + +## Other notes + +### Ambiguity around 2020-09/2020-12 `basic` + +The 2019-09/2020-12 specs don't define the structure of `basic` very thoroughly. Specifically there is a nuance where if the list contains a single output node, there are two possible structures, given the text: + +- the output node for the root schema appears in the list with a containing node that just has a `valid` property + ```json + { + "valid": false, + "errors": [ + { + "valid": false, + "keywordLocation": "", + "absoluteKeywordLocation": "https://json-schema.org/tests/content/draft2019-09/general/0", + "instanceLocation": "" + } + ] + } + ``` +- the entire structure is collapsed to just the root output node as `detailed` would do. + ```json + { + "valid": false, + "keywordLocation": "", + "absoluteKeywordLocation": "https://json-schema.org/tests/content/draft2019-09/general/0", + "instanceLocation": "" + } + ``` +As the Test Suite should not prefer one interpretation over another, these cases need to be tested another way. + +A simple solution (though there are likely others) is to force a second output unit by adding an `"anyOf": [ true ]`. This has no impact on the validation result while adding superfluous structure to the output that avoids the above ambiguous scenario. The test schema should still be targeted on what's being tested and ignore any output units generated by this extra keyword. + +## Contributing + +Of course, first and foremost, follow the [Contributing guide](/CONTRIBUTING.md). + +When writing test cases, try to keep output validation schemas targeted to verify a single requirement. Where possible (and where it makes sense), create multiple tests to cover multiple requirements. This will help keep the output validation schemas small and increase readability. (It also increases your test count. ๐Ÿ˜‰) + +For the content tests, there is also a _general.json_ file that contains tests that do not necessarily pertain to any single keyword. + diff --git a/output-tests/draft-next/content/general.json b/output-tests/draft-next/content/general.json new file mode 100644 index 00000000..23fe1dae --- /dev/null +++ b/output-tests/draft-next/content/general.json @@ -0,0 +1,43 @@ +[ + { + "description": "failed validation produces no annotations", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://json-schema.org/tests/content/draft-next/general/0", + "type": "string", + "readOnly": true + }, + "tests": [ + { + "description": "dropped annotations MAY appear in droppedAnnotations", + "data": 1, + "output": { + "list": { + "$id": "https://json-schema.org/tests/content/draft-next/general/0/tests/0/basic", + "$ref": "/draft/next/output/schema", + "properties": { + "details": { + "contains": { + "properties": { + "evaluationPath": {"const": ""}, + "schemaLocation": {"const": "https://json-schema.org/tests/content/draft-next/general/0#"}, + "instanceLocation": {"const": ""}, + "annotations": false, + "droppedAnnotations": { + "properties": { + "readOnly": {"const": true} + }, + "required": ["readOnly"] + } + }, + "required": ["evaluationPath", "schemaLocation", "instanceLocation"] + } + } + }, + "required": ["details"] + } + } + } + ] + } +] diff --git a/output-tests/draft-next/content/readOnly.json b/output-tests/draft-next/content/readOnly.json new file mode 100644 index 00000000..8d1c2dec --- /dev/null +++ b/output-tests/draft-next/content/readOnly.json @@ -0,0 +1,41 @@ +[ + { + "description": "readOnly generates its value as an annotation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://json-schema.org/tests/content/draft-next/readOnly/0", + "readOnly": true + }, + "tests": [ + { + "description": "readOnly is true", + "data": 1, + "output": { + "list": { + "$id": "https://json-schema.org/tests/content/draft-next/readOnly/0/tests/0/basic", + "$ref": "/draft/next/output/schema", + "properties": { + "details": { + "contains": { + "properties": { + "evaluationPath": {"const": ""}, + "schemaLocation": {"const": "https://json-schema.org/tests/content/draft-next/readOnly/0#"}, + "instanceLocation": {"const": ""}, + "annotations": { + "properties": { + "readOnly": {"const": true} + }, + "required": ["readOnly"] + } + }, + "required": ["evaluationPath", "schemaLocation", "instanceLocation", "annotations"] + } + } + }, + "required": ["details"] + } + } + } + ] + } +] diff --git a/output-tests/draft-next/content/type.json b/output-tests/draft-next/content/type.json new file mode 100644 index 00000000..afc7f5fd --- /dev/null +++ b/output-tests/draft-next/content/type.json @@ -0,0 +1,39 @@ +[ + { + "description": "incorrect type", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://json-schema.org/tests/content/draft-next/type/0", + "type": "string" + }, + "tests": [ + { + "description": "incorrect type must be reported, but a message is not required", + "data": 1, + "output": { + "list": { + "$id": "https://json-schema.org/tests/content/draft-next/type/0/tests/0/basic", + "$ref": "/draft/next/output/schema", + "properties": { + "details": { + "contains": { + "properties": { + "evaluationPath": {"const": ""}, + "schemaLocation": {"const": "https://json-schema.org/tests/content/draft-next/type/0#"}, + "instanceLocation": {"const": ""}, + "annotations": false, + "errors": { + "required": ["type"] + } + }, + "required": ["evaluationPath", "schemaLocation", "instanceLocation"] + } + } + }, + "required": ["details"] + } + } + } + ] + } +] diff --git a/output-tests/draft-next/output-schema.json b/output-tests/draft-next/output-schema.json new file mode 100644 index 00000000..26286fa4 --- /dev/null +++ b/output-tests/draft-next/output-schema.json @@ -0,0 +1,95 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://json-schema.org/draft/next/output/schema", + "description": "A schema that validates the minimum requirements for validation output", + + "anyOf": [ + { "$ref": "#/$defs/flag" }, + { "$ref": "#/$defs/basic" }, + { "$ref": "#/$defs/hierarchical" } + ], + "$defs": { + "outputUnit":{ + "properties": { + "valid": { "type": "boolean" }, + "evaluationPath": { + "type": "string", + "format": "json-pointer" + }, + "schemaLocation": { + "type": "string", + "format": "uri" + }, + "instanceLocation": { + "type": "string", + "format": "json-pointer" + }, + "details": { + "$ref": "#/$defs/outputUnitArray" + }, + "annotations": { + "type": "object", + "additionalProperties": true + }, + "droppedAnnotations": { + "type": "object", + "additionalProperties": true + }, + "errors": { + "type": "object", + "additionalProperties": { "type": "string" } + } + }, + "required": [ "valid", "evaluationPath", "schemaLocation", "instanceLocation" ], + "allOf": [ + { + "if": { + "anyOf": [ + { + "required": [ "errors" ] + }, + { + "required": [ "droppedAnnotations" ] + } + ] + }, + "then": { + "properties": { + "valid": { "const": false } + } + } + }, + { + "if": { + "required": [ "annotations" ] + }, + "then": { + "properties": { + "valid": { "const": true } + } + } + } + ] + }, + "outputUnitArray": { + "type": "array", + "items": { "$ref": "#/$defs/outputUnit" } + }, + "flag": { + "properties": { + "valid": { "type": "boolean" } + }, + "required": [ "valid" ] + }, + "basic": { + "properties": { + "valid": { "type": "boolean" }, + "details": { + "$ref": "#/$defs/outputUnitArray" + } + }, + "required": [ "valid", "details" ] + }, + "hierarchical": { "$ref": "#/$defs/outputUnit" } + } +} diff --git a/output-tests/draft2019-09/content/escape.json b/output-tests/draft2019-09/content/escape.json new file mode 100644 index 00000000..d8cda154 --- /dev/null +++ b/output-tests/draft2019-09/content/escape.json @@ -0,0 +1,38 @@ +[ + { + "description": "tilde and forward slash in json-pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://json-schema.org/tests/content/draft2019-09/escape/0", + "properties": { + "~a/b": {"type": "number"} + } + }, + "tests": [ + { + "description": "incorrect type must be reported, but a message is not required", + "data": {"~a/b": "foobar"}, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2019-09/escape/0/tests/0/basic", + "$ref": "/draft/2019-09/output/schema", + "properties": { + "errors": { + "contains": { + "properties": { + "keywordLocation": {"const": "/properties/~0a~1b/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2019-09/escape/0#/properties/~0a~1b/type"}, + "instanceLocation": {"const": "/~0a~1b"}, + "annotation": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "required": ["errors"] + } + } + } + ] + } +] diff --git a/output-tests/draft2019-09/content/general.json b/output-tests/draft2019-09/content/general.json new file mode 100644 index 00000000..91941700 --- /dev/null +++ b/output-tests/draft2019-09/content/general.json @@ -0,0 +1,34 @@ +[ + { + "description": "failed validation produces no annotations", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://json-schema.org/tests/content/draft2019-09/general/0", + "type": "string", + "readOnly": true + }, + "tests": [ + { + "description": "readOnly annotation is dropped", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2019-09/general/0/tests/0/basic", + "$ref": "/draft/2019-09/output/schema", + "properties": { + "errors": { + "items": { + "properties": { + "annotation": false + } + } + }, + "annotations": false + }, + "required": ["errors"] + } + } + } + ] + } +] diff --git a/output-tests/draft2019-09/content/readOnly.json b/output-tests/draft2019-09/content/readOnly.json new file mode 100644 index 00000000..62db1a83 --- /dev/null +++ b/output-tests/draft2019-09/content/readOnly.json @@ -0,0 +1,38 @@ +[ + { + "description": "readOnly generates its value as an annotation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://json-schema.org/tests/content/draft2019-09/readOnly/0", + "readOnly": true + }, + "tests": [ + { + "description": "readOnly is true", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2019-09/readOnly/0/tests/0/basic", + "$ref": "/draft/2019-09/output/schema", + "properties": { + "annotations": { + "contains": { + "type": "object", + "properties": { + "keywordLocation": {"const": "/readOnly"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2019-09/readOnly/0#/readOnly"}, + "instanceLocation": {"const": ""}, + "annotation": {"const": true} + }, + "required": ["keywordLocation", "instanceLocation", "annotation"] + } + }, + "errors": false + }, + "required": ["annotations"] + } + } + } + ] + } +] diff --git a/output-tests/draft2019-09/content/type.json b/output-tests/draft2019-09/content/type.json new file mode 100644 index 00000000..cff77a74 --- /dev/null +++ b/output-tests/draft2019-09/content/type.json @@ -0,0 +1,63 @@ +[ + { + "description": "validating type", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://json-schema.org/tests/content/draft2019-09/type/0", + "type": "string", + "anyOf": [ true ] + }, + "tests": [ + { + "description": "incorrect type must be reported, but a message is not required", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2019-09/type/0/tests/0/basic", + "$ref": "/draft/2019-09/output/schema", + "properties": { + "errors": { + "contains": { + "properties": { + "keywordLocation": {"const": "/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2019-09/type/0#/type"}, + "instanceLocation": {"const": ""}, + "annotation": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "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/draft2019-09/output-schema.json b/output-tests/draft2019-09/output-schema.json new file mode 100644 index 00000000..ff523eea --- /dev/null +++ b/output-tests/draft2019-09/output-schema.json @@ -0,0 +1,96 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://json-schema.org/draft/2019-09/output/schema", + "description": "A schema that validates the minimum requirements for validation output", + + "anyOf": [ + { "$ref": "#/$defs/flag" }, + { "$ref": "#/$defs/basic" }, + { "$ref": "#/$defs/detailed" }, + { "$ref": "#/$defs/verbose" } + ], + "$defs": { + "outputUnit":{ + "properties": { + "valid": { "type": "boolean" }, + "keywordLocation": { + "type": "string", + "format": "json-pointer" + }, + "absoluteKeywordLocation": { + "type": "string", + "format": "uri" + }, + "instanceLocation": { + "type": "string", + "format": "json-pointer" + }, + "error": { + "type": "string" + }, + "errors": { + "$ref": "#/$defs/outputUnitArray" + }, + "annotations": { + "$ref": "#/$defs/outputUnitArray" + } + }, + "required": [ "valid", "keywordLocation", "instanceLocation" ], + "allOf": [ + { + "if": { + "properties": { + "valid": { "const": false } + } + }, + "then": { + "anyOf": [ + { + "required": [ "error" ] + }, + { + "required": [ "errors" ] + } + ] + } + }, + { + "if": { + "anyOf": [ + { + "properties": { + "keywordLocation": { + "pattern": "/\\$ref/" + } + } + }, + { + "properties": { + "keywordLocation": { + "pattern": "/\\$recursiveRef/" + } + } + } + ] + }, + "then": { + "required": [ "absoluteKeywordLocation" ] + } + } + ] + }, + "outputUnitArray": { + "type": "array", + "items": { "$ref": "#/$defs/outputUnit" } + }, + "flag": { + "properties": { + "valid": { "type": "boolean" } + }, + "required": [ "valid" ] + }, + "basic": { "$ref": "#/$defs/outputUnit" }, + "detailed": { "$ref": "#/$defs/outputUnit" }, + "verbose": { "$ref": "#/$defs/outputUnit" } + } +} diff --git a/output-tests/draft2020-12/content/escape.json b/output-tests/draft2020-12/content/escape.json new file mode 100644 index 00000000..c329c919 --- /dev/null +++ b/output-tests/draft2020-12/content/escape.json @@ -0,0 +1,38 @@ +[ + { + "description": "tilde and forward slash in json-pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/content/draft2020-12/escape/0", + "properties": { + "~a/b": {"type": "number"} + } + }, + "tests": [ + { + "description": "incorrect type must be reported, but a message is not required", + "data": {"~a/b": "foobar"}, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2020-12/escape/0/tests/0/basic", + "$ref": "/draft/2020-12/output/schema", + "properties": { + "errors": { + "contains": { + "properties": { + "keywordLocation": {"const": "/properties/~0a~1b/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2020-12/escape/0#/properties/~0a~1b/type"}, + "instanceLocation": {"const": "/~0a~1b"}, + "annotation": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "required": ["errors"] + } + } + } + ] + } +] diff --git a/output-tests/draft2020-12/content/general.json b/output-tests/draft2020-12/content/general.json new file mode 100644 index 00000000..1f2b370c --- /dev/null +++ b/output-tests/draft2020-12/content/general.json @@ -0,0 +1,34 @@ +[ + { + "description": "failed validation produces no annotations", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/content/draft2020-12/general/0", + "type": "string", + "readOnly": true + }, + "tests": [ + { + "description": "readOnly annotation is dropped", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2020-12/general/0/tests/0/basic", + "$ref": "/draft/2020-12/output/schema", + "properties": { + "errors": { + "items": { + "properties": { + "annotation": false + } + } + }, + "annotations": false + }, + "required": ["errors"] + } + } + } + ] + } +] diff --git a/output-tests/draft2020-12/content/readOnly.json b/output-tests/draft2020-12/content/readOnly.json new file mode 100644 index 00000000..9baf48de --- /dev/null +++ b/output-tests/draft2020-12/content/readOnly.json @@ -0,0 +1,37 @@ +[ + { + "description": "readOnly generates its value as an annotation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/content/draft2020-12/readOnly/0", + "readOnly": true + }, + "tests": [ + { + "description": "readOnly is true", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2020-12/readOnly/0/tests/0/basic", + "$ref": "/draft/2020-12/output/schema", + "properties": { + "annotations": { + "contains": { + "properties": { + "keywordLocation": {"const": "/readOnly"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2020-12/readOnly/0#/readOnly"}, + "instanceLocation": {"const": ""}, + "annotation": {"const": true} + }, + "required": ["keywordLocation", "instanceLocation", "annotation"] + } + }, + "errors": false + }, + "required": ["annotations"] + } + } + } + ] + } +] diff --git a/output-tests/draft2020-12/content/type.json b/output-tests/draft2020-12/content/type.json new file mode 100644 index 00000000..710475b2 --- /dev/null +++ b/output-tests/draft2020-12/content/type.json @@ -0,0 +1,63 @@ +[ + { + "description": "validating type", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/content/draft2020-12/type/0", + "type": "string", + "anyOf": [ true ] + }, + "tests": [ + { + "description": "incorrect type must be reported, but a message is not required", + "data": 1, + "output": { + "basic": { + "$id": "https://json-schema.org/tests/content/draft2020-12/type/0/tests/0/basic", + "$ref": "/draft/2020-12/output/schema", + "properties": { + "errors": { + "contains": { + "properties": { + "keywordLocation": {"const": "/type"}, + "absoluteKeywordLocation": {"const": "https://json-schema.org/tests/content/draft2020-12/type/0#/type"}, + "instanceLocation": {"const": ""}, + "annotation": false + }, + "required": ["keywordLocation", "instanceLocation"] + } + } + }, + "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/output-tests/draft2020-12/output-schema.json b/output-tests/draft2020-12/output-schema.json new file mode 100644 index 00000000..1eef288a --- /dev/null +++ b/output-tests/draft2020-12/output-schema.json @@ -0,0 +1,96 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/draft/2020-12/output/schema", + "description": "A schema that validates the minimum requirements for validation output", + + "anyOf": [ + { "$ref": "#/$defs/flag" }, + { "$ref": "#/$defs/basic" }, + { "$ref": "#/$defs/detailed" }, + { "$ref": "#/$defs/verbose" } + ], + "$defs": { + "outputUnit":{ + "properties": { + "valid": { "type": "boolean" }, + "keywordLocation": { + "type": "string", + "format": "json-pointer" + }, + "absoluteKeywordLocation": { + "type": "string", + "format": "uri" + }, + "instanceLocation": { + "type": "string", + "format": "json-pointer" + }, + "error": { + "type": "string" + }, + "errors": { + "$ref": "#/$defs/outputUnitArray" + }, + "annotations": { + "$ref": "#/$defs/outputUnitArray" + } + }, + "required": [ "valid", "keywordLocation", "instanceLocation" ], + "allOf": [ + { + "if": { + "properties": { + "valid": { "const": false } + } + }, + "then": { + "anyOf": [ + { + "required": [ "error" ] + }, + { + "required": [ "errors" ] + } + ] + } + }, + { + "if": { + "anyOf": [ + { + "properties": { + "keywordLocation": { + "pattern": "/\\$ref/" + } + } + }, + { + "properties": { + "keywordLocation": { + "pattern": "/\\$dynamicRef/" + } + } + } + ] + }, + "then": { + "required": [ "absoluteKeywordLocation" ] + } + } + ] + }, + "outputUnitArray": { + "type": "array", + "items": { "$ref": "#/$defs/outputUnit" } + }, + "flag": { + "properties": { + "valid": { "type": "boolean" } + }, + "required": [ "valid" ] + }, + "basic": { "$ref": "#/$defs/outputUnit" }, + "detailed": { "$ref": "#/$defs/outputUnit" }, + "verbose": { "$ref": "#/$defs/outputUnit" } + } +} diff --git a/package.json b/package.json index 3980136c..75da9e29 100644 --- a/package.json +++ b/package.json @@ -2,27 +2,11 @@ "name": "json-schema-test-suite", "version": "0.1.0", "description": "A language agnostic test suite for the JSON Schema specifications", - "main": "index.js", - "scripts": { - "test": "mocha index.js -R spec" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/json-schema-org/JSON-Schema-Test-Suite.git" - }, + "repository": "github:json-schema-org/JSON-Schema-Test-Suite", "keywords": [ "json-schema", "tests" ], "author": "http://json-schema.org", - "license": "MIT", - "bugs": { - "url": "https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues" - }, - "homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme", - "devDependencies": { - "ajv": "^6.0.0-rc.1", - "json-schema-test": "^2.0.0", - "mocha": "^3.2.0" - } + "license": "MIT" } diff --git a/remotes/folder/folderInteger.json b/remotes/baseUriChange/folderInteger.json similarity index 100% rename from remotes/folder/folderInteger.json rename to remotes/baseUriChange/folderInteger.json diff --git a/remotes/baseUriChangeFolder/folderInteger.json b/remotes/baseUriChangeFolder/folderInteger.json new file mode 100644 index 00000000..8b50ea30 --- /dev/null +++ b/remotes/baseUriChangeFolder/folderInteger.json @@ -0,0 +1,3 @@ +{ + "type": "integer" +} diff --git a/remotes/baseUriChangeFolderInSubschema/folderInteger.json b/remotes/baseUriChangeFolderInSubschema/folderInteger.json new file mode 100644 index 00000000..8b50ea30 --- /dev/null +++ b/remotes/baseUriChangeFolderInSubschema/folderInteger.json @@ -0,0 +1,3 @@ +{ + "type": "integer" +} diff --git a/remotes/different-id-ref-string.json b/remotes/different-id-ref-string.json new file mode 100644 index 00000000..7f888609 --- /dev/null +++ b/remotes/different-id-ref-string.json @@ -0,0 +1,5 @@ +{ + "$id": "http://localhost:1234/real-id-ref-string.json", + "$defs": {"bar": {"type": "string"}}, + "$ref": "#/$defs/bar" +} diff --git a/remotes/draft-next/baseUriChange/folderInteger.json b/remotes/draft-next/baseUriChange/folderInteger.json new file mode 100644 index 00000000..388c8810 --- /dev/null +++ b/remotes/draft-next/baseUriChange/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" +} diff --git a/remotes/draft-next/baseUriChangeFolder/folderInteger.json b/remotes/draft-next/baseUriChangeFolder/folderInteger.json new file mode 100644 index 00000000..388c8810 --- /dev/null +++ b/remotes/draft-next/baseUriChangeFolder/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" +} diff --git a/remotes/draft-next/baseUriChangeFolderInSubschema/folderInteger.json b/remotes/draft-next/baseUriChangeFolderInSubschema/folderInteger.json new file mode 100644 index 00000000..388c8810 --- /dev/null +++ b/remotes/draft-next/baseUriChangeFolderInSubschema/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" +} diff --git a/remotes/draft-next/extendible-dynamic-ref.json b/remotes/draft-next/extendible-dynamic-ref.json new file mode 100644 index 00000000..e787aa3d --- /dev/null +++ b/remotes/draft-next/extendible-dynamic-ref.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "description": "extendible array", + "$id": "http://localhost:1234/draft-next/extendible-dynamic-ref.json", + "type": "object", + "properties": { + "elements": { + "type": "array", + "items": { + "$dynamicRef": "#elements" + } + } + }, + "required": ["elements"], + "additionalProperties": false, + "$defs": { + "elements": { + "$dynamicAnchor": "elements" + } + } +} diff --git a/remotes/draft-next/format-assertion-false.json b/remotes/draft-next/format-assertion-false.json new file mode 100644 index 00000000..91c86699 --- /dev/null +++ b/remotes/draft-next/format-assertion-false.json @@ -0,0 +1,12 @@ +{ + "$id": "http://localhost:1234/draft-next/format-assertion-false.json", + "$schema": "https://json-schema.org/draft/next/schema", + "$vocabulary": { + "https://json-schema.org/draft/next/vocab/core": true, + "https://json-schema.org/draft/next/vocab/format-assertion": false + }, + "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 new file mode 100644 index 00000000..a33d1435 --- /dev/null +++ b/remotes/draft-next/format-assertion-true.json @@ -0,0 +1,12 @@ +{ + "$id": "http://localhost:1234/draft-next/format-assertion-true.json", + "$schema": "https://json-schema.org/draft/next/schema", + "$vocabulary": { + "https://json-schema.org/draft/next/vocab/core": true, + "https://json-schema.org/draft/next/vocab/format-assertion": true + }, + "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/integer.json b/remotes/draft-next/integer.json new file mode 100644 index 00000000..388c8810 --- /dev/null +++ b/remotes/draft-next/integer.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" +} diff --git a/remotes/draft-next/locationIndependentIdentifier.json b/remotes/draft-next/locationIndependentIdentifier.json new file mode 100644 index 00000000..17b4df51 --- /dev/null +++ b/remotes/draft-next/locationIndependentIdentifier.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$anchor": "foo", + "type": "integer" + } + } +} diff --git a/remotes/draft-next/metaschema-no-validation.json b/remotes/draft-next/metaschema-no-validation.json new file mode 100644 index 00000000..c19c9e8a --- /dev/null +++ b/remotes/draft-next/metaschema-no-validation.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/metaschema-no-validation.json", + "$vocabulary": { + "https://json-schema.org/draft/next/vocab/applicator": true, + "https://json-schema.org/draft/next/vocab/core": true + }, + "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 new file mode 100644 index 00000000..e78e531d --- /dev/null +++ b/remotes/draft-next/metaschema-optional-vocabulary.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/metaschema-optional-vocabulary.json", + "$vocabulary": { + "https://json-schema.org/draft/next/vocab/validation": true, + "https://json-schema.org/draft/next/vocab/core": true, + "http://localhost:1234/draft/next/vocab/custom": false + }, + "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/name-defs.json b/remotes/draft-next/name-defs.json new file mode 100644 index 00000000..cdb8c0c3 --- /dev/null +++ b/remotes/draft-next/name-defs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "orNull": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#" + } + ] + } + }, + "type": "string" +} diff --git a/remotes/draft-next/nested/foo-ref-string.json b/remotes/draft-next/nested/foo-ref-string.json new file mode 100644 index 00000000..50bf77f4 --- /dev/null +++ b/remotes/draft-next/nested/foo-ref-string.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": {"$ref": "string.json"} + } +} diff --git a/remotes/draft-next/nested/string.json b/remotes/draft-next/nested/string.json new file mode 100644 index 00000000..7462207e --- /dev/null +++ b/remotes/draft-next/nested/string.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string" +} diff --git a/remotes/draft-next/ref-and-defs.json b/remotes/draft-next/ref-and-defs.json new file mode 100644 index 00000000..46fafc9c --- /dev/null +++ b/remotes/draft-next/ref-and-defs.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/ref-and-defs.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" +} diff --git a/remotes/draft-next/subSchemas-defs.json b/remotes/draft-next/subSchemas-defs.json new file mode 100644 index 00000000..75b7583c --- /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 new file mode 100644 index 00000000..575dd00c --- /dev/null +++ b/remotes/draft-next/subSchemas.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" + } +} diff --git a/remotes/draft-next/tree.json b/remotes/draft-next/tree.json new file mode 100644 index 00000000..cad332ad --- /dev/null +++ b/remotes/draft-next/tree.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft/next/schema", + "description": "tree schema, extensible", + "$id": "http://localhost:1234/draft-next/tree.json", + "$dynamicAnchor": "node", + + "type": "object", + "properties": { + "data": true, + "children": { + "type": "array", + "items": { + "$dynamicRef": "#node" + } + } + } +} diff --git a/remotes/draft2019-09/baseUriChange/folderInteger.json b/remotes/draft2019-09/baseUriChange/folderInteger.json new file mode 100644 index 00000000..bf679e80 --- /dev/null +++ b/remotes/draft2019-09/baseUriChange/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" +} diff --git a/remotes/draft2019-09/baseUriChangeFolder/folderInteger.json b/remotes/draft2019-09/baseUriChangeFolder/folderInteger.json new file mode 100644 index 00000000..bf679e80 --- /dev/null +++ b/remotes/draft2019-09/baseUriChangeFolder/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" +} diff --git a/remotes/draft2019-09/baseUriChangeFolderInSubschema/folderInteger.json b/remotes/draft2019-09/baseUriChangeFolderInSubschema/folderInteger.json new file mode 100644 index 00000000..bf679e80 --- /dev/null +++ b/remotes/draft2019-09/baseUriChangeFolderInSubschema/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" +} diff --git a/remotes/draft2019-09/dependentRequired.json b/remotes/draft2019-09/dependentRequired.json new file mode 100644 index 00000000..0d691d96 --- /dev/null +++ b/remotes/draft2019-09/dependentRequired.json @@ -0,0 +1,7 @@ +{ + "$id": "http://localhost:1234/draft2019-09/dependentRequired.json", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "foo": ["bar"] + } +} diff --git a/remotes/draft2019-09/extendible-dynamic-ref.json b/remotes/draft2019-09/extendible-dynamic-ref.json new file mode 100644 index 00000000..c11bf0a0 --- /dev/null +++ b/remotes/draft2019-09/extendible-dynamic-ref.json @@ -0,0 +1,21 @@ +{ + "description": "extendible array", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/extendible-dynamic-ref.json", + "type": "object", + "properties": { + "elements": { + "type": "array", + "items": { + "$dynamicRef": "#elements" + } + } + }, + "required": ["elements"], + "additionalProperties": false, + "$defs": { + "elements": { + "$dynamicAnchor": "elements" + } + } +} diff --git a/remotes/draft2019-09/ignore-prefixItems.json b/remotes/draft2019-09/ignore-prefixItems.json new file mode 100644 index 00000000..b5ef3928 --- /dev/null +++ b/remotes/draft2019-09/ignore-prefixItems.json @@ -0,0 +1,7 @@ +{ + "$id": "http://localhost:1234/draft2019-09/ignore-prefixItems.json", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "prefixItems": [ + {"type": "string"} + ] +} diff --git a/remotes/draft2019-09/integer.json b/remotes/draft2019-09/integer.json new file mode 100644 index 00000000..bf679e80 --- /dev/null +++ b/remotes/draft2019-09/integer.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" +} diff --git a/remotes/draft2019-09/locationIndependentIdentifier.json b/remotes/draft2019-09/locationIndependentIdentifier.json new file mode 100644 index 00000000..a0fb9fbb --- /dev/null +++ b/remotes/draft2019-09/locationIndependentIdentifier.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$anchor": "foo", + "type": "integer" + } + } +} diff --git a/remotes/draft2019-09/metaschema-no-validation.json b/remotes/draft2019-09/metaschema-no-validation.json new file mode 100644 index 00000000..494f0abf --- /dev/null +++ b/remotes/draft2019-09/metaschema-no-validation.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/metaschema-no-validation.json", + "$vocabulary": { + "https://json-schema.org/draft/2019-09/vocab/applicator": true, + "https://json-schema.org/draft/2019-09/vocab/core": 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 new file mode 100644 index 00000000..968597c4 --- /dev/null +++ b/remotes/draft2019-09/metaschema-optional-vocabulary.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json", + "$vocabulary": { + "https://json-schema.org/draft/2019-09/vocab/validation": true, + "https://json-schema.org/draft/2019-09/vocab/core": true, + "http://localhost:1234/draft/2019-09/vocab/custom": false + }, + "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/name-defs.json b/remotes/draft2019-09/name-defs.json new file mode 100644 index 00000000..8892f16f --- /dev/null +++ b/remotes/draft2019-09/name-defs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "orNull": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#" + } + ] + } + }, + "type": "string" +} diff --git a/remotes/draft2019-09/nested/foo-ref-string.json b/remotes/draft2019-09/nested/foo-ref-string.json new file mode 100644 index 00000000..fe10748c --- /dev/null +++ b/remotes/draft2019-09/nested/foo-ref-string.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": {"$ref": "string.json"} + } +} diff --git a/remotes/draft2019-09/nested/string.json b/remotes/draft2019-09/nested/string.json new file mode 100644 index 00000000..242f7132 --- /dev/null +++ b/remotes/draft2019-09/nested/string.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string" +} diff --git a/remotes/draft2019-09/ref-and-defs.json b/remotes/draft2019-09/ref-and-defs.json new file mode 100644 index 00000000..0ad690dd --- /dev/null +++ b/remotes/draft2019-09/ref-and-defs.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/ref-and-defs.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" +} diff --git a/remotes/draft2019-09/subSchemas-defs.json b/remotes/draft2019-09/subSchemas-defs.json new file mode 100644 index 00000000..fdfee68d --- /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 new file mode 100644 index 00000000..6dea2252 --- /dev/null +++ b/remotes/draft2019-09/subSchemas.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" + } +} diff --git a/remotes/draft2019-09/tree.json b/remotes/draft2019-09/tree.json new file mode 100644 index 00000000..fce79412 --- /dev/null +++ b/remotes/draft2019-09/tree.json @@ -0,0 +1,17 @@ +{ + "description": "tree schema, extensible", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/tree.json", + "$dynamicAnchor": "node", + + "type": "object", + "properties": { + "data": true, + "children": { + "type": "array", + "items": { + "$dynamicRef": "#node" + } + } + } +} diff --git a/remotes/draft2020-12/baseUriChange/folderInteger.json b/remotes/draft2020-12/baseUriChange/folderInteger.json new file mode 100644 index 00000000..1f44a631 --- /dev/null +++ b/remotes/draft2020-12/baseUriChange/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" +} diff --git a/remotes/draft2020-12/baseUriChangeFolder/folderInteger.json b/remotes/draft2020-12/baseUriChangeFolder/folderInteger.json new file mode 100644 index 00000000..1f44a631 --- /dev/null +++ b/remotes/draft2020-12/baseUriChangeFolder/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" +} diff --git a/remotes/draft2020-12/baseUriChangeFolderInSubschema/folderInteger.json b/remotes/draft2020-12/baseUriChangeFolderInSubschema/folderInteger.json new file mode 100644 index 00000000..1f44a631 --- /dev/null +++ b/remotes/draft2020-12/baseUriChangeFolderInSubschema/folderInteger.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" +} diff --git a/remotes/draft2020-12/extendible-dynamic-ref.json b/remotes/draft2020-12/extendible-dynamic-ref.json new file mode 100644 index 00000000..65bc0c21 --- /dev/null +++ b/remotes/draft2020-12/extendible-dynamic-ref.json @@ -0,0 +1,21 @@ +{ + "description": "extendible array", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/extendible-dynamic-ref.json", + "type": "object", + "properties": { + "elements": { + "type": "array", + "items": { + "$dynamicRef": "#elements" + } + } + }, + "required": ["elements"], + "additionalProperties": false, + "$defs": { + "elements": { + "$dynamicAnchor": "elements" + } + } +} diff --git a/remotes/draft2020-12/format-assertion-false.json b/remotes/draft2020-12/format-assertion-false.json new file mode 100644 index 00000000..d6dd645b --- /dev/null +++ b/remotes/draft2020-12/format-assertion-false.json @@ -0,0 +1,12 @@ +{ + "$id": "http://localhost:1234/draft2020-12/format-assertion-false.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$vocabulary": { + "https://json-schema.org/draft/2020-12/vocab/core": true, + "https://json-schema.org/draft/2020-12/vocab/format-assertion": false + }, + "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 new file mode 100644 index 00000000..bb16d586 --- /dev/null +++ b/remotes/draft2020-12/format-assertion-true.json @@ -0,0 +1,12 @@ +{ + "$id": "http://localhost:1234/draft2020-12/format-assertion-true.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$vocabulary": { + "https://json-schema.org/draft/2020-12/vocab/core": true, + "https://json-schema.org/draft/2020-12/vocab/format-assertion": true + }, + "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/integer.json b/remotes/draft2020-12/integer.json new file mode 100644 index 00000000..1f44a631 --- /dev/null +++ b/remotes/draft2020-12/integer.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" +} diff --git a/remotes/draft2020-12/locationIndependentIdentifier.json b/remotes/draft2020-12/locationIndependentIdentifier.json new file mode 100644 index 00000000..6565a1ee --- /dev/null +++ b/remotes/draft2020-12/locationIndependentIdentifier.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$anchor": "foo", + "type": "integer" + } + } +} diff --git a/remotes/draft2020-12/metaschema-no-validation.json b/remotes/draft2020-12/metaschema-no-validation.json new file mode 100644 index 00000000..85d74b21 --- /dev/null +++ b/remotes/draft2020-12/metaschema-no-validation.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/metaschema-no-validation.json", + "$vocabulary": { + "https://json-schema.org/draft/2020-12/vocab/applicator": true, + "https://json-schema.org/draft/2020-12/vocab/core": true + }, + "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 new file mode 100644 index 00000000..f38ec281 --- /dev/null +++ b/remotes/draft2020-12/metaschema-optional-vocabulary.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/metaschema-optional-vocabulary.json", + "$vocabulary": { + "https://json-schema.org/draft/2020-12/vocab/validation": true, + "https://json-schema.org/draft/2020-12/vocab/core": true, + "http://localhost:1234/draft/2020-12/vocab/custom": false + }, + "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/name-defs.json b/remotes/draft2020-12/name-defs.json new file mode 100644 index 00000000..67bc33c5 --- /dev/null +++ b/remotes/draft2020-12/name-defs.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "orNull": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#" + } + ] + } + }, + "type": "string" +} diff --git a/remotes/draft2020-12/nested/foo-ref-string.json b/remotes/draft2020-12/nested/foo-ref-string.json new file mode 100644 index 00000000..29661ff9 --- /dev/null +++ b/remotes/draft2020-12/nested/foo-ref-string.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": {"$ref": "string.json"} + } +} diff --git a/remotes/draft2020-12/nested/string.json b/remotes/draft2020-12/nested/string.json new file mode 100644 index 00000000..6607ac53 --- /dev/null +++ b/remotes/draft2020-12/nested/string.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" +} diff --git a/remotes/draft2020-12/prefixItems.json b/remotes/draft2020-12/prefixItems.json new file mode 100644 index 00000000..acd8293c --- /dev/null +++ b/remotes/draft2020-12/prefixItems.json @@ -0,0 +1,7 @@ +{ + "$id": "http://localhost:1234/draft2020-12/prefixItems.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + {"type": "string"} + ] +} diff --git a/remotes/draft2020-12/ref-and-defs.json b/remotes/draft2020-12/ref-and-defs.json new file mode 100644 index 00000000..16d30fa3 --- /dev/null +++ b/remotes/draft2020-12/ref-and-defs.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/ref-and-defs.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" +} diff --git a/remotes/draft2020-12/subSchemas-defs.json b/remotes/draft2020-12/subSchemas-defs.json new file mode 100644 index 00000000..1bb4846d --- /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 new file mode 100644 index 00000000..5fca21d8 --- /dev/null +++ b/remotes/draft2020-12/subSchemas.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/integer" + } +} diff --git a/remotes/draft2020-12/tree.json b/remotes/draft2020-12/tree.json new file mode 100644 index 00000000..b07555fb --- /dev/null +++ b/remotes/draft2020-12/tree.json @@ -0,0 +1,17 @@ +{ + "description": "tree schema, extensible", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/tree.json", + "$dynamicAnchor": "node", + + "type": "object", + "properties": { + "data": true, + "children": { + "type": "array", + "items": { + "$dynamicRef": "#node" + } + } + } +} diff --git a/remotes/draft7/ignore-dependentRequired.json b/remotes/draft7/ignore-dependentRequired.json new file mode 100644 index 00000000..0ea927b5 --- /dev/null +++ b/remotes/draft7/ignore-dependentRequired.json @@ -0,0 +1,7 @@ +{ + "$id": "http://localhost:1234/draft7/integer.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "dependentRequired": { + "foo": ["bar"] + } +} \ No newline at end of file diff --git a/remotes/extendible-dynamic-ref.json b/remotes/extendible-dynamic-ref.json new file mode 100644 index 00000000..d0bcd37d --- /dev/null +++ b/remotes/extendible-dynamic-ref.json @@ -0,0 +1,20 @@ +{ + "description": "extendible array", + "$id": "http://localhost:1234/extendible-dynamic-ref.json", + "type": "object", + "properties": { + "elements": { + "type": "array", + "items": { + "$dynamicRef": "#elements" + } + } + }, + "required": ["elements"], + "additionalProperties": false, + "$defs": { + "elements": { + "$dynamicAnchor": "elements" + } + } +} diff --git a/remotes/locationIndependentIdentifier.json b/remotes/locationIndependentIdentifier.json new file mode 100644 index 00000000..96b17c3f --- /dev/null +++ b/remotes/locationIndependentIdentifier.json @@ -0,0 +1,11 @@ +{ + "$defs": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$anchor": "foo", + "type": "integer" + } + } +} diff --git a/remotes/locationIndependentIdentifierDraft4.json b/remotes/locationIndependentIdentifierDraft4.json new file mode 100644 index 00000000..eeff1eb2 --- /dev/null +++ b/remotes/locationIndependentIdentifierDraft4.json @@ -0,0 +1,11 @@ +{ + "definitions": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "id": "#foo", + "type": "integer" + } + } +} diff --git a/remotes/locationIndependentIdentifierPre2019.json b/remotes/locationIndependentIdentifierPre2019.json new file mode 100644 index 00000000..e72815cd --- /dev/null +++ b/remotes/locationIndependentIdentifierPre2019.json @@ -0,0 +1,11 @@ +{ + "definitions": { + "refToInteger": { + "$ref": "#foo" + }, + "A": { + "$id": "#foo", + "type": "integer" + } + } +} diff --git a/remotes/nested-absolute-ref-to-string.json b/remotes/nested-absolute-ref-to-string.json new file mode 100644 index 00000000..f46c7616 --- /dev/null +++ b/remotes/nested-absolute-ref-to-string.json @@ -0,0 +1,9 @@ +{ + "$defs": { + "bar": { + "$id": "http://localhost:1234/the-nested-id.json", + "type": "string" + } + }, + "$ref": "http://localhost:1234/the-nested-id.json" +} diff --git a/remotes/nested/foo-ref-string.json b/remotes/nested/foo-ref-string.json new file mode 100644 index 00000000..9cd2527e --- /dev/null +++ b/remotes/nested/foo-ref-string.json @@ -0,0 +1,6 @@ +{ + "type": "object", + "properties": { + "foo": {"$ref": "string.json"} + } +} diff --git a/remotes/nested/string.json b/remotes/nested/string.json new file mode 100644 index 00000000..c2d48c06 --- /dev/null +++ b/remotes/nested/string.json @@ -0,0 +1,3 @@ +{ + "type": "string" +} diff --git a/remotes/ref-and-definitions.json b/remotes/ref-and-definitions.json new file mode 100644 index 00000000..e0ee802a --- /dev/null +++ b/remotes/ref-and-definitions.json @@ -0,0 +1,11 @@ +{ + "$id": "http://localhost:1234/ref-and-definitions.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] +} diff --git a/remotes/ref-and-defs.json b/remotes/ref-and-defs.json new file mode 100644 index 00000000..85d06c39 --- /dev/null +++ b/remotes/ref-and-defs.json @@ -0,0 +1,11 @@ +{ + "$id": "http://localhost:1234/ref-and-defs.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" +} diff --git a/remotes/subSchemas-defs.json b/remotes/subSchemas-defs.json new file mode 100644 index 00000000..50b7b6dc --- /dev/null +++ b/remotes/subSchemas-defs.json @@ -0,0 +1,10 @@ +{ + "$defs": { + "integer": { + "type": "integer" + }, + "refToInteger": { + "$ref": "#/$defs/integer" + } + } +} diff --git a/remotes/tree.json b/remotes/tree.json new file mode 100644 index 00000000..a12d98b0 --- /dev/null +++ b/remotes/tree.json @@ -0,0 +1,16 @@ +{ + "description": "tree schema, extensible", + "$id": "http://localhost:1234/tree.json", + "$dynamicAnchor": "node", + + "type": "object", + "properties": { + "data": true, + "children": { + "type": "array", + "items": { + "$dynamicRef": "#node" + } + } + } +} diff --git a/remotes/urn-ref-string.json b/remotes/urn-ref-string.json new file mode 100644 index 00000000..aca2211b --- /dev/null +++ b/remotes/urn-ref-string.json @@ -0,0 +1,5 @@ +{ + "$id": "urn:uuid:feebdaed-ffff-0000-ffff-0000deadbeef", + "$defs": {"bar": {"type": "string"}}, + "$ref": "#/$defs/bar" +} diff --git a/test-schema.json b/test-schema.json index 670d2804..83393162 100644 --- a/test-schema.json +++ b/test-schema.json @@ -1,59 +1,61 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "outputItem": { - "type": "object", - "properties": { - "valid": {"type": "boolean"}, - "keywordLocation": {"type": "string"}, - "absoluteKeywordLocation": { - "type": "string", - "format": "uri" - }, - "instanceLocation": {"type": "string"}, - "annotations": { - "type": "array", - "items": {"$ref": "#/definitions/outputItem"} - }, - "errors": { - "type": "array", - "items": {"$ref": "#/definitions/outputItem"} - } - } - } - }, + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://json-schema.org/tests/test-schema", + "description": "A schema for files contained within this suite", + "type": "array", + "minItems": 1, "items": { + "description": "An individual test case, containing multiple tests of a single schema's behavior", + "type": "object", - "required": ["description", "schema", "tests"], + "required": [ "description", "schema", "tests" ], "properties": { - "description": {"type": "string"}, - "schema": {}, + "description": { + "description": "The test case description", + "type": "string" + }, + "comment": { + "description": "Any additional comments about the test case", + "type": "string" + }, + "schema": { + "description": "A valid JSON Schema (one written for the corresponding version directory that the file sits within)." + }, "tests": { + "description": "A set of related tests all using the same schema", "type": "array", - "items": { - "type": "object", - "required": ["description", "data", "valid"], - "properties": { - "description": {"type": "string"}, - "data": {}, - "valid": {"type": "boolean"}, - "output": { - "type": "object", - "properties": { - "basic": {"$ref": "#/definitions/outputItem"}, - "detailed": {"$ref": "#/definitions/outputItem"}, - "verbose": {"$ref": "#/definitions/outputItem"} - }, - "required": ["basic", "detailed", "verbose"] - } - }, - "additionalProperties": false - }, + "items": { "$ref": "#/$defs/test" }, "minItems": 1 } }, - "additionalProperties": false, - "minItems": 1 + "additionalProperties": false + }, + + "$defs": { + "test": { + "description": "A single test", + + "type": "object", + "required": [ "description", "data", "valid" ], + "properties": { + "description": { + "description": "The test description, briefly explaining which behavior it exercises", + "type": "string" + }, + "comment": { + "description": "Any additional comments about the test", + "type": "string" + }, + "data": { + "description": "The instance which should be validated against the schema in \"schema\"." + }, + "valid": { + "description": "Whether the validation process of this instance should consider the instance valid or not", + "type": "boolean" + } + }, + "additionalProperties": false + } } } diff --git a/tests/draft-next/additionalProperties.json b/tests/draft-next/additionalProperties.json new file mode 100644 index 00000000..7859fbbf --- /dev/null +++ b/tests/draft-next/additionalProperties.json @@ -0,0 +1,156 @@ +[ + { + "description": + "additionalProperties being false does not allow other properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo": {}, "bar": {}}, + "patternProperties": { "^v": {} }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": {"foo":1, "vroom": 2}, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": {"^รก": {}}, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": {"รกrmรกnyos": 2}, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": {"รฉlmรฉny": 2}, + "valid": false + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo": {}, "bar": {}}, + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": {"foo" : 1, "bar" : 2, "quux" : true}, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : 12}, + "valid": false + } + ] + }, + { + "description": + "additionalProperties can exist by itself", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": {"foo" : true}, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": {"foo" : 1}, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo": {}, "bar": {}} + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": {"foo": 1, "bar": 2, "quux": true}, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + {"properties": {"foo": {}}} + ], + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": {"foo": 1, "bar": true}, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/allOf.json b/tests/draft-next/allOf.json new file mode 100644 index 00000000..86745da2 --- /dev/null +++ b/tests/draft-next/allOf.json @@ -0,0 +1,312 @@ +[ + { + "description": "allOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": {"foo": "baz", "bar": 2}, + "valid": true + }, + { + "description": "mismatch second", + "data": {"foo": "baz"}, + "valid": false + }, + { + "description": "mismatch first", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "wrong type", + "data": {"foo": "baz", "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"bar": {"type": "integer"}}, + "required": ["bar"], + "allOf" : [ + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + }, + { + "properties": { + "baz": {"type": "null"} + }, + "required": ["baz"] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": {"foo": "quux", "bar": 2, "baz": null}, + "valid": true + }, + { + "description": "mismatch base schema", + "data": {"foo": "quux", "baz": null}, + "valid": false + }, + { + "description": "mismatch first allOf", + "data": {"bar": 2, "baz": null}, + "valid": false + }, + { + "description": "mismatch second allOf", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "mismatch both", + "data": {"bar": 2}, + "valid": false + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + {"maximum": 30}, + {"minimum": 20} + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [true, true] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [true, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + {}, + { "type": "number" } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json new file mode 100644 index 00000000..321d8446 --- /dev/null +++ b/tests/draft-next/anchor.json @@ -0,0 +1,234 @@ +[ + { + "description": "Location-independent identifier", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "#foo", + "$defs": { + "A": { + "$anchor": "foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with absolute URI", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/draft-next/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft-next/bar", + "$anchor": "foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/root", + "$ref": "http://localhost:1234/draft-next/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$anchor": "foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/foobar", + "$defs": { + "A": { + "$id": "child1", + "allOf": [ + { + "$id": "child2", + "$anchor": "my_anchor", + "type": "number" + }, + { + "$anchor": "my_anchor", + "type": "string" + } + ] + } + }, + "$ref": "child1#my_anchor" + }, + "tests": [ + { + "description": "$ref resolves to /$defs/A/allOf/1", + "data": "a", + "valid": true + }, + { + "description": "$ref does not resolve to /$defs/A/allOf/0", + "data": 1, + "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/anyOf.json b/tests/draft-next/anyOf.json new file mode 100644 index 00000000..a97267c8 --- /dev/null +++ b/tests/draft-next/anyOf.json @@ -0,0 +1,203 @@ +[ + { + "description": "anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "anyOf" : [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [true, true] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [true, false] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": {"foo": "baz"}, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": {"foo": "baz", "bar": 2}, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/boolean_schema.json b/tests/draft-next/boolean_schema.json new file mode 100644 index 00000000..6d40f23f --- /dev/null +++ b/tests/draft-next/boolean_schema.json @@ -0,0 +1,104 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "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": "boolean schema 'false'", + "schema": false, + "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 + } + ] + } +] diff --git a/tests/draft-next/const.json b/tests/draft-next/const.json new file mode 100644 index 00000000..61fbd839 --- /dev/null +++ b/tests/draft-next/const.json @@ -0,0 +1,387 @@ +[ + { + "description": "const validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": {"foo": "bar", "baz": "bax"} + }, + "tests": [ + { + "description": "same object is valid", + "data": {"foo": "bar", "baz": "bax"}, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": {"baz": "bax", "foo": "bar"}, + "valid": true + }, + { + "description": "another object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "another type is invalid", + "data": [1, 2], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": [{ "foo": "bar" }] + }, + "tests": [ + { + "description": "same array is valid", + "data": [{"foo": "bar"}], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [2], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [1, 2, 3], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": [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": "const with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": [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": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": {"a": false} + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": {"a": true} + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/contains.json b/tests/draft-next/contains.json new file mode 100644 index 00000000..c17f55ee --- /dev/null +++ b/tests/draft-next/contains.json @@ -0,0 +1,267 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "minimum": 5 } + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [3, 4, 5], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [3, 4, 6], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [3, 4, 5, 6], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [2, 3, 4], + "valid": false + }, + { + "description": "empty array is invalid", + "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, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 5 } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [3, 4, 5], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [3, 4, 5, 5], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "any non-empty object is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "non-arrays/objects are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "additionalProperties": { "multipleOf": 2 }, + "items": { "multipleOf": 2 }, + "contains": { "multipleOf": 3 } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [2, 4, 8], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [3, 6, 9], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [6, 12], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { + "if": false, + "else": true + } + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft-next/content.json b/tests/draft-next/content.json new file mode 100644 index 00000000..37e1f095 --- /dev/null +++ b/tests/draft-next/content.json @@ -0,0 +1,131 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document; validates true", + "data": "{:}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character); validates true", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents with schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64", + "contentSchema": { "type": "object", "required": ["foo"], "properties": { "foo": { "type": "string" } } } + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "another valid base64-encoded JSON document", + "data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==", + "valid": true + }, + { + "description": "an invalid base64-encoded JSON document; validates true", + "data": "eyJib28iOiAyMH0=", + "valid": true + }, + { + "description": "an empty object as a base64-encoded JSON document; validates true", + "data": "e30=", + "valid": true + }, + { + "description": "an empty array as a base64-encoded JSON document", + "data": "W10=", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/default.json b/tests/draft-next/default.json new file mode 100644 index 00000000..689b68e6 --- /dev/null +++ b/tests/draft-next/default.json @@ -0,0 +1,82 @@ +[ + { + "description": "invalid type for default", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": {"foo": 13}, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": {"bar": "good"}, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/defs.json b/tests/draft-next/defs.json new file mode 100644 index 00000000..7bda8257 --- /dev/null +++ b/tests/draft-next/defs.json @@ -0,0 +1,21 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "valid definition schema", + "data": {"$defs": {"foo": {"type": "integer"}}}, + "valid": true + }, + { + "description": "invalid definition schema", + "data": {"$defs": {"foo": {"type": 1}}}, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/dependentRequired.json b/tests/draft-next/dependentRequired.json new file mode 100644 index 00000000..23447242 --- /dev/null +++ b/tests/draft-next/dependentRequired.json @@ -0,0 +1,152 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentRequired": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentRequired": {"bar": []} + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentRequired": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentRequired": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/dependentSchemas.json b/tests/draft-next/dependentSchemas.json new file mode 100644 index 00000000..8a847759 --- /dev/null +++ b/tests/draft-next/dependentSchemas.json @@ -0,0 +1,170 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentSchemas": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentSchemas": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependentSchemas": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/dynamicRef.json b/tests/draft-next/dynamicRef.json new file mode 100644 index 00000000..a4a7c449 --- /dev/null +++ b/tests/draft-next/dynamicRef.json @@ -0,0 +1,568 @@ +[ + { + "description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $ref to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root", + "type": "array", + "items": { "$ref": "#items" }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/typical-dynamic-resolution/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" } + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root", + "$ref": "intermediate-scope", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "intermediate-scope": { + "$id": "intermediate-scope", + "$ref": "list" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" } + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root", + "$ref": "list", + "$defs": { + "foo": { + "$anchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$dynamicAnchor": "items" + } + } + } + } + }, + "tests": [ + { + "description": "Any array is valid", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor resolves to the first $dynamicAnchor in the dynamic scope", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/relative-dynamic-reference/root", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "foo": { "const": "pass" } + }, + "$ref": "extended", + "$defs": { + "extended": { + "$id": "extended", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "bar": { "$ref": "bar" } + } + }, + "bar": { + "$id": "bar", + "type": "object", + "properties": { + "baz": { "$dynamicRef": "extended#meta" } + } + } + } + }, + "tests": [ + { + "description": "The recursive part is valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { "foo": "pass" } + } + }, + "valid": true + }, + { + "description": "The recursive part is not valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { "foo": "fail" } + } + }, + "valid": false + } + ] + }, + { + "description": "multiple dynamic paths to the $dynamicRef keyword", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", + "$defs": { + "inner": { + "$id": "inner", + "$dynamicAnchor": "foo", + "title": "inner", + "additionalProperties": { + "$dynamicRef": "#foo" + } + } + }, + "if": { + "propertyNames": { + "pattern": "^[a-m]" + } + }, + "then": { + "title": "any type of node", + "$id": "anyLeafNode", + "$dynamicAnchor": "foo", + "$ref": "inner" + }, + "else": { + "title": "integer node", + "$id": "integerNode", + "$dynamicAnchor": "foo", + "type": [ "object", "integer" ], + "$ref": "inner" + } + }, + "tests": [ + { + "description": "recurse to anyLeafNode - floats are allowed", + "data": { "alpha": 1.1 }, + "valid": true + }, + { + "description": "recurse to integerNode - floats are not allowed", + "data": { "november": 1.1 }, + "valid": false + } + ] + }, + { + "description": "after leaving a dynamic scope, it is not used by a $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main", + "if": { + "$id": "first_scope", + "$defs": { + "thingy": { + "$comment": "this is first_scope#thingy", + "$dynamicAnchor": "thingy", + "type": "number" + } + } + }, + "then": { + "$id": "second_scope", + "$ref": "start", + "$defs": { + "thingy": { + "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef", + "$dynamicAnchor": "thingy", + "type": "null" + } + } + }, + "$defs": { + "start": { + "$comment": "this is the landing spot from $ref", + "$id": "start", + "$dynamicRef": "inner_scope#thingy" + }, + "thingy": { + "$comment": "this is the first stop for the $dynamicRef", + "$id": "inner_scope", + "$dynamicAnchor": "thingy", + "type": "string" + } + } + }, + "tests": [ + { + "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here", + "data": "a string", + "valid": false + }, + { + "description": "first_scope is not in dynamic scope for the $dynamicRef", + "data": 42, + "valid": false + }, + { + "description": "/then/$defs/thingy is the final stop for the $dynamicRef", + "data": null, + "valid": true + } + ] + }, + { + "description": "strict-tree schema, guards against misspelled properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/strict-tree.json", + "$dynamicAnchor": "node", + + "$ref": "tree.json", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "instance with misspelled field", + "data": { + "children": [{ + "daat": 1 + }] + }, + "valid": false + }, + { + "description": "instance with correct field", + "data": { + "children": [{ + "data": 1 + }] + }, + "valid": true + } + ] + }, + { + "description": "tests for implementation dynamic anchor and reference link", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/strict-extendible.json", + "$ref": "extendible-dynamic-ref.json", + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $defs first", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/strict-extendible-allof-defs-first.json", + "allOf": [ + { + "$ref": "extendible-dynamic-ref.json" + }, + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + } + ] + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $ref first", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/strict-extendible-allof-ref-first.json", + "allOf": [ + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + }, + { + "$ref": "extendible-dynamic-ref.json" + } + ] + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + }, + { + "description": "$dynamicAnchor inside propertyDependencies", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/dynamicanchor-in-propertydependencies.json", + "$defs": { + "inner": { + "$id": "inner", + "$dynamicAnchor": "foo", + "type": "object", + "properties": { + "expectedTypes": { + "type": "string" + } + }, + "additionalProperties": { + "$dynamicRef": "#foo" + } + } + }, + "propertyDependencies": { + "expectedTypes": { + "strings": { + "$id": "east", + "$ref": "inner", + "$defs": { + "foo": { + "$dynamicAnchor": "foo", + "type": "string" + } + } + }, + "integers": { + "$id": "west", + "$ref": "inner", + "$defs": { + "foo": { + "$dynamicAnchor": "foo", + "type": "integer" + } + } + } + } + } + }, + "tests": [ + { + "description": "expected strings - additional property as string is valid", + "data": { + "expectedTypes": "strings", + "anotherProperty": "also a string" + }, + "valid": true + }, + { + "description": "expected strings - additional property as not string is invalid", + "data": { + "expectedTypes": "strings", + "anotherProperty": 42 + }, + "valid": false + }, + { + "description": "expected integers - additional property as integer is valid", + "data": { + "expectedTypes": "integers", + "anotherProperty": 42 + }, + "valid": true + }, + { + "description": "expected integers - additional property as not integer is invalid", + "data": { + "expectedTypes": "integers", + "anotherProperty": "a string" + }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/enum.json b/tests/draft-next/enum.json new file mode 100644 index 00000000..32e5af01 --- /dev/null +++ b/tests/draft-next/enum.json @@ -0,0 +1,262 @@ +[ + { + "description": "simple enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [1, 2, 3] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [6, "foo", [], true, {"foo": 12}] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": {"foo": false}, + "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [6, null] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type":"object", + "properties": { + "foo": {"enum":["foo"]}, + "bar": {"enum":["bar"]} + }, + "required": ["bar"] + }, + "tests": [ + { + "description": "both properties are valid", + "data": {"foo":"foo", "bar":"bar"}, + "valid": true + }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": {"bar":"bar"}, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": {"foo":"foo"}, + "valid": false + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": ["foo\nbar", "foo\rbar"] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "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": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "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": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "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": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true + } + ] + }, + { + "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": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "enum": [ "hello\u0000there" ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/exclusiveMaximum.json b/tests/draft-next/exclusiveMaximum.json new file mode 100644 index 00000000..6ec4752d --- /dev/null +++ b/tests/draft-next/exclusiveMaximum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/exclusiveMinimum.json b/tests/draft-next/exclusiveMinimum.json new file mode 100644 index 00000000..90262987 --- /dev/null +++ b/tests/draft-next/exclusiveMinimum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/format.json b/tests/draft-next/format.json new file mode 100644 index 00000000..ec6c7f1d --- /dev/null +++ b/tests/draft-next/format.json @@ -0,0 +1,838 @@ +[ + { + "description": "email format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid email string is only an annotation by default", + "data": "2962", + "valid": true + } + ] + }, + { + "description": "idn-email format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "idn-email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid idn-email string is only an annotation by default", + "data": "2962", + "valid": true + } + ] + }, + { + "description": "regex format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "regex" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid regex string is only an annotation by default", + "data": "^(abc]", + "valid": true + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "ipv4" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid ipv4 string is only an annotation by default", + "data": "127.0.0.0.1", + "valid": true + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "ipv6" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid ipv6 string is only an annotation by default", + "data": "12345::", + "valid": true + } + ] + }, + { + "description": "idn-hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid idn-hostname string is only an annotation by default", + "data": "ใ€ฎ์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + } + ] + }, + { + "description": "hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid hostname string is only an annotation by default", + "data": "-a-host-name-that-starts-with--", + "valid": true + } + ] + }, + { + "description": "date format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "date" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid date string is only an annotation by default", + "data": "06/19/1963", + "valid": true + } + ] + }, + { + "description": "date-time format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "date-time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid date-time string is only an annotation by default", + "data": "1990-02-31T15:59:60.123-08:00", + "valid": true + } + ] + }, + { + "description": "time format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid time string is only an annotation by default", + "data": "08:30:06 PST", + "valid": true + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid json-pointer string is only an annotation by default", + "data": "/foo/bar~", + "valid": true + } + ] + }, + { + "description": "relative-json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "relative-json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid relative-json-pointer string is only an annotation by default", + "data": "/foo/bar", + "valid": true + } + ] + }, + { + "description": "iri format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "iri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid iri string is only an annotation by default", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": true + } + ] + }, + { + "description": "iri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "iri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid iri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": true + } + ] + }, + { + "description": "uri format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri string is only an annotation by default", + "data": "//foo.bar/?baz=qux#quux", + "valid": true + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\fileshare", + "valid": true + } + ] + }, + { + "description": "uri-template format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri-template" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri-template string is only an annotation by default", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": true + } + ] + }, + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uuid string is only an annotation by default", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": true + } + ] + }, + { + "description": "duration format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid duration string is only an annotation by default", + "data": "PT1D", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/id.json b/tests/draft-next/id.json new file mode 100644 index 00000000..9b3a591f --- /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/if-then-else.json b/tests/draft-next/if-then-else.json new file mode 100644 index 00000000..70576c42 --- /dev/null +++ b/tests/draft-next/if-then-else.json @@ -0,0 +1,268 @@ +[ + { + "description": "ignore if without then or else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone if", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone if", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "ignore then without if", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "then": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone then", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone then", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "ignore else without if", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "else": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone else", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone else", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "if and then without else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + } + }, + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true + }, + { + "description": "invalid through then", + "data": -100, + "valid": false + }, + { + "description": "valid when if test fails", + "data": 3, + "valid": true + } + ] + }, + { + "description": "if and else without then", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "exclusiveMaximum": 0 + }, + "else": { + "multipleOf": 2 + } + }, + "tests": [ + { + "description": "valid when if test passes", + "data": -1, + "valid": true + }, + { + "description": "valid through else", + "data": 4, + "valid": true + }, + { + "description": "invalid through else", + "data": 3, + "valid": false + } + ] + }, + { + "description": "validate against correct branch, then vs else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + }, + "else": { + "multipleOf": 2 + } + }, + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true + }, + { + "description": "invalid through then", + "data": -100, + "valid": false + }, + { + "description": "valid through else", + "data": 4, + "valid": true + }, + { + "description": "invalid through else", + "data": 3, + "valid": false + } + ] + }, + { + "description": "non-interference across combined schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "if": { + "exclusiveMaximum": 0 + } + }, + { + "then": { + "minimum": -10 + } + }, + { + "else": { + "multipleOf": 2 + } + } + ] + }, + "tests": [ + { + "description": "valid, but would have been invalid through then", + "data": -100, + "valid": true + }, + { + "description": "valid, but would have been invalid through else", + "data": 3, + "valid": true + } + ] + }, + { + "description": "if with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": true, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": false, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/infinite-loop-detection.json b/tests/draft-next/infinite-loop-detection.json new file mode 100644 index 00000000..fa66743b --- /dev/null +++ b/tests/draft-next/infinite-loop-detection.json @@ -0,0 +1,37 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/items.json b/tests/draft-next/items.json new file mode 100644 index 00000000..459943be --- /dev/null +++ b/tests/draft-next/items.json @@ -0,0 +1,284 @@ +[ + { + "description": "a schema given for items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": {"type": "integer"} + }, + "tests": [ + { + "description": "valid items", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [1, "x"], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": {"foo" : "bar"}, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": true + }, + "tests": [ + { + "description": "any array is valid", + "data": [ 1, "foo", true ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ 1, "foo", true ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "items and subitems", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "item": { + "type": "array", + "items": false, + "prefixItems": [ + { "$ref": "#/$defs/sub-item" }, + { "$ref": "#/$defs/sub-item" } + ] + }, + "sub-item": { + "type": "object", + "required": ["foo"] + } + }, + "type": "array", + "items": false, + "prefixItems": [ + { "$ref": "#/$defs/item" }, + { "$ref": "#/$defs/item" }, + { "$ref": "#/$defs/item" } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ {"foo": null}, {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + {"foo": null}, + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ {}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "fewer items is valid", + "data": [ + [ {"foo": null} ], + [ {"foo": null} ] + ], + "valid": true + } + ] + }, + { + "description": "nested items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": false + }, + { + "description": "not deep enough", + "data": [[[1], [2],[3]], [[4], [5], [6]]], + "valid": false + } + ] + }, + { + "description": "prefixItems with no additional items allowed", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{}, {}, {}], + "items": false + }, + "tests": [ + { + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "equal number of items present", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ 1, 2, 3, 4 ], + "valid": false + } + ] + }, + { + "description": "items does not look in applicators, valid case", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { "prefixItems": [ { "minimum": 3 } ] } + ], + "items": { "minimum": 5 } + }, + "tests": [ + { + "description": "prefixItems in allOf does not constrain items, invalid case", + "data": [ 3, 5 ], + "valid": false + }, + { + "description": "prefixItems in allOf does not constrain items, valid case", + "data": [ 5, 5 ], + "valid": true + } + ] + }, + { + "description": "prefixItems validation adjusts the starting index for items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ { "type": "string" } ], + "items": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft-next/maxContains.json b/tests/draft-next/maxContains.json new file mode 100644 index 00000000..7c151575 --- /dev/null +++ b/tests/draft-next/maxContains.json @@ -0,0 +1,152 @@ +[ + { + "description": "maxContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone maxContains", + "data": [1], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "maxContains with contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty array", + "data": [], + "valid": false + }, + { + "description": "all elements match, valid maxContains", + "data": [1], + "valid": true + }, + { + "description": "all elements match, invalid maxContains", + "data": [1, 1], + "valid": false + }, + { + "description": "some elements match, valid maxContains", + "data": [1, 2], + "valid": true + }, + { + "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 + } + ] + }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, + { + "description": "minContains < maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "minContains": 1, + "maxContains": 3 + }, + "tests": [ + { + "description": "array with actual < minContains < maxContains", + "data": [], + "valid": false + }, + { + "description": "array with minContains < actual < maxContains", + "data": [1, 1], + "valid": true + }, + { + "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/maxItems.json b/tests/draft-next/maxItems.json new file mode 100644 index 00000000..b215850f --- /dev/null +++ b/tests/draft-next/maxItems.json @@ -0,0 +1,50 @@ +[ + { + "description": "maxItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxItems": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] + } +] diff --git a/tests/draft-next/maxLength.json b/tests/draft-next/maxLength.json new file mode 100644 index 00000000..e09e44ad --- /dev/null +++ b/tests/draft-next/maxLength.json @@ -0,0 +1,55 @@ +[ + { + "description": "maxLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two supplementary Unicode code points is long enough", + "data": "\uD83D\uDCA9\uD83D\uDCA9", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/maxProperties.json b/tests/draft-next/maxProperties.json new file mode 100644 index 00000000..5eec9dad --- /dev/null +++ b/tests/draft-next/maxProperties.json @@ -0,0 +1,79 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxProperties": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/maximum.json b/tests/draft-next/maximum.json new file mode 100644 index 00000000..656ce817 --- /dev/null +++ b/tests/draft-next/maximum.json @@ -0,0 +1,60 @@ +[ + { + "description": "maximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/minContains.json b/tests/draft-next/minContains.json new file mode 100644 index 00000000..a6ad212d --- /dev/null +++ b/tests/draft-next/minContains.json @@ -0,0 +1,224 @@ +[ + { + "description": "minContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone minContains", + "data": [1], + "valid": true + }, + { + "description": "zero items still valid against lone minContains", + "data": [], + "valid": true + } + ] + }, + { + "description": "minContains=1 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "minContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "no elements match", + "data": [2], + "valid": false + }, + { + "description": "single element matches, valid minContains", + "data": [1], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [1, 2], + "valid": true + }, + { + "description": "all elements match, valid minContains", + "data": [1, 1], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [1], + "valid": false + }, + { + "description": "some elements match, invalid minContains", + "data": [1, 2], + "valid": false + }, + { + "description": "all elements match, valid minContains (exactly as needed)", + "data": [1, 1], + "valid": true + }, + { + "description": "all elements match, valid minContains (more than needed)", + "data": [1, 1, 1], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [1, 2, 1], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "maxContains = minContains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "maxContains": 2, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [1], + "valid": false + }, + { + "description": "all elements match, invalid maxContains", + "data": [1, 1, 1], + "valid": false + }, + { + "description": "all elements match, valid maxContains and minContains", + "data": [1, 1], + "valid": true + } + ] + }, + { + "description": "maxContains < minContains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "maxContains": 1, + "minContains": 3 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "invalid minContains", + "data": [1], + "valid": false + }, + { + "description": "invalid maxContains", + "data": [1, 1, 1], + "valid": false + }, + { + "description": "invalid maxContains and minContains", + "data": [1, 1], + "valid": false + } + ] + }, + { + "description": "minContains = 0", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": { "const": 1 }, + "minContains": 0 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": true + }, + { + "description": "minContains = 0 makes contains always pass", + "data": [2], + "valid": true + } + ] + }, + { + "description": "minContains = 0 with maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "contains": {"const": 1}, + "minContains": 0, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": true + }, + { + "description": "not more than maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many", + "data": [ 1, 1 ], + "valid": false + } + ] + } +] diff --git a/tests/draft-next/minItems.json b/tests/draft-next/minItems.json new file mode 100644 index 00000000..b0e1c721 --- /dev/null +++ b/tests/draft-next/minItems.json @@ -0,0 +1,50 @@ +[ + { + "description": "minItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minItems": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] + } +] diff --git a/tests/draft-next/minLength.json b/tests/draft-next/minLength.json new file mode 100644 index 00000000..16022acb --- /dev/null +++ b/tests/draft-next/minLength.json @@ -0,0 +1,55 @@ +[ + { + "description": "minLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one supplementary Unicode code point is not long enough", + "data": "\uD83D\uDCA9", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/minProperties.json b/tests/draft-next/minProperties.json new file mode 100644 index 00000000..434c0f1f --- /dev/null +++ b/tests/draft-next/minProperties.json @@ -0,0 +1,60 @@ +[ + { + "description": "minProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minProperties": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minProperties": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/minimum.json b/tests/draft-next/minimum.json new file mode 100644 index 00000000..2c6f71f6 --- /dev/null +++ b/tests/draft-next/minimum.json @@ -0,0 +1,75 @@ +[ + { + "description": "minimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/multipleOf.json b/tests/draft-next/multipleOf.json new file mode 100644 index 00000000..f1534545 --- /dev/null +++ b/tests/draft-next/multipleOf.json @@ -0,0 +1,98 @@ +[ + { + "description": "by int", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer", "multipleOf": 1e-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/not.json b/tests/draft-next/not.json new file mode 100644 index 00000000..b2251043 --- /dev/null +++ b/tests/draft-next/not.json @@ -0,0 +1,153 @@ +[ + { + "description": "not", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": {"type": "integer"} + }, + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true + }, + { + "description": "disallowed", + "data": 1, + "valid": false + } + ] + }, + { + "description": "not multiple types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": {"type": ["integer", "boolean"]} + }, + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true + }, + { + "description": "mismatch", + "data": 1, + "valid": false + }, + { + "description": "other mismatch", + "data": true, + "valid": false + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "tests": [ + { + "description": "match", + "data": 1, + "valid": true + }, + { + "description": "other match", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "mismatch", + "data": {"foo": "bar"}, + "valid": false + } + ] + }, + { + "description": "forbidden property", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": { + "not": {} + } + } + }, + "tests": [ + { + "description": "property present", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "property absent", + "data": {"bar": 1, "baz": 2}, + "valid": true + } + ] + }, + { + "description": "not with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": true + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "not with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": false + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "collect annotations inside a 'not', even if collection is disabled", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "not": { + "$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them", + "anyOf": [ + true, + { "properties": { "foo": true } } + ], + "unevaluatedProperties": false + } + }, + "tests": [ + { + "description": "unevaluated property", + "data": { "bar": 1 }, + "valid": true + }, + { + "description": "annotations are still collected inside a 'not'", + "data": { "foo": 1 }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/oneOf.json b/tests/draft-next/oneOf.json new file mode 100644 index 00000000..e8c07713 --- /dev/null +++ b/tests/draft-next/oneOf.json @@ -0,0 +1,293 @@ +[ + { + "description": "oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "oneOf" : [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [true, true, true] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [true, false, false] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [true, true, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [false, false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": {"foo": "baz"}, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": {"foo": "baz", "bar": 2}, + "valid": false + }, + { + "description": "neither oneOf valid (complex)", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "oneOf": [ + { "required": ["foo", "bar"] }, + { "required": ["foo", "baz"] } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "first valid - valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "second valid - valid", + "data": {"foo": 1, "baz": 3}, + "valid": true + }, + { + "description": "both valid - invalid", + "data": {"foo": 1, "bar": 2, "baz" : 3}, + "valid": false + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": ["bar"] + }, + { + "properties": { + "foo": true + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/bignum.json b/tests/draft-next/optional/bignum.json new file mode 100644 index 00000000..9f4f7079 --- /dev/null +++ b/tests/draft-next/optional/bignum.json @@ -0,0 +1,110 @@ +[ + { + "description": "integer", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/dependencies.json b/tests/draft-next/optional/dependencies-compatibility.json similarity index 77% rename from tests/draft2019-09/dependencies.json rename to tests/draft-next/optional/dependencies-compatibility.json index 8dd78aa5..1fe384ca 100644 --- a/tests/draft2019-09/dependencies.json +++ b/tests/draft-next/optional/dependencies-compatibility.json @@ -1,7 +1,8 @@ [ { - "description": "dependencies", + "description": "single dependency", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": {"bar": ["foo"]} }, "tests": [ @@ -43,8 +44,9 @@ ] }, { - "description": "dependencies with empty array", + "description": "empty dependents", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": {"bar": []} }, "tests": [ @@ -57,12 +59,18 @@ "description": "object with one property", "data": {"bar": 2}, "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true } ] }, { - "description": "multiple dependencies", + "description": "multiple dependents required", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": {"quux": ["foo", "bar"]} }, "tests": [ @@ -99,8 +107,52 @@ ] }, { - "description": "multiple dependencies subschema", + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": { "bar": { "properties": { @@ -135,12 +187,28 @@ "description": "wrong type both", "data": {"foo": "quux", "bar": "quux"}, "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, { - "description": "dependencies with boolean subschemas", + "description": "boolean subschemas", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": { "foo": true, "bar": false @@ -170,53 +238,17 @@ ] }, { - "description": "empty array of dependencies", + "description": "schema dependencies with escaped characters", "schema": { + "$schema": "https://json-schema.org/draft/next/schema", "dependencies": { - "foo": [] + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} } }, "tests": [ { - "description": "object with property is valid", - "data": { "foo": 1 }, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "non-object is valid", - "data": 1, - "valid": true - } - ] - }, - { - "description": "dependencies with escaped characters", - "schema": { - "dependencies": { - "foo\nbar": ["foo\rbar"], - "foo\tbar": { - "minProperties": 4 - }, - "foo'bar": {"required": ["foo\"bar"]}, - "foo\"bar": ["foo'bar"] - } - }, - "tests": [ - { - "description": "valid object 1", - "data": { - "foo\nbar": 1, - "foo\rbar": 2 - }, - "valid": true - }, - { - "description": "valid object 2", + "description": "quoted tab", "data": { "foo\tbar": 1, "a": 2, @@ -226,23 +258,14 @@ "valid": true }, { - "description": "valid object 3", - "data": { - "foo'bar": 1, - "foo\"bar": 2 - }, - "valid": true - }, - { - "description": "invalid object 1", + "description": "quoted quote", "data": { - "foo\nbar": 1, - "foo": 2 + "foo'bar": {"foo\"bar": 1} }, "valid": false }, { - "description": "invalid object 2", + "description": "quoted tab invalid under dependent schema", "data": { "foo\tbar": 1, "a": 2 @@ -250,17 +273,8 @@ "valid": false }, { - "description": "invalid object 3", - "data": { - "foo'bar": 1 - }, - "valid": false - }, - { - "description": "invalid object 4", - "data": { - "foo\"bar": 2 - }, + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, "valid": false } ] diff --git a/tests/draft-next/optional/ecmascript-regex.json b/tests/draft-next/optional/ecmascript-regex.json new file mode 100644 index 00000000..27211450 --- /dev/null +++ b/tests/draft-next/optional/ecmascript-regex.json @@ -0,0 +1,596 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\u0009", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\cC$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false + }, + { + "description": "matches", + "data": "\u0003", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\cc$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false + }, + { + "description": "matches", + "data": "\u0003", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "฿€", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "\u07c0", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "฿€", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "\u07c0", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "รฉ", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "รฉ", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "\\p{Letter}cole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "^\\p{digit}+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/optional/float-overflow.json b/tests/draft-next/optional/float-overflow.json new file mode 100644 index 00000000..a4fcca67 --- /dev/null +++ b/tests/draft-next/optional/float-overflow.json @@ -0,0 +1,17 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/optional/format-assertion.json b/tests/draft-next/optional/format-assertion.json new file mode 100644 index 00000000..ede922a2 --- /dev/null +++ b/tests/draft-next/optional/format-assertion.json @@ -0,0 +1,42 @@ +[ + { + "description": "schema that uses custom metaschema with format-assertion: false", + "schema": { + "$id": "https://schema/using/format-assertion/false", + "$schema": "http://localhost:1234/draft-next/format-assertion-false.json", + "format": "ipv4" + }, + "tests": [ + { + "description": "format-assertion: false: valid string", + "data": "127.0.0.1", + "valid": true + }, + { + "description": "format-assertion: false: invalid string", + "data": "not-an-ipv4", + "valid": false + } + ] + }, + { + "description": "schema that uses custom metaschema with format-assertion: true", + "schema": { + "$id": "https://schema/using/format-assertion/true", + "$schema": "http://localhost:1234/draft-next/format-assertion-true.json", + "format": "ipv4" + }, + "tests": [ + { + "description": "format-assertion: true: valid string", + "data": "127.0.0.1", + "valid": true + }, + { + "description": "format-assertion: true: invalid string", + "data": "not-an-ipv4", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/date-time.json b/tests/draft-next/optional/format/date-time.json new file mode 100644 index 00000000..e25845b0 --- /dev/null +++ b/tests/draft-next/optional/format/date-time.json @@ -0,0 +1,136 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "date-time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/date.json b/tests/draft-next/optional/format/date.json new file mode 100644 index 00000000..aa55555c --- /dev/null +++ b/tests/draft-next/optional/format/date.json @@ -0,0 +1,246 @@ +[ + { + "description": "validation of date strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "date" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1963-06-1เงช", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/duration.json b/tests/draft-next/optional/format/duration.json new file mode 100644 index 00000000..d5adca20 --- /dev/null +++ b/tests/draft-next/optional/format/duration.json @@ -0,0 +1,136 @@ +[ + { + "description": "validation of duration strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid duration string", + "data": "P4DT12H30M5S", + "valid": true + }, + { + "description": "an invalid duration string", + "data": "PT1D", + "valid": false + }, + { + "description": "no elements present", + "data": "P", + "valid": false + }, + { + "description": "no time elements present", + "data": "P1YT", + "valid": false + }, + { + "description": "no date or time elements present", + "data": "PT", + "valid": false + }, + { + "description": "elements out of order", + "data": "P2D1Y", + "valid": false + }, + { + "description": "missing time separator", + "data": "P1D2H", + "valid": false + }, + { + "description": "time element in the date position", + "data": "P2S", + "valid": false + }, + { + "description": "four years duration", + "data": "P4Y", + "valid": true + }, + { + "description": "zero time, in seconds", + "data": "PT0S", + "valid": true + }, + { + "description": "zero time, in days", + "data": "P0D", + "valid": true + }, + { + "description": "one month duration", + "data": "P1M", + "valid": true + }, + { + "description": "one minute duration", + "data": "PT1M", + "valid": true + }, + { + "description": "one and a half days, in hours", + "data": "PT36H", + "valid": true + }, + { + "description": "one and a half days, in days and hours", + "data": "P1DT12H", + "valid": true + }, + { + "description": "two weeks", + "data": "P2W", + "valid": true + }, + { + "description": "weeks cannot be combined with other units", + "data": "P1Y2W", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "PเงจY", + "valid": false + }, + { + "description": "element without unit", + "data": "P1", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/email.json b/tests/draft-next/optional/format/email.json new file mode 100644 index 00000000..5948ebd1 --- /dev/null +++ b/tests/draft-next/optional/format/email.json @@ -0,0 +1,121 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "a quoted string with a space in the local part is valid", + "data": "\"joe bloggs\"@example.com", + "valid": true + }, + { + "description": "a quoted string with a double dot in the local part is valid", + "data": "\"joe..bloggs\"@example.com", + "valid": true + }, + { + "description": "a quoted string with a @ in the local part is valid", + "data": "\"joe@bloggs\"@example.com", + "valid": true + }, + { + "description": "an IPv4-address-literal after the @ is valid", + "data": "joe.bloggs@[127.0.0.1]", + "valid": true + }, + { + "description": "an IPv6-address-literal after the @ is valid", + "data": "joe.bloggs@[IPv6:::1]", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false + }, + { + "description": "an invalid domain", + "data": "joe.bloggs@invalid=domain.com", + "valid": false + }, + { + "description": "an invalid IPv4-address-literal", + "data": "joe.bloggs@[127.0.0.300]", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/hostname.json b/tests/draft-next/optional/format/hostname.json new file mode 100644 index 00000000..96784865 --- /dev/null +++ b/tests/draft-next/optional/format/hostname.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of host names", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/idn-email.json b/tests/draft-next/optional/format/idn-email.json new file mode 100644 index 00000000..1f353670 --- /dev/null +++ b/tests/draft-next/optional/format/idn-email.json @@ -0,0 +1,61 @@ +[ + { + "description": "validation of an internationalized e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "idn-email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid idn e-mail (example@example.test in Hangul)", + "data": "์‹ค๋ก€@์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + }, + { + "description": "an invalid idn e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/idn-hostname.json b/tests/draft-next/optional/format/idn-hostname.json new file mode 100644 index 00000000..ee2e792f --- /dev/null +++ b/tests/draft-next/optional/format/idn-hostname.json @@ -0,0 +1,307 @@ +[ + { + "description": "validation of internationalized host names", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name (example.test in Hangul)", + "data": "์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + }, + { + "description": "illegal first char U+302E Hangul single dot tone mark", + "data": "ใ€ฎ์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "contains illegal char U+302E Hangul single dot tone mark", + "data": "์‹คใ€ฎ๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-> $1.00 <--", + "valid": false + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0903hello", + "valid": false + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0300hello", + "valid": false + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0488hello", + "valid": false + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u00df\u03c2\u0f0b\u3007", + "valid": true + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u06fd\u06fe", + "valid": true + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u0640\u07fa", + "valid": false + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b", + "valid": false + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7a", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7", + "valid": false + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7l", + "valid": true + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375S", + "valid": false + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375", + "valid": false + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375\u03b2", + "valid": true + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05d0\u05f3\u05d1", + "valid": true + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05d0\u05f4\u05d1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def\u30fbabc", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u3041", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u30a1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u4e08", + "valid": true + }, + { + "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", + "valid": false + }, + { + "description": "Arabic-Indic digits not 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\u0628", + "valid": true + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "\u06f00", + "valid": true + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u094d\u200d\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "\u0915\u094d\u200c\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "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 + } + ] + } +] diff --git a/tests/draft-next/optional/format/ipv4.json b/tests/draft-next/optional/format/ipv4.json new file mode 100644 index 00000000..e3e94401 --- /dev/null +++ b/tests/draft-next/optional/format/ipv4.json @@ -0,0 +1,87 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "ipv4" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/ipv6.json b/tests/draft-next/optional/format/ipv6.json new file mode 100644 index 00000000..241df7f3 --- /dev/null +++ b/tests/draft-next/optional/format/ipv6.json @@ -0,0 +1,211 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "ipv6" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/iri-reference.json b/tests/draft-next/optional/format/iri-reference.json new file mode 100644 index 00000000..543b99e7 --- /dev/null +++ b/tests/draft-next/optional/format/iri-reference.json @@ -0,0 +1,76 @@ +[ + { + "description": "validation of IRI References", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "iri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IRI", + "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid protocol-relative IRI Reference", + "data": "//ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid relative IRI Reference", + "data": "/รขฯ€ฯ€", + "valid": true + }, + { + "description": "an invalid IRI Reference", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": false + }, + { + "description": "a valid IRI Reference", + "data": "รขฯ€ฯ€", + "valid": true + }, + { + "description": "a valid IRI fragment", + "data": "#ฦ’rรคgmรชnt", + "valid": true + }, + { + "description": "an invalid IRI fragment", + "data": "#ฦ’rรคg\\mรชnt", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/iri.json b/tests/draft-next/optional/format/iri.json new file mode 100644 index 00000000..48e82a28 --- /dev/null +++ b/tests/draft-next/optional/format/iri.json @@ -0,0 +1,86 @@ +[ + { + "description": "validation of IRIs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "iri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IRI with anchor tag", + "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid IRI with anchor tag and parentheses", + "data": "http://ฦ’รธรธ.com/blah_(wรฎkรฏpรฉdiรฅ)_blah#รŸitรฉ-1", + "valid": true + }, + { + "description": "a valid IRI with URL-encoded stuff", + "data": "http://ฦ’รธรธ.รŸรฅr/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid IRI with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid IRI based on IPv6", + "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", + "valid": true + }, + { + "description": "an invalid IRI based on IPv6", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": false + }, + { + "description": "an invalid relative IRI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid IRI", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": false + }, + { + "description": "an invalid IRI though valid IRI reference", + "data": "รขฯ€ฯ€", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/json-pointer.json b/tests/draft-next/optional/format/json-pointer.json new file mode 100644 index 00000000..f55342f1 --- /dev/null +++ b/tests/draft-next/optional/format/json-pointer.json @@ -0,0 +1,201 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/regex.json b/tests/draft-next/optional/format/regex.json new file mode 100644 index 00000000..5987f534 --- /dev/null +++ b/tests/draft-next/optional/format/regex.json @@ -0,0 +1,51 @@ +[ + { + "description": "validation of regular expressions", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "regex" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/relative-json-pointer.json b/tests/draft-next/optional/format/relative-json-pointer.json new file mode 100644 index 00000000..1e28fc29 --- /dev/null +++ b/tests/draft-next/optional/format/relative-json-pointer.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of Relative JSON Pointers (RJP)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "relative-json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid upwards RJP", + "data": "1", + "valid": true + }, + { + "description": "a valid downwards RJP", + "data": "0/foo/bar", + "valid": true + }, + { + "description": "a valid up and then down RJP, with array index", + "data": "2/0/baz/1/zip", + "valid": true + }, + { + "description": "a valid RJP taking the member or index name", + "data": "0#", + "valid": true + }, + { + "description": "an invalid RJP that is a valid JSON Pointer", + "data": "/foo/bar", + "valid": false + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/optional/format/time.json b/tests/draft-next/optional/format/time.json new file mode 100644 index 00000000..0a000a48 --- /dev/null +++ b/tests/draft-next/optional/format/time.json @@ -0,0 +1,236 @@ +[ + { + "description": "validation of time strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid time string", + "data": "08:30:06Z", + "valid": true + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true + }, + { + "description": "a valid time string with precise second fraction", + "data": "08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false + }, + { + "description": "an invalid offset indicator", + "data": "08:30:06 PST", + "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "01:01:01,1111", + "valid": false + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ:00:00Z", + "valid": false + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/uri-reference.json b/tests/draft-next/optional/format/uri-reference.json new file mode 100644 index 00000000..8d9d254e --- /dev/null +++ b/tests/draft-next/optional/format/uri-reference.json @@ -0,0 +1,76 @@ +[ + { + "description": "validation of URI References", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/uri-template.json b/tests/draft-next/optional/format/uri-template.json new file mode 100644 index 00000000..f57d62df --- /dev/null +++ b/tests/draft-next/optional/format/uri-template.json @@ -0,0 +1,61 @@ +[ + { + "description": "format: uri-template", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri-template" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/optional/format/uri.json b/tests/draft-next/optional/format/uri.json new file mode 100644 index 00000000..50908eab --- /dev/null +++ b/tests/draft-next/optional/format/uri.json @@ -0,0 +1,141 @@ +[ + { + "description": "validation of URIs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/format/uuid.json b/tests/draft-next/optional/format/uuid.json new file mode 100644 index 00000000..6cea9dad --- /dev/null +++ b/tests/draft-next/optional/format/uuid.json @@ -0,0 +1,116 @@ +[ + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "all upper-case", + "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", + "valid": true + }, + { + "description": "all lower-case", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", + "valid": true + }, + { + "description": "mixed case", + "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", + "valid": true + }, + { + "description": "all zeroes is valid", + "data": "00000000-0000-0000-0000-000000000000", + "valid": true + }, + { + "description": "wrong length", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": false + }, + { + "description": "missing section", + "data": "2eb8aa08-aa98-11ea-73b441d16380", + "valid": false + }, + { + "description": "bad characters (not hex)", + "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", + "valid": false + }, + { + "description": "no dashes", + "data": "2eb8aa08aa9811eab4aa73b441d16380", + "valid": false + }, + { + "description": "too few dashes", + "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", + "valid": false + }, + { + "description": "too many dashes", + "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", + "valid": false + }, + { + "description": "dashes in the wrong spot", + "data": "2eb8aa08aa9811eab4aa73b441d16380----", + "valid": false + }, + { + "description": "valid version 4", + "data": "98d80576-482e-427f-8434-7f86890ab222", + "valid": true + }, + { + "description": "valid version 5", + "data": "99c17cbb-656f-564a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 6", + "data": "99c17cbb-656f-664a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 15", + "data": "99c17cbb-656f-f64a-940f-1a4568f03487", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/optional/non-bmp-regex.json b/tests/draft-next/optional/non-bmp-regex.json new file mode 100644 index 00000000..3af875c9 --- /dev/null +++ b/tests/draft-next/optional/non-bmp-regex.json @@ -0,0 +1,86 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "^๐Ÿฒ*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/optional/refOfUnknownKeyword.json b/tests/draft-next/optional/refOfUnknownKeyword.json new file mode 100644 index 00000000..489701cd --- /dev/null +++ b/tests/draft-next/optional/refOfUnknownKeyword.json @@ -0,0 +1,46 @@ +[ + { + "description": "reference of a root arbitrary keyword ", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unknown-keyword": {"type": "integer"}, + "properties": { + "bar": {"$ref": "#/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "reference of an arbitrary keyword of a sub-schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"unknown-keyword": {"type": "integer"}}, + "bar": {"$ref": "#/properties/foo/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/pattern.json b/tests/draft-next/pattern.json new file mode 100644 index 00000000..09c6d0fb --- /dev/null +++ b/tests/draft-next/pattern.json @@ -0,0 +1,65 @@ +[ + { + "description": "pattern validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/patternProperties.json b/tests/draft-next/patternProperties.json new file mode 100644 index 00000000..c7aca3df --- /dev/null +++ b/tests/draft-next/patternProperties.json @@ -0,0 +1,176 @@ +[ + { + "description": + "patternProperties validates properties matching a regex", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "f.*o": {"type": "integer"} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": {"foo": 1, "foooooo" : 2}, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": {"foo": "bar", "fooooo": 2}, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": {"foo": "bar", "foooooo" : "baz"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["foo"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "a*": {"type": "integer"}, + "aaa*": {"maximum": 20} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"a": 21}, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": {"aaaa": 18}, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": {"a": 21, "aaaa": 18}, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": {"a": "bar"}, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": {"aaaa": 31}, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": {"aaa": "foo", "aaaa": 31}, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "[0-9]{2,}": { "type": "boolean" }, + "X_": { "type": "string" } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { "answer 1": "42" }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { "a31b": null }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { "a_x_3": 3 }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { "a_X_3": 3 }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": {"foobar":1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/prefixItems.json b/tests/draft-next/prefixItems.json new file mode 100644 index 00000000..a7f5928c --- /dev/null +++ b/tests/draft-next/prefixItems.json @@ -0,0 +1,104 @@ +[ + { + "description": "a schema given for prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + {"type": "integer"}, + {"type": "string"} + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "wrong types", + "data": [ "foo", 1 ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ 1 ], + "valid": true + }, + { + "description": "array with additional items", + "data": [ 1, "foo", true ], + "valid": true + }, + { + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "prefixItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [true, false] + }, + "tests": [ + { + "description": "array with one item is valid", + "data": [ 1 ], + "valid": true + }, + { + "description": "array with two items is invalid", + "data": [ 1, "foo" ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "additional items are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{"type": "integer"}] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [1, "foo", false], + "valid": true + } + ] + }, + { + "description": "prefixItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft-next/properties.json b/tests/draft-next/properties.json new file mode 100644 index 00000000..1ba4fe8e --- /dev/null +++ b/tests/draft-next/properties.json @@ -0,0 +1,242 @@ +[ + { + "description": "object properties validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": {"foo": 1, "bar": "baz"}, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": {"foo": 1, "bar": {}}, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": {"foo": [], "bar": {}}, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": {"quux": []}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": + "properties, patternProperties, additionalProperties interaction", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"type": "array", "maxItems": 3}, + "bar": {"type": "array"} + }, + "patternProperties": {"f.o": {"minItems": 2}}, + "additionalProperties": {"type": "integer"} + }, + "tests": [ + { + "description": "property validates property", + "data": {"foo": [1, 2]}, + "valid": true + }, + { + "description": "property invalidates property", + "data": {"foo": [1, 2, 3, 4]}, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": {"foo": []}, + "valid": false + }, + { + "description": "patternProperty validates nonproperty", + "data": {"fxo": [1, 2]}, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": {"fxo": []}, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": {"bar": []}, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": {"quux": 3}, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": {"quux": "foo"}, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo\nbar": {"type": "number"}, + "foo\"bar": {"type": "number"}, + "foo\\bar": {"type": "number"}, + "foo\rbar": {"type": "number"}, + "foo\tbar": {"type": "number"}, + "foo\fbar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/propertyDependencies.json b/tests/draft-next/propertyDependencies.json new file mode 100644 index 00000000..9efa2b48 --- /dev/null +++ b/tests/draft-next/propertyDependencies.json @@ -0,0 +1,161 @@ +[ + { + "description": "propertyDependencies doesn't act on non-objects", + "schema": { + "propertyDependencies": { + "foo": {"bar": false} + } + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores strings", + "data": "abc", + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "propertyDependencies doesn't act on non-string property values", + "schema": { + "propertyDependencies": { + "foo": {"bar": false} + } + }, + "tests": [ + { + "description": "ignores booleans", + "data": {"foo": false}, + "valid": true + }, + { + "description": "ignores integers", + "data": {"foo": 2}, + "valid": true + }, + { + "description": "ignores floats", + "data": {"foo": 1.1}, + "valid": true + }, + { + "description": "ignores objects", + "data": {"foo": {}}, + "valid": true + }, + { + "description": "ignores objects wth a key of the expected value", + "data": {"foo": {"bar": "baz"}}, + "valid": true + }, + { + "description": "ignores objects with the expected value nested in structure", + "data": {"foo": {"baz": "bar"}}, + "valid": true + }, + { + "description": "ignores arrays", + "data": {"foo": []}, + "valid": true + }, + { + "description": "ignores null", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "multiple options selects the right one", + "schema": { + "propertyDependencies": { + "foo": { + "bar": { + "minProperties": 2, + "maxProperties": 2 + }, + "baz": {"maxProperties": 1}, + "qux": true, + "quux": false + } + } + }, + "tests": [ + { + "description": "bar with exactly 2 properties is valid", + "data": { + "foo": "bar", + "other-foo": "other-bar" + }, + "valid": true + }, + { + "description": "bar with more than 2 properties is invalid", + "data": { + "foo": "bar", + "other-foo": "other-bar", + "too": "many" + }, + "valid": false + }, + { + "description": "bar with fewer than 2 properties is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "baz alone is valid", + "data": {"foo": "baz"}, + "valid": true + }, + { + "description": "baz with other properties is invalid", + "data": { + "foo": "baz", + "other-foo": "other-bar" + }, + "valid": false + }, + { + "description": "anything allowed with qux", + "data": { + "foo": "qux", + "blah": ["some other property"], + "more": "properties" + }, + "valid": true + }, + { + "description": "quux is disallowed", + "data": { + "foo": "quux" + }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/propertyNames.json b/tests/draft-next/propertyNames.json new file mode 100644 index 00000000..e6140170 --- /dev/null +++ b/tests/draft-next/propertyNames.json @@ -0,0 +1,85 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "propertyNames": {"maxLength": 3} + }, + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [1, 2, 3, 4], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/ref.json b/tests/draft-next/ref.json new file mode 100644 index 00000000..1d5f2561 --- /dev/null +++ b/tests/draft-next/ref.json @@ -0,0 +1,1059 @@ +[ + { + "description": "root pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"$ref": "#"} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": {"foo": {"foo": false}}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": false}, + "valid": false + }, + { + "description": "recursive mismatch", + "data": {"foo": {"bar": false}}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {"type": "integer"}, + "bar": {"$ref": "#/properties/foo"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + {"type": "integer"}, + {"$ref": "#/prefixItems/0"} + ] + }, + "tests": [ + { + "description": "match array", + "data": [1, 2], + "valid": true + }, + { + "description": "mismatch array", + "data": [1, "foo"], + "valid": false + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, + "properties": { + "tilde": {"$ref": "#/$defs/tilde~0field"}, + "slash": {"$ref": "#/$defs/slash~1field"}, + "percent": {"$ref": "#/$defs/percent%25field"} + } + }, + "tests": [ + { + "description": "slash invalid", + "data": {"slash": "aoeu"}, + "valid": false + }, + { + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, + "valid": false + }, + { + "description": "percent invalid", + "data": {"percent": "aoeu"}, + "valid": false + }, + { + "description": "slash valid", + "data": {"slash": 123}, + "valid": true + }, + { + "description": "tilde valid", + "data": {"tilde": 123}, + "valid": true + }, + { + "description": "percent valid", + "data": {"percent": 123}, + "valid": true + } + ] + }, + { + "description": "nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "a": {"type": "integer"}, + "b": {"$ref": "#/$defs/a"}, + "c": {"$ref": "#/$defs/b"} + }, + "$ref": "#/$defs/c" + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref applies alongside sibling keywords", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/$defs/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid, maxItems valid", + "data": { "foo": [] }, + "valid": true + }, + { + "description": "ref valid, maxItems invalid", + "data": { "foo": [1, 2, 3] }, + "valid": false + }, + { + "description": "ref invalid", + "data": { "foo": "string" }, + "valid": false + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "https://json-schema.org/draft/next/schema" + }, + "tests": [ + { + "description": "remote ref valid", + "data": {"minLength": 1}, + "valid": true + }, + { + "description": "remote ref invalid", + "data": {"minLength": -1}, + "valid": false + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "$ref": {"type": "string"} + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "$ref": {"$ref": "#/$defs/is-string"} + }, + "$defs": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": false + } + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": {"type": "string"}, + "nodes": { + "type": "array", + "items": {"$ref": "node"} + } + }, + "required": ["meta", "nodes"], + "$defs": { + "node": { + "$id": "http://localhost:1234/draft-next/node", + "description": "node", + "type": "object", + "properties": { + "value": {"type": "number"}, + "subtree": {"$ref": "tree"} + }, + "required": ["value"] + } + } + }, + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 1.1}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": true + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": "string is invalid"}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": false + } + ] + }, + { + "description": "refs with quote", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo\"bar": {"$ref": "#/$defs/foo%22bar"} + }, + "$defs": { + "foo\"bar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "ref creates new scope when adjacent to keywords", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "A": { + "unevaluatedProperties": false + } + }, + "properties": { + "prop1": { + "type": "string" + } + }, + "$ref": "#/$defs/A" + }, + "tests": [ + { + "description": "referenced subschema doesn't see annotations from properties", + "data": { + "prop1": "match" + }, + "valid": false + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/$defs/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/$defs/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-relative-uri-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-refs-absolute-uris-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://example.com/a.json", + "$defs": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "$defs": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft/next/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id1-int.json", + "$id": "/draft/next/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft/next/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/ref-and-id2/base.json#/$defs/bigint; another valid uri for this location: https://example.com/ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id2#/$defs/smallint; another valid uri for this location: https://example.com/ref-and-id2/#bigint", + "$id": "/draft/next/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "RFC 8141 ยง2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "RFC 8141 ยง2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "RFC 8141 ยง2.3.2", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with f-component", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$comment": "RFC 8141 ยง2.3.3, but we don't allow fragments", + "$ref": "https://json-schema.org/draft/next/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": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "$defs": { + "bar": { + "$anchor": "something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN ref with nested pointer ref", + "schema": { + "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "foo": { + "$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": {"bar": {"type": "string"}}, + "$ref": "#/$defs/bar" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": "bar", + "valid": true + }, + { + "description": "a non-string is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "$ref": "http://example.com/ref/if", + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to then", + "schema": { + "$ref": "http://example.com/ref/then", + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to else", + "schema": { + "$ref": "http://example.com/ref/else", + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "$defs": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "$ref": "/absref/foobar.json" + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/refRemote.json b/tests/draft-next/refRemote.json new file mode 100644 index 00000000..3768b53b --- /dev/null +++ b/tests/draft-next/refRemote.json @@ -0,0 +1,314 @@ +[ + { + "description": "remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/draft-next/integer.json" + }, + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "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" + }, + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "anchor within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/draft-next/locationIndependentIdentifier.json#foo" + }, + "tests": [ + { + "description": "remote anchor valid", + "data": 1, + "valid": true + }, + { + "description": "remote anchor invalid", + "data": "a", + "valid": false + } + ] + }, + { + "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" + }, + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "base URI change", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/", + "items": { + "$id": "baseUriChange/", + "items": {"$ref": "folderInteger.json"} + } + }, + "tests": [ + { + "description": "base URI change ref valid", + "data": [[1]], + "valid": true + }, + { + "description": "base URI change ref invalid", + "data": [["a"]], + "valid": false + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/scope_change_defs1.json", + "type" : "object", + "properties": {"list": {"$ref": "baseUriChangeFolder/"}}, + "$defs": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/scope_change_defs2.json", + "type" : "object", + "properties": {"list": {"$ref": "baseUriChangeFolderInSubschema/#/$defs/bar"}}, + "$defs": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "$defs": { + "bar": { + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/object", + "type": "object", + "properties": { + "name": {"$ref": "name-defs.json#/$defs/orNull"} + } + }, + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false + } + ] + }, + { + "description": "remote ref with ref to defs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/schema-remote-ref-ref-defs1.json", + "$ref": "ref-and-defs.json" + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "http://localhost:1234/draft-next/locationIndependentIdentifier.json#/$defs/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "http://localhost:1234/draft-next/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different $id", + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different URN $id", + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with nested absolute ref", + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + } +] diff --git a/tests/draft-next/required.json b/tests/draft-next/required.json new file mode 100644 index 00000000..cc02fd34 --- /dev/null +++ b/tests/draft-next/required.json @@ -0,0 +1,158 @@ +[ + { + "description": "required validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "required": ["foo"] + }, + "tests": [ + { + "description": "present required property is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "required": ["__proto__", "toString", "constructor"] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/tests/draft-next/type.json b/tests/draft-next/type.json new file mode 100644 index 00000000..86e551c7 --- /dev/null +++ b/tests/draft-next/type.json @@ -0,0 +1,501 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": ["integer", "string"] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": ["string"] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": ["array", "object"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": ["array", "object", "null"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/tests/draft-next/unevaluatedItems.json b/tests/draft-next/unevaluatedItems.json new file mode 100644 index 00000000..7379afb4 --- /dev/null +++ b/tests/draft-next/unevaluatedItems.json @@ -0,0 +1,719 @@ +[ + { + "description": "unevaluatedItems true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": true + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": { "type": "string" } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with valid unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with invalid unevaluated items", + "data": [42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with uniform items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": { "type": "string" }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", "bar"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with tuple", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with items and prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "type": "string" } + ], + "items": true, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "items": {"type": "number"}, + "unevaluatedItems": {"type": "string"} + }, + "tests": [ + { + "description": "valid under items", + "comment": "no elements are considered by unevaluatedItems", + "data": [5, 6, 7, 8], + "valid": true + }, + { + "description": "invalid under items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested tuple", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "type": "string" } + ], + "allOf": [ + { + "prefixItems": [ + true, + { "type": "number" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", 42], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", 42, true], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": {"type": "boolean"}, + "anyOf": [ + { "items": {"type": "string"} }, + true + ] + }, + "tests": [ + { + "description": "with only (valid) additional items", + "data": [true, false], + "valid": true + }, + { + "description": "with no additional items", + "data": ["yes", "no"], + "valid": true + }, + { + "description": "with invalid additional item", + "data": ["yes", false], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested prefixItems and items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "prefixItems": [ + { "type": "string" } + ], + "items": true + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with nested unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "prefixItems": [ + { "type": "string" } + ] + }, + { "unevaluatedItems": true } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "const": "foo" } + ], + "anyOf": [ + { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + { + "prefixItems": [ + true, + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when one schema matches and has no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "when one schema matches and has unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + }, + { + "description": "when two schemas match and has no unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "when two schemas match and has unevaluated items", + "data": ["foo", "bar", "baz", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "const": "foo" } + ], + "oneOf": [ + { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + { + "prefixItems": [ + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with not", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "const": "foo" } + ], + "not": { + "not": { + "prefixItems": [ + true, + { "const": "bar" } + ] + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [ + { "const": "foo" } + ], + "if": { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + "then": { + "prefixItems": [ + true, + true, + { "const": "then" } + ] + }, + "else": { + "prefixItems": [ + true, + true, + true, + { "const": "else" } + ] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when if matches and it has no unevaluated items", + "data": ["foo", "bar", "then"], + "valid": true + }, + { + "description": "when if matches and it has unevaluated items", + "data": ["foo", "bar", "then", "else"], + "valid": false + }, + { + "description": "when if doesn't match and it has no unevaluated items", + "data": ["foo", 42, 42, "else"], + "valid": true + }, + { + "description": "when if doesn't match and it has unevaluated items", + "data": ["foo", 42, 42, "else", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [true], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$ref": "#/$defs/bar", + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "prefixItems": [ true ] + }, + { "unevaluatedItems": false } + ] + }, + "tests": [ + { + "description": "always fails", + "data": [ 1 ], + "valid": false + } + ] + }, + { + "description": "item is evaluated in an uncle schema to unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": { + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "prefixItems": [ + true, + { "type": "string" } + ] + } + } + } + ] + }, + "tests": [ + { + "description": "no extra items", + "data": { + "foo": [ + "test" + ] + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": [ + "test", + "test" + ] + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on adjacent contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [true], + "contains": {"type": "string"}, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "second item is evaluated by contains", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "contains fails, second item is not evaluated", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "contains passes, second item is not evaluated", + "data": [ 1, 2, "foo" ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on multiple nested contains", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { "contains": { "multipleOf": 2 } }, + { "contains": { "multipleOf": 3 } } + ], + "unevaluatedItems": { "multipleOf": 5 } + }, + "tests": [ + { + "description": "5 not evaluated, passes unevaluatedItems", + "data": [ 2, 3, 4, 5, 6 ], + "valid": true + }, + { + "description": "7 not evaluated, fails unevaluatedItems", + "data": [ 2, 3, 4, 7, 8 ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems and contains interact to control item dependency relationship", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "contains": {"const": "a"} + }, + "then": { + "if": { + "contains": {"const": "b"} + }, + "then": { + "if": { + "contains": {"const": "c"} + } + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "empty array is valid", + "data": [], + "valid": true + }, + { + "description": "only a's are valid", + "data": [ "a", "a" ], + "valid": true + }, + { + "description": "a's and b's are valid", + "data": [ "a", "b", "a", "b", "a" ], + "valid": true + }, + { + "description": "a's, b's and c's are valid", + "data": [ "c", "a", "c", "c", "b", "a" ], + "valid": true + }, + { + "description": "only b's are invalid", + "data": [ "b", "b" ], + "valid": false + }, + { + "description": "only c's are invalid", + "data": [ "c", "c" ], + "valid": false + }, + { + "description": "only b's and c's are invalid", + "data": [ "c", "b", "c", "b", "c" ], + "valid": false + }, + { + "description": "only a's and c's are invalid", + "data": [ "c", "a", "c", "a", "c" ], + "valid": false + } + ] + }, + { + "description": "non-array instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "prefixItems": [{"const": "a"}] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": [ "a" ], + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": [ "b" ], + "valid": false + } + + ] + } +] diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json new file mode 100644 index 00000000..69fe8a00 --- /dev/null +++ b/tests/draft-next/unevaluatedProperties.json @@ -0,0 +1,1572 @@ +[ + { + "description": "unevaluatedProperties true", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties schema", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "unevaluatedProperties": { + "type": "string", + "minLength": 3 + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with valid unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with invalid unevaluated properties", + "data": { + "foo": "fo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "patternProperties": { + "^foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "additionalProperties": true, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "properties": { + "bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "patternProperties": { + "^bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "additionalProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": { + "type": "string", + "maxLength": 2 + } + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "anyOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + }, + { + "properties": { + "quux": { "const": "quux" } + }, + "required": ["quux"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when one matches and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when one matches and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "not-baz" + }, + "valid": false + }, + { + "description": "when two match and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": true + }, + { + "description": "when two match and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz", + "quux": "not-quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "oneOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "quux": "quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with not", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "not": { + "not": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, then not defined", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": false + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, else not defined", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with dependentSchemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [true], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "$ref": "#/$defs/bar", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins (reverse order)", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "allOf": [ + { + "unevaluatedProperties": false + }, + { + "properties": { + "foo": true + } + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, true with properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, false with properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "unevaluatedProperties": true + }, + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "property is evaluated in an uncle schema to unevaluatedProperties", + "comment": "see https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "properties": { + "faz": { + "type": "string" + } + } + } + } + } + ] + }, + "tests": [ + { + "description": "no extra properties", + "data": { + "foo": { + "bar": "test" + } + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": { + "bar": "test", + "faz": "test" + } + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, allOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + }, + "unevaluatedProperties": false + } + ], + "anyOf": [ + { + "properties": { + "bar": true + } + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, anyOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + } + ], + "anyOf": [ + { + "properties": { + "bar": true + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties + single cyclic ref", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "type": "object", + "properties": { + "x": { "$ref": "#" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is valid", + "data": {}, + "valid": true + }, + { + "description": "Single is valid", + "data": { "x": {} }, + "valid": true + }, + { + "description": "Unevaluated on 1st level is invalid", + "data": { "x": {}, "y": {} }, + "valid": false + }, + { + "description": "Nested is valid", + "data": { "x": { "x": {} } }, + "valid": true + }, + { + "description": "Unevaluated on 2nd level is invalid", + "data": { "x": { "x": {}, "y": {} } }, + "valid": false + }, + { + "description": "Deep nested is valid", + "data": { "x": { "x": { "x": {} } } }, + "valid": true + }, + { + "description": "Unevaluated on 3rd level is invalid", + "data": { "x": { "x": { "x": {}, "y": {} } } }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties + ref inside allOf / oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "one": { + "properties": { "a": true } + }, + "two": { + "required": ["x"], + "properties": { "x": true } + } + }, + "allOf": [ + { "$ref": "#/$defs/one" }, + { "properties": { "b": true } }, + { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { + "required": ["y"], + "properties": { "y": true } + } + ] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid (no x or y)", + "data": {}, + "valid": false + }, + { + "description": "a and b are invalid (no x or y)", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "x and y are invalid", + "data": { "x": 1, "y": 1 }, + "valid": false + }, + { + "description": "a and x are valid", + "data": { "a": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and y are valid", + "data": { "a": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x are valid", + "data": { "a": 1, "b": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and b and y are valid", + "data": { "a": 1, "b": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x and y are invalid", + "data": { "a": 1, "b": 1, "x": 1, "y": 1 }, + "valid": false + } + ] + }, + { + "description": "dynamic evaluation inside nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "one": { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { "required": ["b"], "properties": { "b": true } }, + { "required": ["xx"], "patternProperties": { "x": true } }, + { "required": ["all"], "unevaluatedProperties": true } + ] + }, + "two": { + "oneOf": [ + { "required": ["c"], "properties": { "c": true } }, + { "required": ["d"], "properties": { "d": true } } + ] + } + }, + "oneOf": [ + { "$ref": "#/$defs/one" }, + { "required": ["a"], "properties": { "a": true } } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid", + "data": {}, + "valid": false + }, + { + "description": "a is valid", + "data": { "a": 1 }, + "valid": true + }, + { + "description": "b is valid", + "data": { "b": 1 }, + "valid": true + }, + { + "description": "c is valid", + "data": { "c": 1 }, + "valid": true + }, + { + "description": "d is valid", + "data": { "d": 1 }, + "valid": true + }, + { + "description": "a + b is invalid", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "a + c is invalid", + "data": { "a": 1, "c": 1 }, + "valid": false + }, + { + "description": "a + d is invalid", + "data": { "a": 1, "d": 1 }, + "valid": false + }, + { + "description": "b + c is invalid", + "data": { "b": 1, "c": 1 }, + "valid": false + }, + { + "description": "b + d is invalid", + "data": { "b": 1, "d": 1 }, + "valid": false + }, + { + "description": "c + d is invalid", + "data": { "c": 1, "d": 1 }, + "valid": false + }, + { + "description": "xx is valid", + "data": { "xx": 1 }, + "valid": true + }, + { + "description": "xx + foox is valid", + "data": { "xx": 1, "foox": 1 }, + "valid": true + }, + { + "description": "xx + foo is invalid", + "data": { "xx": 1, "foo": 1 }, + "valid": false + }, + { + "description": "xx + a is invalid", + "data": { "xx": 1, "a": 1 }, + "valid": false + }, + { + "description": "xx + b is invalid", + "data": { "xx": 1, "b": 1 }, + "valid": false + }, + { + "description": "xx + c is invalid", + "data": { "xx": 1, "c": 1 }, + "valid": false + }, + { + "description": "xx + d is invalid", + "data": { "xx": 1, "d": 1 }, + "valid": false + }, + { + "description": "all is valid", + "data": { "all": 1 }, + "valid": true + }, + { + "description": "all + foo is valid", + "data": { "all": 1, "foo": 1 }, + "valid": true + }, + { + "description": "all + a is invalid", + "data": { "all": 1, "a": 1 }, + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "unevaluatedProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null valued properties", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties can see inside propertyDependencies", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": { + "foo": { + "type": "string" + } + }, + "propertyDependencies": { + "foo": { + "foo1": { + "properties": { + "bar": true + } + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "allows bar if foo = foo1", + "data": { + "foo": "foo1", + "bar": 42 + }, + "valid": true + }, + { + "description": "disallows bar if foo != foo1", + "data": { + "foo": "foo2", + "bar": 42 + }, + "valid": false + }, + { + "description": "disallows bar if foo is absent", + "data": { + "bar": 42 + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties not affected by propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "propertyNames": {"maxLength": 1}, + "unevaluatedProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "allows only number properties", + "data": {"a": 1}, + "valid": true + }, + { + "description": "string property is invalid", + "data": {"a": "b"}, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "if": { + "patternProperties": { + "foo": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": { + "foo": "a" + }, + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": { + "bar": "a" + }, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/uniqueItems.json b/tests/draft-next/uniqueItems.json new file mode 100644 index 00000000..b16dd505 --- /dev/null +++ b/tests/draft-next/uniqueItems.json @@ -0,0 +1,419 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": false + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1, "{}"], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [{}, [1], true, null, {}, 1], + "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [false, false], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [true, true], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [false, true, "foo", "foo"], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [true, false, "foo", "foo"], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, + "items": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [false, false], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [true, true], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "items": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] + } +] diff --git a/tests/draft-next/unknownKeyword.json b/tests/draft-next/unknownKeyword.json new file mode 100644 index 00000000..055ff6b6 --- /dev/null +++ b/tests/draft-next/unknownKeyword.json @@ -0,0 +1,57 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$defs": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/draft-next/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft-next/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/draft-next/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_unknown0" }, + { "$ref": "#/$defs/id_in_unknown1" }, + { "$ref": "https://localhost:1234/draft-next/unknownKeyword/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft-next/vocabulary.json b/tests/draft-next/vocabulary.json new file mode 100644 index 00000000..f25b9e12 --- /dev/null +++ b/tests/draft-next/vocabulary.json @@ -0,0 +1,57 @@ +[ + { + "description": "schema that uses custom metaschema with with no validation vocabulary", + "schema": { + "$id": "https://schema/using/no/validation", + "$schema": "http://localhost:1234/draft-next/metaschema-no-validation.json", + "properties": { + "badProperty": false, + "numberProperty": { + "minimum": 10 + } + } + }, + "tests": [ + { + "description": "applicator vocabulary still works", + "data": { + "badProperty": "this property should not exist" + }, + "valid": false + }, + { + "description": "no validation: valid number", + "data": { + "numberProperty": 20 + }, + "valid": true + }, + { + "description": "no validation: invalid number, but it still validates", + "data": { + "numberProperty": 1 + }, + "valid": true + } + ] + }, + { + "description": "ignore unrecognized optional vocabulary", + "schema": { + "$schema": "http://localhost:1234/draft-next/metaschema-optional-vocabulary.json", + "type": "number" + }, + "tests": [ + { + "description": "string value", + "data": "foobar", + "valid": false + }, + { + "description": "number value", + "data": 20, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/additionalItems.json b/tests/draft2019-09/additionalItems.json index abecc578..aa44bcb7 100644 --- a/tests/draft2019-09/additionalItems.json +++ b/tests/draft2019-09/additionalItems.json @@ -2,6 +2,7 @@ { "description": "additionalItems as schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": [{}], "additionalItems": {"type": "integer"} }, @@ -19,8 +20,33 @@ ] }, { - "description": "items is schema, no additionalItems", + "description": "when items is schema, additionalItems does nothing", "schema": { + "$schema":"https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [1,2,3], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [1,"2","3"], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": {}, "additionalItems": false }, @@ -33,14 +59,25 @@ ] }, { - "description": "array of items with no additionalItems", + "description": "array of items with no additionalItems permitted", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { - "description": "fewer number of items present", + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", "data": [ 1, 2 ], "valid": true }, @@ -58,7 +95,10 @@ }, { "description": "additionalItems as false without items", - "schema": {"additionalItems": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": false + }, "tests": [ { "description": @@ -75,7 +115,10 @@ }, { "description": "additionalItems are allowed by default", - "schema": {"items": [{"type": "integer"}]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{"type": "integer"}] + }, "tests": [ { "description": "only the first item is validated", @@ -83,5 +126,76 @@ "valid": true } ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { "items": [ { "type": "integer" } ] } + ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, null ], + "valid": true + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { "items": [ { "type": "integer" }, { "type": "string" } ] } + ], + "items": [ {"type": "integer" } ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, "hello" ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ { "type": "string" } ], + "additionalItems": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/additionalProperties.json b/tests/draft2019-09/additionalProperties.json index ffeac6b3..f9f03bb0 100644 --- a/tests/draft2019-09/additionalProperties.json +++ b/tests/draft2019-09/additionalProperties.json @@ -3,6 +3,7 @@ "description": "additionalProperties being false does not allow other properties", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": {"foo": {}, "bar": {}}, "patternProperties": { "^v": {} }, "additionalProperties": false @@ -43,6 +44,7 @@ { "description": "non-ASCII pattern with additionalProperties", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "patternProperties": {"^รก": {}}, "additionalProperties": false }, @@ -60,9 +62,9 @@ ] }, { - "description": - "additionalProperties allows a schema which should validate", + "description": "additionalProperties with schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} }, @@ -88,6 +90,7 @@ "description": "additionalProperties can exist by itself", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "additionalProperties": {"type": "boolean"} }, "tests": [ @@ -105,7 +108,10 @@ }, { "description": "additionalProperties are allowed by default", - "schema": {"properties": {"foo": {}, "bar": {}}}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo": {}, "bar": {}} + }, "tests": [ { "description": "additional properties are allowed", @@ -115,8 +121,9 @@ ] }, { - "description": "additionalProperties should not look in applicators", + "description": "additionalProperties does not look in applicators", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ {"properties": {"foo": {}}} ], @@ -124,10 +131,26 @@ }, "tests": [ { - "description": "properties defined in allOf are not allowed", + "description": "properties defined in allOf are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/allOf.json b/tests/draft2019-09/allOf.json index eb612091..dec267e1 100644 --- a/tests/draft2019-09/allOf.json +++ b/tests/draft2019-09/allOf.json @@ -2,6 +2,7 @@ { "description": "allOf", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ { "properties": { @@ -43,6 +44,7 @@ { "description": "allOf with base schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": {"bar": {"type": "integer"}}, "required": ["bar"], "allOf" : [ @@ -91,6 +93,7 @@ { "description": "allOf simple types", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ {"maximum": 30}, {"minimum": 20} @@ -111,7 +114,10 @@ }, { "description": "allOf with boolean schemas, all true", - "schema": {"allOf": [true, true]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [true, true] + }, "tests": [ { "description": "any value is valid", @@ -122,7 +128,10 @@ }, { "description": "allOf with boolean schemas, some false", - "schema": {"allOf": [true, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [true, false] + }, "tests": [ { "description": "any value is invalid", @@ -133,7 +142,10 @@ }, { "description": "allOf with boolean schemas, all false", - "schema": {"allOf": [false, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [false, false] + }, "tests": [ { "description": "any value is invalid", @@ -145,6 +157,7 @@ { "description": "allOf with one empty schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ {} ] @@ -160,6 +173,7 @@ { "description": "allOf with two empty schemas", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ {}, {} @@ -176,6 +190,7 @@ { "description": "allOf with the first empty schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ {}, { "type": "number" } @@ -197,6 +212,7 @@ { "description": "allOf with the last empty schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ { "type": "number" }, {} @@ -214,5 +230,83 @@ "valid": false } ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index 06b0ba4d..5d8c86f1 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -2,9 +2,8 @@ { "description": "Location-independent identifier", "schema": { - "allOf": [{ - "$ref": "#foo" - }], + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#foo", "$defs": { "A": { "$anchor": "foo", @@ -28,12 +27,11 @@ { "description": "Location-independent identifier with absolute URI", "schema": { - "allOf": [{ - "$ref": "http://localhost:1234/bar#foo" - }], + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/bar#foo", "$defs": { "A": { - "$id": "http://localhost:1234/bar", + "$id": "http://localhost:1234/draft2019-09/bar", "$anchor": "foo", "type": "integer" } @@ -55,10 +53,9 @@ { "description": "Location-independent identifier with base URI change in subschema", "schema": { - "$id": "http://localhost:1234/root", - "allOf": [{ - "$ref": "http://localhost:1234/nested.json#foo" - }], + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/root", + "$ref": "http://localhost:1234/draft2019-09/nested.json#foo", "$defs": { "A": { "$id": "nested.json", @@ -83,5 +80,156 @@ "valid": false } ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/foobar", + "$defs": { + "A": { + "$id": "child1", + "allOf": [ + { + "$id": "child2", + "$anchor": "my_anchor", + "type": "number" + }, + { + "$anchor": "my_anchor", + "type": "string" + } + ] + } + }, + "$ref": "child1#my_anchor" + }, + "tests": [ + { + "description": "$ref resolves to /$defs/A/allOf/1", + "data": "a", + "valid": true + }, + { + "description": "$ref does not resolve to /$defs/A/allOf/0", + "data": 1, + "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/anyOf.json b/tests/draft2019-09/anyOf.json index ab5eb386..8712d114 100644 --- a/tests/draft2019-09/anyOf.json +++ b/tests/draft2019-09/anyOf.json @@ -2,6 +2,7 @@ { "description": "anyOf", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "anyOf": [ { "type": "integer" @@ -37,6 +38,7 @@ { "description": "anyOf with base schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "anyOf" : [ { @@ -67,7 +69,10 @@ }, { "description": "anyOf with boolean schemas, all true", - "schema": {"anyOf": [true, true]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [true, true] + }, "tests": [ { "description": "any value is valid", @@ -78,7 +83,10 @@ }, { "description": "anyOf with boolean schemas, some true", - "schema": {"anyOf": [true, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [true, false] + }, "tests": [ { "description": "any value is valid", @@ -89,7 +97,10 @@ }, { "description": "anyOf with boolean schemas, all false", - "schema": {"anyOf": [false, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [false, false] + }, "tests": [ { "description": "any value is invalid", @@ -101,6 +112,7 @@ { "description": "anyOf complex types", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "anyOf": [ { "properties": { @@ -142,6 +154,7 @@ { "description": "anyOf with one empty schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "anyOf": [ { "type": "number" }, {} @@ -163,6 +176,7 @@ { "description": "nested anyOf, to check validation semantics", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "anyOf": [ { "anyOf": [ diff --git a/tests/draft2019-09/const.json b/tests/draft2019-09/const.json index c089625d..29700fda 100644 --- a/tests/draft2019-09/const.json +++ b/tests/draft2019-09/const.json @@ -1,7 +1,10 @@ [ { "description": "const validation", - "schema": {"const": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 2 + }, "tests": [ { "description": "same value is valid", @@ -22,7 +25,10 @@ }, { "description": "const with object", - "schema": {"const": {"foo": "bar", "baz": "bax"}}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": {"foo": "bar", "baz": "bax"} + }, "tests": [ { "description": "same object is valid", @@ -48,7 +54,10 @@ }, { "description": "const with array", - "schema": {"const": [{ "foo": "bar" }]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [{ "foo": "bar" }] + }, "tests": [ { "description": "same array is valid", @@ -69,7 +78,10 @@ }, { "description": "const with null", - "schema": {"const": null}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": null + }, "tests": [ { "description": "null is valid", @@ -85,7 +97,10 @@ }, { "description": "const with false does not match 0", - "schema": {"const": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": false + }, "tests": [ { "description": "false is valid", @@ -106,7 +121,10 @@ }, { "description": "const with true does not match 1", - "schema": {"const": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": true + }, "tests": [ { "description": "true is valid", @@ -126,8 +144,107 @@ ] }, { - "description": "const with 0 does not match false", - "schema": {"const": 0}, + "description": "const with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [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": "const with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [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": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": {"a": false} + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": {"a": true} + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 0 + }, "tests": [ { "description": "false is invalid", @@ -143,12 +260,30 @@ "description": "float zero is valid", "data": 0.0, "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false } ] }, { "description": "const with 1 does not match true", - "schema": {"const": 1}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 1 + }, "tests": [ { "description": "true is invalid", @@ -166,5 +301,87 @@ "valid": true } ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/contains.json b/tests/draft2019-09/contains.json index b7ae5a25..30458bf4 100644 --- a/tests/draft2019-09/contains.json +++ b/tests/draft2019-09/contains.json @@ -2,6 +2,7 @@ { "description": "contains keyword validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "contains": {"minimum": 5} }, "tests": [ @@ -40,6 +41,7 @@ { "description": "contains keyword with const keyword", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "contains": { "const": 5 } }, "tests": [ @@ -62,7 +64,10 @@ }, { "description": "contains keyword with boolean schema true", - "schema": {"contains": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": true + }, "tests": [ { "description": "any non-empty array is valid", @@ -78,7 +83,10 @@ }, { "description": "contains keyword with boolean schema false", - "schema": {"contains": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": false + }, "tests": [ { "description": "any non-empty array is invalid", @@ -89,6 +97,79 @@ "description": "empty array is invalid", "data": [], "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { "multipleOf": 2 }, + "contains": { "multipleOf": 3 } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ 2, 4, 8 ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ 3, 6, 9 ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ 6, 12 ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ 1, 5 ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "if": false, + "else": true + } + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ null ], + "valid": true } ] } diff --git a/tests/draft2019-09/content.json b/tests/draft2019-09/content.json new file mode 100644 index 00000000..2a7a5d87 --- /dev/null +++ b/tests/draft2019-09/content.json @@ -0,0 +1,131 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document; validates true", + "data": "{:}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character); validates true", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64", + "contentSchema": { "type": "object", "required": ["foo"], "properties": { "foo": { "type": "string" } } } + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "another valid base64-encoded JSON document", + "data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==", + "valid": true + }, + { + "description": "an invalid base64-encoded JSON document; validates true", + "data": "eyJib28iOiAyMH0=", + "valid": true + }, + { + "description": "an empty object as a base64-encoded JSON document; validates true", + "data": "e30=", + "valid": true + }, + { + "description": "an empty array as a base64-encoded JSON document", + "data": "W10=", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/default.json b/tests/draft2019-09/default.json index 17629779..95eba5a7 100644 --- a/tests/draft2019-09/default.json +++ b/tests/draft2019-09/default.json @@ -2,6 +2,7 @@ { "description": "invalid type for default", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": { "type": "integer", @@ -25,6 +26,7 @@ { "description": "invalid string value for default", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "bar": { "type": "string", @@ -45,5 +47,36 @@ "valid": true } ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/defs.json b/tests/draft2019-09/defs.json index f2fbec42..3f9088c3 100644 --- a/tests/draft2019-09/defs.json +++ b/tests/draft2019-09/defs.json @@ -1,19 +1,16 @@ [ { - "description": "valid definition", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "description": "validate definition against metaschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "valid definition schema", "data": {"$defs": {"foo": {"type": "integer"}}}, "valid": true - } - ] - }, - { - "description": "invalid definition", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, - "tests": [ + }, { "description": "invalid definition schema", "data": {"$defs": {"foo": {"type": 1}}}, diff --git a/tests/draft2019-09/dependentRequired.json b/tests/draft2019-09/dependentRequired.json new file mode 100644 index 00000000..d573c10b --- /dev/null +++ b/tests/draft2019-09/dependentRequired.json @@ -0,0 +1,152 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": {"bar": []} + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/dependentSchemas.json b/tests/draft2019-09/dependentSchemas.json new file mode 100644 index 00000000..3577efdf --- /dev/null +++ b/tests/draft2019-09/dependentSchemas.json @@ -0,0 +1,170 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/enum.json b/tests/draft2019-09/enum.json index 32d79026..f9a44a61 100644 --- a/tests/draft2019-09/enum.json +++ b/tests/draft2019-09/enum.json @@ -1,7 +1,10 @@ [ { "description": "simple enum validation", - "schema": {"enum": [1, 2, 3]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [1, 2, 3] + }, "tests": [ { "description": "one of the enum is valid", @@ -17,7 +20,10 @@ }, { "description": "heterogeneous enum validation", - "schema": {"enum": [6, "foo", [], true, {"foo": 12}]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [6, "foo", [], true, {"foo": 12}] + }, "tests": [ { "description": "one of the enum is valid", @@ -33,12 +39,47 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [6, null] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false } ] }, { "description": "enums in properties", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type":"object", "properties": { "foo": {"enum":["foo"]}, @@ -52,6 +93,16 @@ "data": {"foo":"foo", "bar":"bar"}, "valid": true }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, @@ -72,6 +123,7 @@ { "description": "enum with escaped characters", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "enum": ["foo\nbar", "foo\rbar"] }, "tests": [ @@ -94,7 +146,10 @@ }, { "description": "enum with false does not match 0", - "schema": {"enum": [false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [false] + }, "tests": [ { "description": "false is valid", @@ -115,7 +170,10 @@ }, { "description": "enum with true does not match 1", - "schema": {"enum": [true]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [true] + }, "tests": [ { "description": "true is valid", @@ -136,7 +194,10 @@ }, { "description": "enum with 0 does not match false", - "schema": {"enum": [0]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [0] + }, "tests": [ { "description": "false is invalid", @@ -157,7 +218,10 @@ }, { "description": "enum with 1 does not match true", - "schema": {"enum": [1]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [1] + }, "tests": [ { "description": "true is invalid", @@ -175,5 +239,24 @@ "valid": true } ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ "hello\u0000there" ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/exclusiveMaximum.json b/tests/draft2019-09/exclusiveMaximum.json index dc3cd709..4ec85698 100644 --- a/tests/draft2019-09/exclusiveMaximum.json +++ b/tests/draft2019-09/exclusiveMaximum.json @@ -2,6 +2,7 @@ { "description": "exclusiveMaximum validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "exclusiveMaximum": 3.0 }, "tests": [ diff --git a/tests/draft2019-09/exclusiveMinimum.json b/tests/draft2019-09/exclusiveMinimum.json index b38d7ece..24f46898 100644 --- a/tests/draft2019-09/exclusiveMinimum.json +++ b/tests/draft2019-09/exclusiveMinimum.json @@ -2,6 +2,7 @@ { "description": "exclusiveMinimum validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "exclusiveMinimum": 1.1 }, "tests": [ diff --git a/tests/draft2019-09/format.json b/tests/draft2019-09/format.json index 93305f5c..2934dcef 100644 --- a/tests/draft2019-09/format.json +++ b/tests/draft2019-09/format.json @@ -1,611 +1,740 @@ [ { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "description": "email format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "email" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IDN e-mail addresses", - "schema": {"format": "idn-email"}, + "description": "idn-email format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-email" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of regexes", - "schema": {"format": "regex"}, + "description": "regex format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "regex" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "description": "ipv4 format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv4" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "description": "ipv6 format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv6" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IDN hostnames", - "schema": {"format": "idn-hostname"}, + "description": "idn-hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-hostname" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of hostnames", - "schema": {"format": "hostname"}, + "description": "hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "hostname" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date strings", - "schema": {"format": "date"}, + "description": "date format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "description": "date-time format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date-time" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of time strings", - "schema": {"format": "time"}, + "description": "time format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "time" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of JSON pointers", - "schema": {"format": "json-pointer"}, + "description": "json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "json-pointer" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of relative JSON pointers", - "schema": {"format": "relative-json-pointer"}, + "description": "relative-json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "relative-json-pointer" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IRIs", - "schema": {"format": "iri"}, + "description": "iri format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IRI references", - "schema": {"format": "iri-reference"}, + "description": "iri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri-reference" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URIs", - "schema": {"format": "uri"}, + "description": "uri format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI references", - "schema": {"format": "uri-reference"}, + "description": "uri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-reference" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI templates", - "schema": {"format": "uri-template"}, + "description": "uri-template format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-template" + }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", + "data": null, + "valid": true + } + ] + }, + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + } + ] + }, + { + "description": "duration format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", "data": null, "valid": true } diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json new file mode 100644 index 00000000..e2e403f0 --- /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/if-then-else.json b/tests/draft2019-09/if-then-else.json index be732816..510a0e0a 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -2,6 +2,7 @@ { "description": "ignore if without then or else", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { "const": 0 } @@ -22,6 +23,7 @@ { "description": "ignore then without if", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "then": { "const": 0 } @@ -42,6 +44,7 @@ { "description": "ignore else without if", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "else": { "const": 0 } @@ -62,6 +65,7 @@ { "description": "if and then without else", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { "exclusiveMaximum": 0 }, @@ -90,6 +94,7 @@ { "description": "if and else without then", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { "exclusiveMaximum": 0 }, @@ -118,6 +123,7 @@ { "description": "validate against correct branch, then vs else", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { "exclusiveMaximum": 0 }, @@ -154,6 +160,7 @@ { "description": "non-interference across combined schemas", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "allOf": [ { "if": { @@ -184,5 +191,78 @@ "valid": true } ] + }, + { + "description": "if with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": true, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": false, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/infinite-loop-detection.json b/tests/draft2019-09/infinite-loop-detection.json new file mode 100644 index 00000000..eb694145 --- /dev/null +++ b/tests/draft2019-09/infinite-loop-detection.json @@ -0,0 +1,37 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/items.json b/tests/draft2019-09/items.json index 6e98ee82..e24156a7 100644 --- a/tests/draft2019-09/items.json +++ b/tests/draft2019-09/items.json @@ -2,6 +2,7 @@ { "description": "a schema given for items", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": {"type": "integer"} }, "tests": [ @@ -33,6 +34,7 @@ { "description": "an array of schemas for items", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": [ {"type": "integer"}, {"type": "string"} @@ -77,7 +79,10 @@ }, { "description": "items with boolean schema (true)", - "schema": {"items": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": true + }, "tests": [ { "description": "any array is valid", @@ -93,7 +98,10 @@ }, { "description": "items with boolean schema (false)", - "schema": {"items": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": false + }, "tests": [ { "description": "any non-empty array is invalid", @@ -110,6 +118,7 @@ { "description": "items with boolean schemas", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": [true, false] }, "tests": [ @@ -133,6 +142,7 @@ { "description": "items and subitems", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$defs": { "item": { "type": "array", @@ -215,6 +225,7 @@ { "description": "nested items", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "array", "items": { "type": "array", @@ -246,5 +257,39 @@ "valid": false } ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/maxContains.json b/tests/draft2019-09/maxContains.json new file mode 100644 index 00000000..ce4507c3 --- /dev/null +++ b/tests/draft2019-09/maxContains.json @@ -0,0 +1,102 @@ +[ + { + "description": "maxContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "two items still valid against lone maxContains", + "data": [ 1, 2 ], + "valid": true + } + ] + }, + { + "description": "maxContains with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "all elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + }, + { + "description": "some elements match, valid maxContains", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "some elements match, invalid maxContains", + "data": [ 1, 2, 1 ], + "valid": false + } + ] + }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, + { + "description": "minContains < maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 1, + "maxContains": 3 + }, + "tests": [ + { + "description": "actual < minContains < maxContains", + "data": [ ], + "valid": false + }, + { + "description": "minContains < actual < maxContains", + "data": [ 1, 1 ], + "valid": true + }, + { + "description": "minContains < maxContains < actual", + "data": [ 1, 1, 1, 1 ], + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/maxItems.json b/tests/draft2019-09/maxItems.json index 3b53a6b3..d9ed1570 100644 --- a/tests/draft2019-09/maxItems.json +++ b/tests/draft2019-09/maxItems.json @@ -1,7 +1,10 @@ [ { "description": "maxItems validation", - "schema": {"maxItems": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxItems": 2 + }, "tests": [ { "description": "shorter is valid", @@ -24,5 +27,24 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxItems": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maxLength.json b/tests/draft2019-09/maxLength.json index 811d35b2..f242c3ef 100644 --- a/tests/draft2019-09/maxLength.json +++ b/tests/draft2019-09/maxLength.json @@ -1,7 +1,10 @@ [ { "description": "maxLength validation", - "schema": {"maxLength": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxLength": 2 + }, "tests": [ { "description": "shorter is valid", @@ -29,5 +32,24 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maxProperties.json b/tests/draft2019-09/maxProperties.json index 513731e4..5b31474c 100644 --- a/tests/draft2019-09/maxProperties.json +++ b/tests/draft2019-09/maxProperties.json @@ -1,7 +1,10 @@ [ { "description": "maxProperties validation", - "schema": {"maxProperties": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 2 + }, "tests": [ { "description": "shorter is valid", @@ -34,5 +37,43 @@ "valid": true } ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/maximum.json b/tests/draft2019-09/maximum.json index 8150984e..c1f1dfd8 100644 --- a/tests/draft2019-09/maximum.json +++ b/tests/draft2019-09/maximum.json @@ -1,7 +1,10 @@ [ { "description": "maximum validation", - "schema": {"maximum": 3.0}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 3.0 + }, "tests": [ { "description": "below the maximum is valid", @@ -24,5 +27,34 @@ "valid": true } ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minContains.json b/tests/draft2019-09/minContains.json new file mode 100644 index 00000000..8d3093c4 --- /dev/null +++ b/tests/draft2019-09/minContains.json @@ -0,0 +1,224 @@ +[ + { + "description": "minContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone minContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "zero items still valid against lone minContains", + "data": [], + "valid": true + } + ] + }, + { + "description": "minContains=1 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "no elements match", + "data": [ 2 ], + "valid": false + }, + { + "description": "single element matches, valid minContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "all elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "some elements match, invalid minContains", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "all elements match, valid minContains (exactly as needed)", + "data": [ 1, 1 ], + "valid": true + }, + { + "description": "all elements match, valid minContains (more than needed)", + "data": [ 1, 1, 1 ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ 1, 2, 1 ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "maxContains = minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "maxContains": 2, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "all elements match, invalid maxContains", + "data": [ 1, 1, 1 ], + "valid": false + }, + { + "description": "all elements match, valid maxContains and minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "maxContains < minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "maxContains": 1, + "minContains": 3 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "invalid maxContains", + "data": [ 1, 1, 1 ], + "valid": false + }, + { + "description": "invalid maxContains and minContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, + { + "description": "minContains = 0 with no maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 0 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": true + }, + { + "description": "minContains = 0 makes contains always pass", + "data": [ 2 ], + "valid": true + } + ] + }, + { + "description": "minContains = 0 with maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": {"const": 1}, + "minContains": 0, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": true + }, + { + "description": "not more than maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many", + "data": [ 1, 1 ], + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/minItems.json b/tests/draft2019-09/minItems.json index ed511881..07817cc2 100644 --- a/tests/draft2019-09/minItems.json +++ b/tests/draft2019-09/minItems.json @@ -1,7 +1,10 @@ [ { "description": "minItems validation", - "schema": {"minItems": 1}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minItems": 1 + }, "tests": [ { "description": "longer is valid", @@ -24,5 +27,24 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minItems": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minLength.json b/tests/draft2019-09/minLength.json index 3f09158d..19dec2ca 100644 --- a/tests/draft2019-09/minLength.json +++ b/tests/draft2019-09/minLength.json @@ -1,7 +1,10 @@ [ { "description": "minLength validation", - "schema": {"minLength": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minLength": 2 + }, "tests": [ { "description": "longer is valid", @@ -29,5 +32,24 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minProperties.json b/tests/draft2019-09/minProperties.json index 49a0726e..20e01a9e 100644 --- a/tests/draft2019-09/minProperties.json +++ b/tests/draft2019-09/minProperties.json @@ -1,7 +1,10 @@ [ { "description": "minProperties validation", - "schema": {"minProperties": 1}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minProperties": 1 + }, "tests": [ { "description": "longer is valid", @@ -34,5 +37,24 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minProperties": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/minimum.json b/tests/draft2019-09/minimum.json index 2a9c42b3..afb5f200 100644 --- a/tests/draft2019-09/minimum.json +++ b/tests/draft2019-09/minimum.json @@ -1,7 +1,10 @@ [ { "description": "minimum validation", - "schema": {"minimum": 1.1}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": 1.1 + }, "tests": [ { "description": "above the minimum is valid", @@ -27,7 +30,10 @@ }, { "description": "minimum validation with signed integer", - "schema": {"minimum": -2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": -2 + }, "tests": [ { "description": "negative above the minimum is valid", @@ -45,7 +51,17 @@ "valid": true }, { - "description": "below the minimum is invalid", + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", "data": -3, "valid": false }, diff --git a/tests/draft2019-09/multipleOf.json b/tests/draft2019-09/multipleOf.json index ca3b7618..760a434c 100644 --- a/tests/draft2019-09/multipleOf.json +++ b/tests/draft2019-09/multipleOf.json @@ -1,7 +1,10 @@ [ { "description": "by int", - "schema": {"multipleOf": 2}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 2 + }, "tests": [ { "description": "int by int", @@ -22,7 +25,10 @@ }, { "description": "by number", - "schema": {"multipleOf": 1.5}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 1.5 + }, "tests": [ { "description": "zero is multiple of anything", @@ -43,7 +49,10 @@ }, { "description": "by small number", - "schema": {"multipleOf": 0.0001}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 0.0001 + }, "tests": [ { "description": "0.0075 is multiple of 0.0001", @@ -56,5 +65,33 @@ "valid": false } ] + }, + { + "description": "float division = inf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", "multipleOf": 1e-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/not.json b/tests/draft2019-09/not.json index 98de0eda..62c9af9d 100644 --- a/tests/draft2019-09/not.json +++ b/tests/draft2019-09/not.json @@ -2,6 +2,7 @@ { "description": "not", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "not": {"type": "integer"} }, "tests": [ @@ -20,6 +21,7 @@ { "description": "not multiple types", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "not": {"type": ["integer", "boolean"]} }, "tests": [ @@ -43,6 +45,7 @@ { "description": "not more complex schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "not": { "type": "object", "properties": { @@ -73,6 +76,7 @@ { "description": "forbidden property", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": { "not": {} @@ -94,7 +98,10 @@ }, { "description": "not with boolean schema true", - "schema": {"not": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": true + }, "tests": [ { "description": "any value is invalid", @@ -105,7 +112,10 @@ }, { "description": "not with boolean schema false", - "schema": {"not": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": false + }, "tests": [ { "description": "any value is valid", @@ -113,5 +123,31 @@ "valid": true } ] - } + }, + { + "description": "collect annotations inside a 'not', even if collection is disabled", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them", + "anyOf": [ + true, + { "properties": { "foo": true } } + ], + "unevaluatedProperties": false + } + }, + "tests": [ + { + "description": "unevaluated property", + "data": { "bar": 1 }, + "valid": true + }, + { + "description": "annotations are still collected inside a 'not'", + "data": { "foo": 1 }, + "valid": false + } + ] + } ] diff --git a/tests/draft2019-09/oneOf.json b/tests/draft2019-09/oneOf.json index 57640b7a..9b7a2204 100644 --- a/tests/draft2019-09/oneOf.json +++ b/tests/draft2019-09/oneOf.json @@ -2,6 +2,7 @@ { "description": "oneOf", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "oneOf": [ { "type": "integer" @@ -37,6 +38,7 @@ { "description": "oneOf with base schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "oneOf" : [ { @@ -67,7 +69,10 @@ }, { "description": "oneOf with boolean schemas, all true", - "schema": {"oneOf": [true, true, true]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [true, true, true] + }, "tests": [ { "description": "any value is invalid", @@ -78,7 +83,10 @@ }, { "description": "oneOf with boolean schemas, one true", - "schema": {"oneOf": [true, false, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [true, false, false] + }, "tests": [ { "description": "any value is valid", @@ -89,7 +97,10 @@ }, { "description": "oneOf with boolean schemas, more than one true", - "schema": {"oneOf": [true, true, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [true, true, false] + }, "tests": [ { "description": "any value is invalid", @@ -100,7 +111,10 @@ }, { "description": "oneOf with boolean schemas, all false", - "schema": {"oneOf": [false, false, false]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [false, false, false] + }, "tests": [ { "description": "any value is invalid", @@ -112,6 +126,7 @@ { "description": "oneOf complex types", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "oneOf": [ { "properties": { @@ -153,6 +168,7 @@ { "description": "oneOf with empty schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "oneOf": [ { "type": "number" }, {} @@ -174,6 +190,7 @@ { "description": "oneOf with required", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "object", "oneOf": [ { "required": ["foo", "bar"] }, @@ -202,5 +219,75 @@ "valid": false } ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": ["bar"] + }, + { + "properties": { + "foo": true + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/optional/bignum.json b/tests/draft2019-09/optional/bignum.json index fac275e2..8b064677 100644 --- a/tests/draft2019-09/optional/bignum.json +++ b/tests/draft2019-09/optional/bignum.json @@ -1,30 +1,16 @@ [ { "description": "integer", - "schema": {"type": "integer"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" + }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true - } - ] - }, - { - "description": "number", - "schema": {"type": "number"}, - "tests": [ - { - "description": "a bignum is a number", - "data": 98249283749234923498293171823948729348710298301928331, - "valid": true - } - ] - }, - { - "description": "integer", - "schema": {"type": "integer"}, - "tests": [ + }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, @@ -34,8 +20,16 @@ }, { "description": "number", - "schema": {"type": "number"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "number" + }, "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, @@ -45,7 +39,10 @@ }, { "description": "string", - "schema": {"type": "string"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string" + }, "tests": [ { "description": "a bignum is not a string", @@ -55,8 +52,11 @@ ] }, { - "description": "integer comparison", - "schema": {"maximum": 18446744073709551615}, + "description": "maximum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 18446744073709551615 + }, "tests": [ { "description": "comparison works for high numbers", @@ -68,6 +68,7 @@ { "description": "float comparison with high precision", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "exclusiveMaximum": 972783798187987123879878123.18878137 }, "tests": [ @@ -79,8 +80,11 @@ ] }, { - "description": "integer comparison", - "schema": {"minimum": -18446744073709551615}, + "description": "minimum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": -18446744073709551615 + }, "tests": [ { "description": "comparison works for very negative numbers", @@ -92,6 +96,7 @@ { "description": "float comparison with high precision on negative numbers", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "exclusiveMinimum": -972783798187987123879878123.18878137 }, "tests": [ diff --git a/tests/draft2019-09/optional/content.json b/tests/draft2019-09/optional/content.json deleted file mode 100644 index 3f5a7430..00000000 --- a/tests/draft2019-09/optional/content.json +++ /dev/null @@ -1,77 +0,0 @@ -[ - { - "description": "validation of string-encoded content based on media type", - "schema": { - "contentMediaType": "application/json" - }, - "tests": [ - { - "description": "a valid JSON document", - "data": "{\"foo\": \"bar\"}", - "valid": true - }, - { - "description": "an invalid JSON document", - "data": "{:}", - "valid": false - }, - { - "description": "ignores non-strings", - "data": 100, - "valid": true - } - ] - }, - { - "description": "validation of binary string-encoding", - "schema": { - "contentEncoding": "base64" - }, - "tests": [ - { - "description": "a valid base64 string", - "data": "eyJmb28iOiAiYmFyIn0K", - "valid": true - }, - { - "description": "an invalid base64 string (% is not a valid character)", - "data": "eyJmb28iOi%iYmFyIn0K", - "valid": false - }, - { - "description": "ignores non-strings", - "data": 100, - "valid": true - } - ] - }, - { - "description": "validation of binary-encoded media type documents", - "schema": { - "contentMediaType": "application/json", - "contentEncoding": "base64" - }, - "tests": [ - { - "description": "a valid base64-encoded JSON document", - "data": "eyJmb28iOiAiYmFyIn0K", - "valid": true - }, - { - "description": "a validly-encoded invalid JSON document", - "data": "ezp9Cg==", - "valid": false - }, - { - "description": "an invalid base64 string that is valid JSON", - "data": "{}", - "valid": false - }, - { - "description": "ignores non-strings", - "data": 100, - "valid": true - } - ] - } -] diff --git a/tests/draft2019-09/optional/cross-draft.json b/tests/draft2019-09/optional/cross-draft.json new file mode 100644 index 00000000..efd3f87d --- /dev/null +++ b/tests/draft2019-09/optional/cross-draft.json @@ -0,0 +1,41 @@ +[ + { + "description": "refs to future drafts are processed as future drafts", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "array", + "$ref": "http://localhost:1234/draft2020-12/prefixItems.json" + }, + "tests": [ + { + "description": "first item not a string is invalid", + "comment": "if the implementation is not processing the $ref as a 2020-12 schema, this test will fail", + "data": [1, 2, 3], + "valid": false + }, + { + "description": "first item is a string is valid", + "data": ["a string", 1, 2, 3], + "valid": true + } + ] + }, + { + "description": "refs to historic drafts are processed as historic drafts", + "schema": { + "type": "object", + "allOf": [ + { "properties": { "foo": true } }, + { "$ref": "http://localhost:1234/draft7/ignore-dependentRequired.json" } + ] + }, + "tests": [ + { + "description": "missing bar is valid", + "comment": "if the implementation is not processing the $ref as a draft 7 schema, this test will fail", + "data": {"foo": "any value"}, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/optional/dependencies-compatibility.json b/tests/draft2019-09/optional/dependencies-compatibility.json new file mode 100644 index 00000000..5bfbd058 --- /dev/null +++ b/tests/draft2019-09/optional/dependencies-compatibility.json @@ -0,0 +1,282 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": {"bar": []} + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/ecmascript-regex.json b/tests/draft2019-09/optional/ecmascript-regex.json index d82e0feb..be1059c9 100644 --- a/tests/draft2019-09/optional/ecmascript-regex.json +++ b/tests/draft2019-09/optional/ecmascript-regex.json @@ -1,49 +1,40 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^abc$" }, "tests": [ { - "description": "matches in Python, but should not in jsonschema", - "data": "abc\n", + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", "valid": false }, { - "description": "should match", + "description": "matches", "data": "abc", "valid": true } ] }, { - "description": "ECMA 262 regex converts \\a to ascii BEL", + "description": "ECMA 262 regex converts \\t to horizontal tab", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", - "pattern": "^\\a$" + "pattern": "^\\t$" }, "tests": [ { "description": "does not match", - "data": "\\a", + "data": "\\t", "valid": false }, { "description": "matches", - "data": "\u0007", + "data": "\u0009", "valid": true } ] @@ -51,6 +42,7 @@ { "description": "ECMA 262 regex escapes control codes with \\c and upper letter", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\cC$" }, @@ -70,6 +62,7 @@ { "description": "ECMA 262 regex escapes control codes with \\c and lower letter", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\cc$" }, @@ -89,6 +82,7 @@ { "description": "ECMA 262 \\d matches ascii digits only", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\d$" }, @@ -113,6 +107,7 @@ { "description": "ECMA 262 \\D matches everything but ascii digits", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\D$" }, @@ -137,6 +132,7 @@ { "description": "ECMA 262 \\w matches ascii letters only", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\w$" }, @@ -154,8 +150,9 @@ ] }, { - "description": "ECMA 262 \\w matches everything but ascii letters", + "description": "ECMA 262 \\W matches everything but ascii letters", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\W$" }, @@ -173,8 +170,9 @@ ] }, { - "description": "ECMA 262 \\s matches ascii whitespace only", + "description": "ECMA 262 \\s matches whitespace", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\s$" }, @@ -185,15 +183,61 @@ "valid": true }, { - "description": "latin-1 non-breaking-space does not match (unlike e.g. Python)", + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", "valid": false } ] }, { - "description": "ECMA 262 \\S matches everything but ascii whitespace", + "description": "ECMA 262 \\S matches everything but whitespace", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": "string", "pattern": "^\\S$" }, @@ -204,8 +248,333 @@ "valid": false }, { - "description": "latin-1 non-breaking-space matches (unlike e.g. Python)", + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "\\p{Letter}cole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^\\p{digit}+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, "valid": true } ] diff --git a/tests/draft2019-09/optional/float-overflow.json b/tests/draft2019-09/optional/float-overflow.json new file mode 100644 index 00000000..f5741fac --- /dev/null +++ b/tests/draft2019-09/optional/float-overflow.json @@ -0,0 +1,16 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/optional/format/date-time.json b/tests/draft2019-09/optional/format/date-time.json index dfccee6e..731001d5 100644 --- a/tests/draft2019-09/optional/format/date-time.json +++ b/tests/draft2019-09/optional/format/date-time.json @@ -1,8 +1,41 @@ [ { "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date-time" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid date-time string", "data": "1963-06-19T08:30:06.283185Z", @@ -24,13 +57,43 @@ "valid": true }, { - "description": "a invalid day in date-time string", - "data": "1990-02-31T15:59:60.123-08:00", + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", "valid": false }, { "description": "an invalid offset in date-time string", - "data": "1990-12-31T15:59:60-24:00", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", "valid": false }, { @@ -47,6 +110,26 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/date.json b/tests/draft2019-09/optional/format/date.json index cd23baae..805888c2 100644 --- a/tests/draft2019-09/optional/format/date.json +++ b/tests/draft2019-09/optional/format/date.json @@ -1,15 +1,183 @@ [ { "description": "validation of date strings", - "schema": {"format": "date"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid date string", "data": "1963-06-19", "valid": true }, { - "description": "an invalid date-time string", + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false + }, + { + "description": "an invalid date string", "data": "06/19/1963", "valid": false }, @@ -17,6 +185,61 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350", "valid": false + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1963-06-1เงช", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/duration.json b/tests/draft2019-09/optional/format/duration.json new file mode 100644 index 00000000..00d5f47a --- /dev/null +++ b/tests/draft2019-09/optional/format/duration.json @@ -0,0 +1,136 @@ +[ + { + "description": "validation of duration strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid duration string", + "data": "P4DT12H30M5S", + "valid": true + }, + { + "description": "an invalid duration string", + "data": "PT1D", + "valid": false + }, + { + "description": "no elements present", + "data": "P", + "valid": false + }, + { + "description": "no time elements present", + "data": "P1YT", + "valid": false + }, + { + "description": "no date or time elements present", + "data": "PT", + "valid": false + }, + { + "description": "elements out of order", + "data": "P2D1Y", + "valid": false + }, + { + "description": "missing time separator", + "data": "P1D2H", + "valid": false + }, + { + "description": "time element in the date position", + "data": "P2S", + "valid": false + }, + { + "description": "four years duration", + "data": "P4Y", + "valid": true + }, + { + "description": "zero time, in seconds", + "data": "PT0S", + "valid": true + }, + { + "description": "zero time, in days", + "data": "P0D", + "valid": true + }, + { + "description": "one month duration", + "data": "P1M", + "valid": true + }, + { + "description": "one minute duration", + "data": "PT1M", + "valid": true + }, + { + "description": "one and a half days, in hours", + "data": "PT36H", + "valid": true + }, + { + "description": "one and a half days, in days and hours", + "data": "P1DT12H", + "valid": true + }, + { + "description": "two weeks", + "data": "P2W", + "valid": true + }, + { + "description": "weeks cannot be combined with other units", + "data": "P1Y2W", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "PเงจY", + "valid": false + }, + { + "description": "element without unit", + "data": "P1", + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/format/email.json b/tests/draft2019-09/optional/format/email.json index c837c84b..e6acc32b 100644 --- a/tests/draft2019-09/optional/format/email.json +++ b/tests/draft2019-09/optional/format/email.json @@ -1,8 +1,41 @@ [ { "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "email" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid e-mail address", "data": "joe.bloggs@example.com", @@ -12,6 +45,41 @@ "description": "an invalid e-mail address", "data": "2962", "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/hostname.json b/tests/draft2019-09/optional/format/hostname.json index d22e57db..eac8cac6 100644 --- a/tests/draft2019-09/optional/format/hostname.json +++ b/tests/draft2019-09/optional/format/hostname.json @@ -1,8 +1,41 @@ [ { "description": "validation of host names", - "schema": {"format": "hostname"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "hostname" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid host name", "data": "www.example.com", @@ -27,6 +60,41 @@ "description": "a host name with a component too long", "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/idn-email.json b/tests/draft2019-09/optional/format/idn-email.json index 637409ea..baf01d0a 100644 --- a/tests/draft2019-09/optional/format/idn-email.json +++ b/tests/draft2019-09/optional/format/idn-email.json @@ -1,8 +1,41 @@ [ { "description": "validation of an internationalized e-mail addresses", - "schema": {"format": "idn-email"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-email" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid idn e-mail (example@example.test in Hangul)", "data": "์‹ค๋ก€@์‹ค๋ก€.ํ…Œ์ŠคํŠธ", @@ -12,6 +45,16 @@ "description": "an invalid idn e-mail address", "data": "2962", "valid": false + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/idn-hostname.json b/tests/draft2019-09/optional/format/idn-hostname.json index 3291820e..72f17975 100644 --- a/tests/draft2019-09/optional/format/idn-hostname.json +++ b/tests/draft2019-09/optional/format/idn-hostname.json @@ -1,8 +1,41 @@ [ { "description": "validation of internationalized host names", - "schema": {"format": "idn-hostname"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-hostname" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid host name (example.test in Hangul)", "data": "์‹ค๋ก€.ํ…Œ์ŠคํŠธ", @@ -22,6 +55,252 @@ "description": "a host name with a component too long", "data": "์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€์‹ค๋ก€.ํ…Œ์ŠคํŠธ", "valid": false + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-> $1.00 <--", + "valid": false + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0903hello", + "valid": false + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0300hello", + "valid": false + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0488hello", + "valid": false + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u00df\u03c2\u0f0b\u3007", + "valid": true + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u06fd\u06fe", + "valid": true + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u0640\u07fa", + "valid": false + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b", + "valid": false + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7a", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7", + "valid": false + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7l", + "valid": true + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375S", + "valid": false + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375", + "valid": false + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375\u03b2", + "valid": true + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05d0\u05f3\u05d1", + "valid": true + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05d0\u05f4\u05d1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def\u30fbabc", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u3041", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u30a1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u4e08", + "valid": true + }, + { + "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", + "valid": false + }, + { + "description": "Arabic-Indic digits not 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\u0628", + "valid": true + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "\u06f00", + "valid": true + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u094d\u200d\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "\u0915\u094d\u200c\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "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 } ] } diff --git a/tests/draft2019-09/optional/format/ipv4.json b/tests/draft2019-09/optional/format/ipv4.json index 661148a7..ac1e14c6 100644 --- a/tests/draft2019-09/optional/format/ipv4.json +++ b/tests/draft2019-09/optional/format/ipv4.json @@ -1,8 +1,41 @@ [ { "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv4" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IP address", "data": "192.168.0.1", @@ -27,6 +60,27 @@ "description": "an IP address as an integer", "data": "0x7f000001", "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/ipv6.json b/tests/draft2019-09/optional/format/ipv6.json index f67559b3..04860917 100644 --- a/tests/draft2019-09/optional/format/ipv6.json +++ b/tests/draft2019-09/optional/format/ipv6.json @@ -1,8 +1,41 @@ [ { "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv6" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IPv6 address", "data": "::1", @@ -13,6 +46,16 @@ "data": "12345::", "valid": false }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, { "description": "an IPv6 address with too many components", "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", @@ -22,6 +65,146 @@ "description": "an IPv6 address containing illegal characters", "data": "::laptop", "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/iri-reference.json b/tests/draft2019-09/optional/format/iri-reference.json index 1fd779c2..69142102 100644 --- a/tests/draft2019-09/optional/format/iri-reference.json +++ b/tests/draft2019-09/optional/format/iri-reference.json @@ -1,8 +1,41 @@ [ { "description": "validation of IRI References", - "schema": {"format": "iri-reference"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri-reference" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IRI", "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", diff --git a/tests/draft2019-09/optional/format/iri.json b/tests/draft2019-09/optional/format/iri.json index ed54094c..ad4c79e8 100644 --- a/tests/draft2019-09/optional/format/iri.json +++ b/tests/draft2019-09/optional/format/iri.json @@ -1,15 +1,48 @@ [ { "description": "validation of IRIs", - "schema": {"format": "iri"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IRI with anchor tag", "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", "valid": true }, { - "description": "a valid IRI with anchor tag and parantheses", + "description": "a valid IRI with anchor tag and parentheses", "data": "http://ฦ’รธรธ.com/blah_(wรฎkรฏpรฉdiรฅ)_blah#รŸitรฉ-1", "valid": true }, diff --git a/tests/draft2019-09/optional/format/json-pointer.json b/tests/draft2019-09/optional/format/json-pointer.json index 65c2f064..39f1cc92 100644 --- a/tests/draft2019-09/optional/format/json-pointer.json +++ b/tests/draft2019-09/optional/format/json-pointer.json @@ -1,8 +1,41 @@ [ { "description": "validation of JSON-pointers (JSON String Representation)", - "schema": {"format": "json-pointer"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "json-pointer" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid JSON-pointer", "data": "/foo/bar~0/baz~1/%a", diff --git a/tests/draft2019-09/optional/format/regex.json b/tests/draft2019-09/optional/format/regex.json index d99d021e..da32401c 100644 --- a/tests/draft2019-09/optional/format/regex.json +++ b/tests/draft2019-09/optional/format/regex.json @@ -1,8 +1,41 @@ [ { "description": "validation of regular expressions", - "schema": {"format": "regex"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "regex" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid regular expression", "data": "([abc])+\\s+$", diff --git a/tests/draft2019-09/optional/format/relative-json-pointer.json b/tests/draft2019-09/optional/format/relative-json-pointer.json index ceeb743a..ba97d2a1 100644 --- a/tests/draft2019-09/optional/format/relative-json-pointer.json +++ b/tests/draft2019-09/optional/format/relative-json-pointer.json @@ -1,15 +1,48 @@ [ { "description": "validation of Relative JSON Pointers (RJP)", - "schema": {"format": "relative-json-pointer"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "relative-json-pointer" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid upwards RJP", "data": "1", "valid": true }, { - "description": "a valid downwards RJP", + "description": "a valid downwards RJP", "data": "0/foo/bar", "valid": true }, @@ -27,6 +60,41 @@ "description": "an invalid RJP that is a valid JSON Pointer", "data": "/foo/bar", "valid": false + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true } ] } diff --git a/tests/draft2019-09/optional/format/time.json b/tests/draft2019-09/optional/format/time.json index 4ec8a01a..dadaae6a 100644 --- a/tests/draft2019-09/optional/format/time.json +++ b/tests/draft2019-09/optional/format/time.json @@ -1,15 +1,203 @@ [ { "description": "validation of time strings", - "schema": {"format": "time"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "time" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid time string", + "data": "08:30:06Z", + "valid": true + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true + }, + { + "description": "a valid time string with precise second fraction", "data": "08:30:06.283185Z", "valid": true }, { - "description": "an invalid time string", + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false + }, + { + "description": "an invalid offset indicator", "data": "08:30:06 PST", "valid": false }, @@ -17,6 +205,31 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "01:01:01,1111", "valid": false + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ:00:00Z", + "valid": false + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/unknown.json b/tests/draft2019-09/optional/format/unknown.json new file mode 100644 index 00000000..c89f7303 --- /dev/null +++ b/tests/draft2019-09/optional/format/unknown.json @@ -0,0 +1,46 @@ +[ + { + "description": "unknown format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "unknown" + }, + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/optional/format/uri-reference.json b/tests/draft2019-09/optional/format/uri-reference.json index e4c9eef6..2c49da63 100644 --- a/tests/draft2019-09/optional/format/uri-reference.json +++ b/tests/draft2019-09/optional/format/uri-reference.json @@ -1,8 +1,41 @@ [ { "description": "validation of URI References", - "schema": {"format": "uri-reference"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-reference" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid URI", "data": "http://foo.bar/?baz=qux#quux", diff --git a/tests/draft2019-09/optional/format/uri-template.json b/tests/draft2019-09/optional/format/uri-template.json index 33ab76ee..f4aee104 100644 --- a/tests/draft2019-09/optional/format/uri-template.json +++ b/tests/draft2019-09/optional/format/uri-template.json @@ -1,8 +1,41 @@ [ { "description": "format: uri-template", - "schema": {"format": "uri-template"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-template" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid uri-template", "data": "http://example.com/dictionary/{term:1}/{term}", diff --git a/tests/draft2019-09/optional/format/uri.json b/tests/draft2019-09/optional/format/uri.json index 25cc40c8..ad67840d 100644 --- a/tests/draft2019-09/optional/format/uri.json +++ b/tests/draft2019-09/optional/format/uri.json @@ -1,15 +1,48 @@ [ { "description": "validation of URIs", - "schema": {"format": "uri"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri" + }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid URL with anchor tag", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { - "description": "a valid URL with anchor tag and parantheses", + "description": "a valid URL with anchor tag and parentheses", "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", "valid": true }, @@ -97,6 +130,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/uuid.json b/tests/draft2019-09/optional/format/uuid.json new file mode 100644 index 00000000..dc6fb7e0 --- /dev/null +++ b/tests/draft2019-09/optional/format/uuid.json @@ -0,0 +1,116 @@ +[ + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "all upper-case", + "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", + "valid": true + }, + { + "description": "all lower-case", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", + "valid": true + }, + { + "description": "mixed case", + "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", + "valid": true + }, + { + "description": "all zeroes is valid", + "data": "00000000-0000-0000-0000-000000000000", + "valid": true + }, + { + "description": "wrong length", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": false + }, + { + "description": "missing section", + "data": "2eb8aa08-aa98-11ea-73b441d16380", + "valid": false + }, + { + "description": "bad characters (not hex)", + "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", + "valid": false + }, + { + "description": "no dashes", + "data": "2eb8aa08aa9811eab4aa73b441d16380", + "valid": false + }, + { + "description": "too few dashes", + "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", + "valid": false + }, + { + "description": "too many dashes", + "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", + "valid": false + }, + { + "description": "dashes in the wrong spot", + "data": "2eb8aa08aa9811eab4aa73b441d16380----", + "valid": false + }, + { + "description": "valid version 4", + "data": "98d80576-482e-427f-8434-7f86890ab222", + "valid": true + }, + { + "description": "valid version 5", + "data": "99c17cbb-656f-564a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 6", + "data": "99c17cbb-656f-664a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 15", + "data": "99c17cbb-656f-f64a-940f-1a4568f03487", + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/optional/no-schema.json b/tests/draft2019-09/optional/no-schema.json new file mode 100644 index 00000000..676e6b53 --- /dev/null +++ b/tests/draft2019-09/optional/no-schema.json @@ -0,0 +1,26 @@ +[ + { + "description": "validation without $schema", + "comment": "minLength is the same across all drafts", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "a 3-character string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a 1-character string is not valid", + "data": "a", + "valid": false + }, + { + "description": "a non-string is valid", + "data": 5, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/optional/non-bmp-regex.json b/tests/draft2019-09/optional/non-bmp-regex.json new file mode 100644 index 00000000..ef250006 --- /dev/null +++ b/tests/draft2019-09/optional/non-bmp-regex.json @@ -0,0 +1,86 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^๐Ÿฒ*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/refOfUnknownKeyword.json b/tests/draft2019-09/optional/refOfUnknownKeyword.json new file mode 100644 index 00000000..eee1c33e --- /dev/null +++ b/tests/draft2019-09/optional/refOfUnknownKeyword.json @@ -0,0 +1,46 @@ +[ + { + "description": "reference of a root arbitrary keyword ", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unknown-keyword": {"type": "integer"}, + "properties": { + "bar": {"$ref": "#/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "reference of an arbitrary keyword of a sub-schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {"unknown-keyword": {"type": "integer"}}, + "bar": {"$ref": "#/properties/foo/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/optional/zeroTerminatedFloats.json b/tests/draft2019-09/optional/zeroTerminatedFloats.json deleted file mode 100644 index 1bcdf960..00000000 --- a/tests/draft2019-09/optional/zeroTerminatedFloats.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "description": "some languages do not distinguish between different types of numeric value", - "schema": { - "type": "integer" - }, - "tests": [ - { - "description": "a float without fractional part is an integer", - "data": 1.0, - "valid": true - } - ] - } -] diff --git a/tests/draft2019-09/pattern.json b/tests/draft2019-09/pattern.json index 25e72997..cfb87744 100644 --- a/tests/draft2019-09/pattern.json +++ b/tests/draft2019-09/pattern.json @@ -1,7 +1,10 @@ [ { "description": "pattern validation", - "schema": {"pattern": "^a*$"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^a*$" + }, "tests": [ { "description": "a matching pattern is valid", @@ -14,15 +17,43 @@ "valid": false }, { - "description": "ignores non-strings", + "description": "ignores booleans", "data": true, "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true } ] }, { "description": "pattern is not anchored", - "schema": {"pattern": "a+"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "a+" + }, "tests": [ { "description": "matches a substring", diff --git a/tests/draft2019-09/patternProperties.json b/tests/draft2019-09/patternProperties.json index 1d04a167..354bb48b 100644 --- a/tests/draft2019-09/patternProperties.json +++ b/tests/draft2019-09/patternProperties.json @@ -3,6 +3,7 @@ "description": "patternProperties validates properties matching a regex", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "patternProperties": { "f.*o": {"type": "integer"} } @@ -48,6 +49,7 @@ { "description": "multiple simultaneous patternProperties are validated", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "patternProperties": { "a*": {"type": "integer"}, "aaa*": {"maximum": 20} @@ -89,6 +91,7 @@ { "description": "regexes are not anchored by default and are case sensitive", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "patternProperties": { "[0-9]{2,}": { "type": "boolean" }, "X_": { "type": "string" } @@ -120,6 +123,7 @@ { "description": "patternProperties with boolean schemas", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "patternProperties": { "f.*": true, "b.*": false @@ -141,11 +145,32 @@ "data": {"foo": 1, "bar": 2}, "valid": false }, + { + "description": "object with a property matching both true and false is invalid", + "data": {"foobar":1}, + "valid": false + }, { "description": "empty object is valid", "data": {}, "valid": true } ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/properties.json b/tests/draft2019-09/properties.json index b86c1819..a53429c5 100644 --- a/tests/draft2019-09/properties.json +++ b/tests/draft2019-09/properties.json @@ -2,6 +2,7 @@ { "description": "object properties validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {"type": "integer"}, "bar": {"type": "string"} @@ -44,6 +45,7 @@ "description": "properties, patternProperties, additionalProperties interaction", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {"type": "array", "maxItems": 3}, "bar": {"type": "array"} @@ -97,6 +99,7 @@ { "description": "properties with boolean schema", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": true, "bar": false @@ -128,6 +131,7 @@ { "description": "properties with escaped characters", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo\nbar": {"type": "number"}, "foo\"bar": {"type": "number"}, @@ -163,5 +167,76 @@ "valid": false } ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/propertyNames.json b/tests/draft2019-09/propertyNames.json index 8423690d..b7fecbf7 100644 --- a/tests/draft2019-09/propertyNames.json +++ b/tests/draft2019-09/propertyNames.json @@ -2,6 +2,7 @@ { "description": "propertyNames validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "propertyNames": {"maxLength": 3} }, "tests": [ @@ -43,9 +44,42 @@ } ] }, + { + "description": "propertyNames validation with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/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": {"propertyNames": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": true + }, "tests": [ { "description": "object with any properties is valid", @@ -61,7 +95,10 @@ }, { "description": "propertyNames with boolean schema false", - "schema": {"propertyNames": false}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": false + }, "tests": [ { "description": "object with any properties is invalid", diff --git a/tests/draft2019-09/recursiveRef.json b/tests/draft2019-09/recursiveRef.json new file mode 100644 index 00000000..22b47e74 --- /dev/null +++ b/tests/draft2019-09/recursiveRef.json @@ -0,0 +1,408 @@ +[ + { + "description": "$recursiveRef without $recursiveAnchor works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { "$recursiveRef": "#" } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": { "foo": { "foo": false } }, + "valid": true + }, + { + "description": "mismatch", + "data": { "bar": false }, + "valid": false + }, + { + "description": "recursive mismatch", + "data": { "foo": { "bar": false } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef without using nesting", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef2/schema.json", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, no match", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with nesting", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef3/schema.json", + "$recursiveAnchor": true, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer now matches as a property value", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, properties match with $recursiveRef", + "data": { "foo": { "bar": 1 } }, + "valid": true + } + ] + }, + { + "description": "$recursiveRef with $recursiveAnchor: false works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef4/schema.json", + "$recursiveAnchor": false, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, integer does not match as a property value", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef5/schema.json", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { "$recursiveRef": "#" } + } + ] + } + }, + "anyOf": [ + { "type": "integer" }, + { "$ref": "#/$defs/myobject" } + ] + }, + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true + }, + { + "description": "single level match", + "data": { "foo": "hi" }, + "valid": true + }, + { + "description": "integer does not match as a property value", + "data": { "foo": 1 }, + "valid": false + }, + { + "description": "two levels, properties match with inner definition", + "data": { "foo": { "bar": "hi" } }, + "valid": true + }, + { + "description": "two levels, integer does not match as a property value", + "data": { "foo": { "bar": 1 } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the initial target schema resource", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef6/base.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "boolean" }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/draft2019-09/recursiveRef6/inner.json", + "$comment": "there is no $recursiveAnchor: true here, so we do NOT recurse to the base", + "anyOf": [ + { "type": "integer" }, + { "type": "object", "additionalProperties": { "$recursiveRef": "#" } } + ] + } + } + ] + }, + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { "foo": true }, + "valid": false + }, + { + "description": "leaf node matches: recursion uses the inner schema", + "data": { "foo": { "bar": 1 } }, + "valid": true + }, + { + "description": "leaf node does not match: recursion uses the inner schema", + "data": { "foo": { "bar": true } }, + "valid": false + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the outer schema resource", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef7/base.json", + "anyOf": [ + { "type": "boolean" }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/draft2019-09/recursiveRef7/inner.json", + "$recursiveAnchor": true, + "anyOf": [ + { "type": "integer" }, + { "type": "object", "additionalProperties": { "$recursiveRef": "#" } } + ] + } + } + ] + }, + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { "foo": true }, + "valid": false + }, + { + "description": "leaf node matches: recursion only uses inner schema", + "data": { "foo": { "bar": 1 } }, + "valid": true + }, + { + "description": "leaf node does not match: recursion only uses inner schema", + "data": { "foo": { "bar": true } }, + "valid": false + } + ] + }, + { + "description": "multiple dynamic paths to the $recursiveRef keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/recursiveRef8_main.json", + "$defs": { + "inner": { + "$id": "recursiveRef8_inner.json", + "$recursiveAnchor": true, + "title": "inner", + "additionalProperties": { + "$recursiveRef": "#" + } + } + }, + "if": { + "propertyNames": { + "pattern": "^[a-m]" + } + }, + "then": { + "title": "any type of node", + "$id": "recursiveRef8_anyLeafNode.json", + "$recursiveAnchor": true, + "$ref": "recursiveRef8_inner.json" + }, + "else": { + "title": "integer node", + "$id": "recursiveRef8_integerNode.json", + "$recursiveAnchor": true, + "type": [ "object", "integer" ], + "$ref": "recursiveRef8_inner.json" + } + }, + "tests": [ + { + "description": "recurse to anyLeafNode - floats are allowed", + "data": { "alpha": 1.1 }, + "valid": true + }, + { + "description": "recurse to integerNode - floats are not allowed", + "data": { "november": 1.1 }, + "valid": false + } + ] + }, + { + "description": "dynamic $recursiveRef destination (not predictable at schema compile time)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/main.json", + "$defs": { + "inner": { + "$id": "inner.json", + "$recursiveAnchor": true, + "title": "inner", + "additionalProperties": { + "$recursiveRef": "#" + } + } + + }, + "if": { "propertyNames": { "pattern": "^[a-m]" } }, + "then": { + "title": "any type of node", + "$id": "anyLeafNode.json", + "$recursiveAnchor": true, + "$ref": "main.json#/$defs/inner" + }, + "else": { + "title": "integer node", + "$id": "integerNode.json", + "$recursiveAnchor": true, + "type": [ "object", "integer" ], + "$ref": "main.json#/$defs/inner" + } + }, + "tests": [ + { + "description": "numeric node", + "data": { "alpha": 1.1 }, + "valid": true + }, + { + "description": "integer node", + "data": { "november": 1.1 }, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index 285de55c..7d850414 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -2,6 +2,7 @@ { "description": "root pointer ref", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {"$ref": "#"} }, @@ -33,6 +34,7 @@ { "description": "relative pointer ref to object", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {"type": "integer"}, "bar": {"$ref": "#/properties/foo"} @@ -54,6 +56,7 @@ { "description": "relative pointer ref to array", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "items": [ {"type": "integer"}, {"$ref": "#/items/0"} @@ -75,13 +78,16 @@ { "description": "escaped pointer ref", "schema": { - "tilda~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilda": {"$ref": "#/tilda~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/$defs/tilde~0field"}, + "slash": {"$ref": "#/$defs/slash~1field"}, + "percent": {"$ref": "#/$defs/percent%25field"} } }, "tests": [ @@ -91,8 +97,8 @@ "valid": false }, { - "description": "tilda invalid", - "data": {"tilda": "aoeu"}, + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, "valid": false }, { @@ -106,8 +112,8 @@ "valid": true }, { - "description": "tilda valid", - "data": {"tilda": 123}, + "description": "tilde valid", + "data": {"tilde": 123}, "valid": true }, { @@ -120,6 +126,7 @@ { "description": "nested refs", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$defs": { "a": {"type": "integer"}, "b": {"$ref": "#/$defs/a"}, @@ -141,8 +148,9 @@ ] }, { - "description": "ref overrides any sibling keywords", + "description": "ref applies alongside sibling keywords", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$defs": { "reffed": { "type": "array" @@ -157,14 +165,14 @@ }, "tests": [ { - "description": "ref valid", + "description": "ref valid, maxItems valid", "data": { "foo": [] }, "valid": true }, { - "description": "ref valid, maxItems ignored", - "data": { "foo": [ 1, 2, 3] }, - "valid": true + "description": "ref valid, maxItems invalid", + "data": { "foo": [1, 2, 3] }, + "valid": false }, { "description": "ref invalid", @@ -175,7 +183,10 @@ }, { "description": "remote ref, containing refs itself", - "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, "tests": [ { "description": "remote ref valid", @@ -192,6 +203,7 @@ { "description": "property named $ref that is not a reference", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "$ref": {"type": "string"} } @@ -209,9 +221,36 @@ } ] }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "$ref": {"$ref": "#/$defs/is-string"} + }, + "$defs": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, { "description": "$ref to boolean schema true", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "#/$defs/bool", "$defs": { "bool": true @@ -228,6 +267,7 @@ { "description": "$ref to boolean schema false", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "$ref": "#/$defs/bool", "$defs": { "bool": false @@ -244,7 +284,8 @@ { "description": "Recursive references between schemas", "schema": { - "$id": "http://localhost:1234/tree", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/tree", "description": "tree of nodes", "type": "object", "properties": { @@ -257,7 +298,7 @@ "required": ["meta", "nodes"], "$defs": { "node": { - "$id": "http://localhost:1234/node", + "$id": "http://localhost:1234/draft2019-09/node", "description": "node", "type": "object", "properties": { @@ -271,7 +312,7 @@ "tests": [ { "description": "valid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -300,7 +341,7 @@ }, { "description": "invalid tree", - "data": { + "data": { "meta": "root", "nodes": [ { @@ -332,6 +373,7 @@ { "description": "refs with quote", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo\"bar": {"$ref": "#/$defs/foo%22bar"} }, @@ -355,5 +397,663 @@ "valid": false } ] - } + }, + { + "description": "ref creates new scope when adjacent to keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "A": { + "unevaluatedProperties": false + } + }, + "properties": { + "prop1": { + "type": "string" + } + }, + "$ref": "#/$defs/A" + }, + "tests": [ + { + "description": "referenced subschema doesn't see annotations from properties", + "data": { + "prop1": "match" + }, + "valid": false + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/$defs/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/$defs/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-relative-uri-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-refs-absolute-uris-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/a.json", + "$defs": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "$defs": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft2019-09/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id1-int.json", + "$id": "/draft2019-09/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft2019-09/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id2/base.json#/$defs/bigint; another valid uri for this location: https://example.com/ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id2#/$defs/smallint; another valid uri for this location: https://example.com/ref-and-id2/#bigint", + "$id": "/draft2019-09/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 ยง2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 ยง2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 ยง2.3.2", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "$defs": { + "bar": { + "$anchor": "something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN ref with nested pointer ref", + "schema": { + "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "foo": { + "$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": {"bar": {"type": "string"}}, + "$ref": "#/$defs/bar" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": "bar", + "valid": true + }, + { + "description": "a non-string is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "$ref": "http://example.com/ref/if", + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to then", + "schema": { + "$ref": "http://example.com/ref/then", + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to else", + "schema": { + "$ref": "http://example.com/ref/else", + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "$defs": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "$ref": "/absref/foobar.json" + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 9cadc926..79107f9e 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -1,7 +1,10 @@ [ { "description": "remote ref", - "schema": {"$ref": "http://localhost:1234/integer.json"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/integer.json" + }, "tests": [ { "description": "remote ref valid", @@ -17,7 +20,10 @@ }, { "description": "fragment within remote ref", - "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/integer" + }, "tests": [ { "description": "remote fragment valid", @@ -31,10 +37,30 @@ } ] }, + { + "description": "anchor within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/locationIndependentIdentifier.json#foo" + }, + "tests": [ + { + "description": "remote anchor valid", + "data": 1, + "valid": true + }, + { + "description": "remote anchor invalid", + "data": "a", + "valid": false + } + ] + }, { "description": "ref within remote ref", "schema": { - "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/subSchemas-defs.json#/$defs/refToInteger" }, "tests": [ { @@ -52,9 +78,10 @@ { "description": "base URI change", "schema": { - "$id": "http://localhost:1234/", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -74,12 +101,13 @@ { "description": "base URI change - change folder", "schema": { - "$id": "http://localhost:1234/scope_change_defs1.json", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/scope_change_defs1.json", "type" : "object", - "properties": {"list": {"$ref": "#/$defs/baz"}}, + "properties": {"list": {"$ref": "baseUriChangeFolder/"}}, "$defs": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -101,12 +129,13 @@ { "description": "base URI change - change folder in subschema", "schema": { - "$id": "http://localhost:1234/scope_change_defs2.json", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/scope_change_defs2.json", "type" : "object", - "properties": {"list": {"$ref": "#/$defs/baz/$defs/bar"}}, + "properties": {"list": {"$ref": "baseUriChangeFolderInSubschema/#/$defs/bar"}}, "$defs": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "$defs": { "bar": { "type": "array", @@ -132,7 +161,8 @@ { "description": "root ref in remote ref", "schema": { - "$id": "http://localhost:1234/object", + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/object", "type": "object", "properties": { "name": {"$ref": "name-defs.json#/$defs/orNull"} @@ -163,5 +193,122 @@ "valid": false } ] + }, + { + "description": "remote ref with ref to defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/schema-remote-ref-ref-defs1.json", + "$ref": "ref-and-defs.json" + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/locationIndependentIdentifier.json#/$defs/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different $id", + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different URN $id", + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with nested absolute ref", + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/required.json b/tests/draft2019-09/required.json index abf18f34..bca98a98 100644 --- a/tests/draft2019-09/required.json +++ b/tests/draft2019-09/required.json @@ -2,6 +2,7 @@ { "description": "required validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {}, "bar": {} @@ -39,6 +40,7 @@ { "description": "required default validation", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {} } @@ -54,6 +56,7 @@ { "description": "required with empty array", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "properties": { "foo": {} }, @@ -70,6 +73,7 @@ { "description": "required with escaped characters", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "required": [ "foo\nbar", "foo\"bar", @@ -101,5 +105,54 @@ "valid": false } ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "required": ["__proto__", "toString", "constructor"] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/type.json b/tests/draft2019-09/type.json index ea33b182..92c6be89 100644 --- a/tests/draft2019-09/type.json +++ b/tests/draft2019-09/type.json @@ -1,13 +1,21 @@ [ { "description": "integer type matches integers", - "schema": {"type": "integer"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" + }, "tests": [ { "description": "an integer is an integer", "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true + }, { "description": "a float is not an integer", "data": 1.1, @@ -47,13 +55,21 @@ }, { "description": "number type matches numbers", - "schema": {"type": "number"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "number" + }, "tests": [ { "description": "an integer is a number", "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, { "description": "a float is a number", "data": 1.1, @@ -93,7 +109,10 @@ }, { "description": "string type matches strings", - "schema": {"type": "string"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string" + }, "tests": [ { "description": "1 is not a string", @@ -144,7 +163,10 @@ }, { "description": "object type matches objects", - "schema": {"type": "object"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object" + }, "tests": [ { "description": "an integer is not an object", @@ -185,7 +207,10 @@ }, { "description": "array type matches arrays", - "schema": {"type": "array"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "array" + }, "tests": [ { "description": "an integer is not an array", @@ -226,7 +251,10 @@ }, { "description": "boolean type matches booleans", - "schema": {"type": "boolean"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "boolean" + }, "tests": [ { "description": "an integer is not a boolean", @@ -282,7 +310,10 @@ }, { "description": "null type matches only the null object", - "schema": {"type": "null"}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "null" + }, "tests": [ { "description": "an integer is not null", @@ -338,7 +369,10 @@ }, { "description": "multiple types can be specified in an array", - "schema": {"type": ["integer", "string"]}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": ["integer", "string"] + }, "tests": [ { "description": "an integer is valid", @@ -380,6 +414,7 @@ { "description": "type as array with one item", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": ["string"] }, "tests": [ @@ -398,6 +433,7 @@ { "description": "type: array or object", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": ["array", "object"] }, "tests": [ @@ -431,6 +467,7 @@ { "description": "type: array, object or null", "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", "type": ["array", "object", "null"] }, "tests": [ diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json new file mode 100644 index 00000000..53565a0b --- /dev/null +++ b/tests/draft2019-09/unevaluatedItems.json @@ -0,0 +1,627 @@ +[ + { + "description": "unevaluatedItems true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": true + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": { "type": "string" } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with valid unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with invalid unevaluated items", + "data": [42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with uniform items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { "type": "string" }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", "bar"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "type": "string" } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with items and additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "type": "string" } + ], + "additionalItems": true, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with ignored additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": {"type": "number"}, + "unevaluatedItems": {"type": "string"} + }, + "tests": [ + { + "description": "invalid under unevaluatedItems", + "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema", + "data": ["foo", 1], + "valid": false + }, + { + "description": "all valid under unevaluatedItems", + "data": ["foo", "bar", "baz"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with ignored applicator additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ { "additionalItems": { "type": "number" } } ], + "unevaluatedItems": {"type": "string"} + }, + "tests": [ + { + "description": "invalid under unevaluatedItems", + "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema", + "data": ["foo", 1], + "valid": false + }, + { + "description": "all valid under unevaluatedItems", + "data": ["foo", "bar", "baz"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with nested tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "type": "string" } + ], + "allOf": [ + { + "items": [ + true, + { "type": "number" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", 42], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", 42, true], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": {"type": "boolean"}, + "anyOf": [ + { "items": {"type": "string"} }, + true + ] + }, + "tests": [ + { + "description": "with only (valid) additional items", + "data": [true, false], + "valid": true + }, + { + "description": "with no additional items", + "data": ["yes", "no"], + "valid": true + }, + { + "description": "with invalid additional item", + "data": ["yes", false], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested items and additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { "type": "string" } + ], + "additionalItems": true + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with nested unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { "type": "string" } + ] + }, + { "unevaluatedItems": true } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "const": "foo" } + ], + "anyOf": [ + { + "items": [ + true, + { "const": "bar" } + ] + }, + { + "items": [ + true, + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when one schema matches and has no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "when one schema matches and has unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + }, + { + "description": "when two schemas match and has no unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "when two schemas match and has unevaluated items", + "data": ["foo", "bar", "baz", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "const": "foo" } + ], + "oneOf": [ + { + "items": [ + true, + { "const": "bar" } + ] + }, + { + "items": [ + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with not", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { "const": "foo" } + ], + "not": { + "not": { + "items": [ + true, + { "const": "bar" } + ] + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ { "const": "foo" } ], + "if": { + "items": [ + true, + { "const": "bar" } + ] + }, + "then": { + "items": [ + true, + true, + { "const": "then" } + ] + }, + "else": { + "items": [ + true, + true, + true, + { "const": "else" } + ] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when if matches and it has no unevaluated items", + "data": ["foo", "bar", "then"], + "valid": true + }, + { + "description": "when if matches and it has unevaluated items", + "data": ["foo", "bar", "then", "else"], + "valid": false + }, + { + "description": "when if doesn't match and it has no unevaluated items", + "data": ["foo", 42, 42, "else"], + "valid": true + }, + { + "description": "when if doesn't match and it has unevaluated items", + "data": ["foo", 42, 42, "else", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [true], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#/$defs/bar", + "items": [ + { "type": "string" } + ], + "unevaluatedItems": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ true ] + }, + { "unevaluatedItems": false } + ] + }, + "tests": [ + { + "description": "always fails", + "data": [ 1 ], + "valid": false + } + ] + }, + { + "description": "item is evaluated in an uncle schema to unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "items": [ + { "type": "string" } + ], + "unevaluatedItems": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "items": [ + true, + { "type": "string" } + ] + } + } + } + ] + }, + "tests": [ + { + "description": "no extra items", + "data": { + "foo": [ + "test" + ] + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": [ + "test", + "test" + ] + }, + "valid": false + } + ] + }, + { + "description": "non-array instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "items": [{"const": "a"}] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": [ "a" ], + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": [ "b" ], + "valid": false + } + + ] + } +] diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json new file mode 100644 index 00000000..a6cce8bb --- /dev/null +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -0,0 +1,1475 @@ +[ + { + "description": "unevaluatedProperties true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": { + "type": "string", + "minLength": 3 + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with valid unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with invalid unevaluated properties", + "data": { + "foo": "fo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "additionalProperties": true, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "properties": { + "bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "patternProperties": { + "^bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "additionalProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": { + "type": "string", + "maxLength": 2 + } + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "anyOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + }, + { + "properties": { + "quux": { "const": "quux" } + }, + "required": ["quux"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when one matches and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when one matches and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "not-baz" + }, + "valid": false + }, + { + "description": "when two match and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": true + }, + { + "description": "when two match and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz", + "quux": "not-quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "oneOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "quux": "quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with not", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "not": { + "not": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, then not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": false + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, else not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with dependentSchemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [true], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "$ref": "#/$defs/bar", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins (reverse order)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "unevaluatedProperties": false + }, + { + "properties": { + "foo": true + } + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, true with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, false with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "unevaluatedProperties": true + }, + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "property is evaluated in an uncle schema to unevaluatedProperties", + "comment": "see https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "properties": { + "faz": { + "type": "string" + } + } + } + } + } + ] + }, + "tests": [ + { + "description": "no extra properties", + "data": { + "foo": { + "bar": "test" + } + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": { + "bar": "test", + "faz": "test" + } + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, allOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + }, + "unevaluatedProperties": false + } + ], + "anyOf": [ + { + "properties": { + "bar": true + } + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, anyOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + } + ], + "anyOf": [ + { + "properties": { + "bar": true + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties + single cyclic ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "x": { "$ref": "#" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is valid", + "data": {}, + "valid": true + }, + { + "description": "Single is valid", + "data": { "x": {} }, + "valid": true + }, + { + "description": "Unevaluated on 1st level is invalid", + "data": { "x": {}, "y": {} }, + "valid": false + }, + { + "description": "Nested is valid", + "data": { "x": { "x": {} } }, + "valid": true + }, + { + "description": "Unevaluated on 2nd level is invalid", + "data": { "x": { "x": {}, "y": {} } }, + "valid": false + }, + { + "description": "Deep nested is valid", + "data": { "x": { "x": { "x": {} } } }, + "valid": true + }, + { + "description": "Unevaluated on 3rd level is invalid", + "data": { "x": { "x": { "x": {}, "y": {} } } }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties + ref inside allOf / oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "one": { + "properties": { "a": true } + }, + "two": { + "required": ["x"], + "properties": { "x": true } + } + }, + "allOf": [ + { "$ref": "#/$defs/one" }, + { "properties": { "b": true } }, + { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { + "required": ["y"], + "properties": { "y": true } + } + ] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid (no x or y)", + "data": {}, + "valid": false + }, + { + "description": "a and b are invalid (no x or y)", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "x and y are invalid", + "data": { "x": 1, "y": 1 }, + "valid": false + }, + { + "description": "a and x are valid", + "data": { "a": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and y are valid", + "data": { "a": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x are valid", + "data": { "a": 1, "b": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and b and y are valid", + "data": { "a": 1, "b": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x and y are invalid", + "data": { "a": 1, "b": 1, "x": 1, "y": 1 }, + "valid": false + } + ] + }, + { + "description": "dynamic evalation inside nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "one": { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { "required": ["b"], "properties": { "b": true } }, + { "required": ["xx"], "patternProperties": { "x": true } }, + { "required": ["all"], "unevaluatedProperties": true } + ] + }, + "two": { + "oneOf": [ + { "required": ["c"], "properties": { "c": true } }, + { "required": ["d"], "properties": { "d": true } } + ] + } + }, + "oneOf": [ + { "$ref": "#/$defs/one" }, + { "required": ["a"], "properties": { "a": true } } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid", + "data": {}, + "valid": false + }, + { + "description": "a is valid", + "data": { "a": 1 }, + "valid": true + }, + { + "description": "b is valid", + "data": { "b": 1 }, + "valid": true + }, + { + "description": "c is valid", + "data": { "c": 1 }, + "valid": true + }, + { + "description": "d is valid", + "data": { "d": 1 }, + "valid": true + }, + { + "description": "a + b is invalid", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "a + c is invalid", + "data": { "a": 1, "c": 1 }, + "valid": false + }, + { + "description": "a + d is invalid", + "data": { "a": 1, "d": 1 }, + "valid": false + }, + { + "description": "b + c is invalid", + "data": { "b": 1, "c": 1 }, + "valid": false + }, + { + "description": "b + d is invalid", + "data": { "b": 1, "d": 1 }, + "valid": false + }, + { + "description": "c + d is invalid", + "data": { "c": 1, "d": 1 }, + "valid": false + }, + { + "description": "xx is valid", + "data": { "xx": 1 }, + "valid": true + }, + { + "description": "xx + foox is valid", + "data": { "xx": 1, "foox": 1 }, + "valid": true + }, + { + "description": "xx + foo is invalid", + "data": { "xx": 1, "foo": 1 }, + "valid": false + }, + { + "description": "xx + a is invalid", + "data": { "xx": 1, "a": 1 }, + "valid": false + }, + { + "description": "xx + b is invalid", + "data": { "xx": 1, "b": 1 }, + "valid": false + }, + { + "description": "xx + c is invalid", + "data": { "xx": 1, "c": 1 }, + "valid": false + }, + { + "description": "xx + d is invalid", + "data": { "xx": 1, "d": 1 }, + "valid": false + }, + { + "description": "all is valid", + "data": { "all": 1 }, + "valid": true + }, + { + "description": "all + foo is valid", + "data": { "all": 1, "foo": 1 }, + "valid": true + }, + { + "description": "all + a is invalid", + "data": { "all": 1, "a": 1 }, + "valid": false + } + ] + }, + { + "description": "non-object instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null valued properties", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties not affected by propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": {"maxLength": 1}, + "unevaluatedProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "allows only number properties", + "data": {"a": 1}, + "valid": true + }, + { + "description": "string property is invalid", + "data": {"a": "b"}, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "patternProperties": { + "foo": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": { + "foo": "a" + }, + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": { + "bar": "a" + }, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/uniqueItems.json b/tests/draft2019-09/uniqueItems.json index d312ad71..314b4b9c 100644 --- a/tests/draft2019-09/uniqueItems.json +++ b/tests/draft2019-09/uniqueItems.json @@ -1,7 +1,10 @@ [ { "description": "uniqueItems validation", - "schema": {"uniqueItems": true}, + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "uniqueItems": true + }, "tests": [ { "description": "unique array of integers is valid", @@ -13,6 +16,11 @@ "data": [1, 1], "valid": false }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], @@ -28,6 +36,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -38,6 +56,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ @@ -64,6 +87,11 @@ "data": [["foo"], ["foo"]], "valid": false }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, { "description": "1 and true are unique", "data": [1, true], @@ -74,22 +102,63 @@ "data": [0, false], "valid": true }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, { "description": "unique heterogeneous types are valid", - "data": [{}, [1], true, null, 1], + "data": [{}, [1], true, null, 1, "{}"], "valid": true }, { "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, { "description": "uniqueItems with an array of items", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true }, "tests": [ @@ -138,8 +207,9 @@ { "description": "uniqueItems with an array of items and additionalItems=false", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], - "uniqueItems": true, + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, "additionalItems": false }, "tests": [ @@ -169,5 +239,181 @@ "valid": false } ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/unknownKeyword.json b/tests/draft2019-09/unknownKeyword.json new file mode 100644 index 00000000..f98e87c5 --- /dev/null +++ b/tests/draft2019-09/unknownKeyword.json @@ -0,0 +1,57 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_unknown0" }, + { "$ref": "#/$defs/id_in_unknown1" }, + { "$ref": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2019-09/vocabulary.json b/tests/draft2019-09/vocabulary.json new file mode 100644 index 00000000..98482b20 --- /dev/null +++ b/tests/draft2019-09/vocabulary.json @@ -0,0 +1,57 @@ +[ + { + "description": "schema that uses custom metaschema with with no validation vocabulary", + "schema": { + "$id": "https://schema/using/no/validation", + "$schema": "http://localhost:1234/draft2019-09/metaschema-no-validation.json", + "properties": { + "badProperty": false, + "numberProperty": { + "minimum": 10 + } + } + }, + "tests": [ + { + "description": "applicator vocabulary still works", + "data": { + "badProperty": "this property should not exist" + }, + "valid": false + }, + { + "description": "no validation: valid number", + "data": { + "numberProperty": 20 + }, + "valid": true + }, + { + "description": "no validation: invalid number, but it still validates", + "data": { + "numberProperty": 1 + }, + "valid": true + } + ] + }, + { + "description": "ignore unrecognized optional vocabulary", + "schema": { + "$schema": "http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json", + "type": "number" + }, + "tests": [ + { + "description": "string value", + "data": "foobar", + "valid": false + }, + { + "description": "number value", + "data": 20, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json new file mode 100644 index 00000000..29e69c13 --- /dev/null +++ b/tests/draft2020-12/additionalProperties.json @@ -0,0 +1,156 @@ +[ + { + "description": + "additionalProperties being false does not allow other properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo": {}, "bar": {}}, + "patternProperties": { "^v": {} }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": {"foo":1, "vroom": 2}, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": {"^รก": {}}, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": {"รกrmรกnyos": 2}, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": {"รฉlmรฉny": 2}, + "valid": false + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo": {}, "bar": {}}, + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": {"foo" : 1, "bar" : 2, "quux" : true}, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : 12}, + "valid": false + } + ] + }, + { + "description": + "additionalProperties can exist by itself", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": {"foo" : true}, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": {"foo" : 1}, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo": {}, "bar": {}} + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": {"foo": 1, "bar": 2, "quux": true}, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {"properties": {"foo": {}}} + ], + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": {"foo": 1, "bar": true}, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/allOf.json b/tests/draft2020-12/allOf.json new file mode 100644 index 00000000..9e87903f --- /dev/null +++ b/tests/draft2020-12/allOf.json @@ -0,0 +1,312 @@ +[ + { + "description": "allOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": {"foo": "baz", "bar": 2}, + "valid": true + }, + { + "description": "mismatch second", + "data": {"foo": "baz"}, + "valid": false + }, + { + "description": "mismatch first", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "wrong type", + "data": {"foo": "baz", "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"bar": {"type": "integer"}}, + "required": ["bar"], + "allOf" : [ + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + }, + { + "properties": { + "baz": {"type": "null"} + }, + "required": ["baz"] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": {"foo": "quux", "bar": 2, "baz": null}, + "valid": true + }, + { + "description": "mismatch base schema", + "data": {"foo": "quux", "baz": null}, + "valid": false + }, + { + "description": "mismatch first allOf", + "data": {"bar": 2, "baz": null}, + "valid": false + }, + { + "description": "mismatch second allOf", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "mismatch both", + "data": {"bar": 2}, + "valid": false + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {"maximum": 30}, + {"minimum": 20} + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [true, true] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [true, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {}, + { "type": "number" } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json new file mode 100644 index 00000000..423835da --- /dev/null +++ b/tests/draft2020-12/anchor.json @@ -0,0 +1,235 @@ +[ + { + "description": "Location-independent identifier", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#foo", + "$defs": { + "A": { + "$anchor": "foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with absolute URI", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/bar", + "$anchor": "foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/root", + "$ref": "http://localhost:1234/draft2020-12/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$anchor": "foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/foobar", + "$defs": { + "A": { + "$id": "child1", + "allOf": [ + { + "$id": "child2", + "$anchor": "my_anchor", + "type": "number" + }, + { + "$anchor": "my_anchor", + "type": "string" + } + ] + } + }, + "$ref": "child1#my_anchor" + }, + "tests": [ + { + "description": "$ref resolves to /$defs/A/allOf/1", + "data": "a", + "valid": true + }, + { + "description": "$ref does not resolve to /$defs/A/allOf/0", + "data": 1, + "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/anyOf.json b/tests/draft2020-12/anyOf.json new file mode 100644 index 00000000..89b192db --- /dev/null +++ b/tests/draft2020-12/anyOf.json @@ -0,0 +1,203 @@ +[ + { + "description": "anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "anyOf" : [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [true, true] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [true, false] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": {"foo": "baz"}, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": {"foo": "baz", "bar": 2}, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/boolean_schema.json b/tests/draft2020-12/boolean_schema.json new file mode 100644 index 00000000..6d40f23f --- /dev/null +++ b/tests/draft2020-12/boolean_schema.json @@ -0,0 +1,104 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "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": "boolean schema 'false'", + "schema": false, + "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 + } + ] + } +] diff --git a/tests/draft2020-12/const.json b/tests/draft2020-12/const.json new file mode 100644 index 00000000..50be86a0 --- /dev/null +++ b/tests/draft2020-12/const.json @@ -0,0 +1,387 @@ +[ + { + "description": "const validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": {"foo": "bar", "baz": "bax"} + }, + "tests": [ + { + "description": "same object is valid", + "data": {"foo": "bar", "baz": "bax"}, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": {"baz": "bax", "foo": "bar"}, + "valid": true + }, + { + "description": "another object is invalid", + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "another type is invalid", + "data": [1, 2], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [{ "foo": "bar" }] + }, + "tests": [ + { + "description": "same array is valid", + "data": [{"foo": "bar"}], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [2], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [1, 2, 3], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [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": "const with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [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": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": {"a": false} + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": {"a": true} + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/contains.json b/tests/draft2020-12/contains.json new file mode 100644 index 00000000..08a00a75 --- /dev/null +++ b/tests/draft2020-12/contains.json @@ -0,0 +1,176 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"minimum": 5} + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [3, 4, 5], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [3, 4, 6], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [3, 4, 5, 6], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [2, 3, 4], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "not array is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { "const": 5 } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [3, 4, 5], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [3, 4, 5, 5], + "valid": true + }, + { + "description": "array without item 5 is invalid", + "data": [1, 2, 3, 4], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": ["foo"], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { "multipleOf": 2 }, + "contains": { "multipleOf": 3 } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ 2, 4, 8 ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ 3, 6, 9 ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ 6, 12 ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ 1, 5 ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "if": false, + "else": true + } + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/content.json b/tests/draft2020-12/content.json new file mode 100644 index 00000000..698f7805 --- /dev/null +++ b/tests/draft2020-12/content.json @@ -0,0 +1,131 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document; validates true", + "data": "{:}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character); validates true", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64", + "contentSchema": { "type": "object", "required": ["foo"], "properties": { "foo": { "type": "string" } } } + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "another valid base64-encoded JSON document", + "data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==", + "valid": true + }, + { + "description": "an invalid base64-encoded JSON document; validates true", + "data": "eyJib28iOiAyMH0=", + "valid": true + }, + { + "description": "an empty object as a base64-encoded JSON document; validates true", + "data": "e30=", + "valid": true + }, + { + "description": "an empty array as a base64-encoded JSON document", + "data": "W10=", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/default.json b/tests/draft2020-12/default.json new file mode 100644 index 00000000..ceb3ae27 --- /dev/null +++ b/tests/draft2020-12/default.json @@ -0,0 +1,82 @@ +[ + { + "description": "invalid type for default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": {"foo": 13}, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": {"bar": "good"}, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/defs.json b/tests/draft2020-12/defs.json new file mode 100644 index 00000000..da2a503b --- /dev/null +++ b/tests/draft2020-12/defs.json @@ -0,0 +1,21 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "valid definition schema", + "data": {"$defs": {"foo": {"type": "integer"}}}, + "valid": true + }, + { + "description": "invalid definition schema", + "data": {"$defs": {"foo": {"type": 1}}}, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/dependentRequired.json b/tests/draft2020-12/dependentRequired.json new file mode 100644 index 00000000..2baa38e9 --- /dev/null +++ b/tests/draft2020-12/dependentRequired.json @@ -0,0 +1,152 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": {"bar": []} + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/dependentSchemas.json b/tests/draft2020-12/dependentSchemas.json new file mode 100644 index 00000000..66ac0eb4 --- /dev/null +++ b/tests/draft2020-12/dependentSchemas.json @@ -0,0 +1,170 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json new file mode 100644 index 00000000..0f6ed480 --- /dev/null +++ b/tests/draft2020-12/dynamicRef.json @@ -0,0 +1,673 @@ +[ + { + "description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $dynamicRef to an $anchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-anchor-same-schema/root", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "foo": { + "$anchor": "items", + "type": "string" + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $ref to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root", + "type": "array", + "items": { "$ref": "#items" }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/typical-dynamic-resolution/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "A $dynamicRef without anchor in fragment behaves identical to $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-without-anchor/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#/$defs/items" }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items", + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "An array of strings is invalid", + "data": ["foo", "bar"], + "valid": false + }, + { + "description": "An array of numbers is valid", + "data": [24, 42], + "valid": true + } + ] + }, + { + "description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root", + "$ref": "intermediate-scope", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "intermediate-scope": { + "$id": "intermediate-scope", + "$ref": "list" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "tests": [ + { + "description": "An array of strings is valid", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "An array containing non-strings is invalid", + "data": ["foo", 42], + "valid": false + } + ] + }, + { + "description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root", + "$ref": "list", + "$defs": { + "foo": { + "$anchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "tests": [ + { + "description": "Any array is valid", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "A $dynamicRef without a matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-without-bookend/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", + "$anchor": "items" + } + } + } + } + }, + "tests": [ + { + "description": "Any array is valid", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "A $dynamicRef with a non-matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/unmatched-dynamic-anchor/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { "$dynamicRef": "#items" }, + "$defs": { + "items": { + "$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", + "$anchor": "items", + "$dynamicAnchor": "foo" + } + } + } + } + }, + "tests": [ + { + "description": "Any array is valid", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor resolves to the first $dynamicAnchor in the dynamic scope", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/relative-dynamic-reference/root", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "foo": { "const": "pass" } + }, + "$ref": "extended", + "$defs": { + "extended": { + "$id": "extended", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "bar": { "$ref": "bar" } + } + }, + "bar": { + "$id": "bar", + "type": "object", + "properties": { + "baz": { "$dynamicRef": "extended#meta" } + } + } + } + }, + "tests": [ + { + "description": "The recursive part is valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { "foo": "pass" } + } + }, + "valid": true + }, + { + "description": "The recursive part is not valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { "foo": "fail" } + } + }, + "valid": false + } + ] + }, + { + "description": "A $dynamicRef that initially resolves to a schema without a matching $dynamicAnchor behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/relative-dynamic-reference-without-bookend/root", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "foo": { "const": "pass" } + }, + "$ref": "extended", + "$defs": { + "extended": { + "$id": "extended", + "$anchor": "meta", + "type": "object", + "properties": { + "bar": { "$ref": "bar" } + } + }, + "bar": { + "$id": "bar", + "type": "object", + "properties": { + "baz": { "$dynamicRef": "extended#meta" } + } + } + } + }, + "tests": [ + { + "description": "The recursive part doesn't need to validate against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { "foo": "fail" } + } + }, + "valid": true + } + ] + }, + { + "description": "multiple dynamic paths to the $dynamicRef keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", + "$defs": { + "inner": { + "$id": "inner", + "$dynamicAnchor": "foo", + "title": "inner", + "additionalProperties": { + "$dynamicRef": "#foo" + } + } + }, + "if": { + "propertyNames": { + "pattern": "^[a-m]" + } + }, + "then": { + "title": "any type of node", + "$id": "anyLeafNode", + "$dynamicAnchor": "foo", + "$ref": "inner" + }, + "else": { + "title": "integer node", + "$id": "integerNode", + "$dynamicAnchor": "foo", + "type": [ "object", "integer" ], + "$ref": "inner" + } + }, + "tests": [ + { + "description": "recurse to anyLeafNode - floats are allowed", + "data": { "alpha": 1.1 }, + "valid": true + }, + { + "description": "recurse to integerNode - floats are not allowed", + "data": { "november": 1.1 }, + "valid": false + } + ] + }, + { + "description": "after leaving a dynamic scope, it is not used by a $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main", + "if": { + "$id": "first_scope", + "$defs": { + "thingy": { + "$comment": "this is first_scope#thingy", + "$dynamicAnchor": "thingy", + "type": "number" + } + } + }, + "then": { + "$id": "second_scope", + "$ref": "start", + "$defs": { + "thingy": { + "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef", + "$dynamicAnchor": "thingy", + "type": "null" + } + } + }, + "$defs": { + "start": { + "$comment": "this is the landing spot from $ref", + "$id": "start", + "$dynamicRef": "inner_scope#thingy" + }, + "thingy": { + "$comment": "this is the first stop for the $dynamicRef", + "$id": "inner_scope", + "$dynamicAnchor": "thingy", + "type": "string" + } + } + }, + "tests": [ + { + "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here", + "data": "a string", + "valid": false + }, + { + "description": "first_scope is not in dynamic scope for the $dynamicRef", + "data": 42, + "valid": false + }, + { + "description": "/then/$defs/thingy is the final stop for the $dynamicRef", + "data": null, + "valid": true + } + ] + }, + { + "description": "strict-tree schema, guards against misspelled properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-tree.json", + "$dynamicAnchor": "node", + + "$ref": "tree.json", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "instance with misspelled field", + "data": { + "children": [{ + "daat": 1 + }] + }, + "valid": false + }, + { + "description": "instance with correct field", + "data": { + "children": [{ + "data": 1 + }] + }, + "valid": true + } + ] + }, + { + "description": "tests for implementation dynamic anchor and reference link", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible.json", + "$ref": "extendible-dynamic-ref.json", + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $defs first", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-defs-first.json", + "allOf": [ + { + "$ref": "extendible-dynamic-ref.json" + }, + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + } + ] + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $ref first", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-ref-first.json", + "allOf": [ + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": ["a"], + "additionalProperties": false + } + } + }, + { + "$ref": "extendible-dynamic-ref.json" + } + ] + }, + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { "b": 1 } + ] + }, + "valid": false + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { "a": 1 } + ] + }, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/enum.json b/tests/draft2020-12/enum.json new file mode 100644 index 00000000..0d780b2a --- /dev/null +++ b/tests/draft2020-12/enum.json @@ -0,0 +1,262 @@ +[ + { + "description": "simple enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [1, 2, 3] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [6, "foo", [], true, {"foo": 12}] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": {"foo": false}, + "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [6, null] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type":"object", + "properties": { + "foo": {"enum":["foo"]}, + "bar": {"enum":["bar"]} + }, + "required": ["bar"] + }, + "tests": [ + { + "description": "both properties are valid", + "data": {"foo":"foo", "bar":"bar"}, + "valid": true + }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": {"bar":"bar"}, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": {"foo":"foo"}, + "valid": false + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": ["foo\nbar", "foo\rbar"] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "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": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "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": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "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": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true + } + ] + }, + { + "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": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ "hello\u0000there" ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/exclusiveMaximum.json b/tests/draft2020-12/exclusiveMaximum.json new file mode 100644 index 00000000..05db2335 --- /dev/null +++ b/tests/draft2020-12/exclusiveMaximum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/exclusiveMinimum.json b/tests/draft2020-12/exclusiveMinimum.json new file mode 100644 index 00000000..00af9d7f --- /dev/null +++ b/tests/draft2020-12/exclusiveMinimum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/format.json b/tests/draft2020-12/format.json new file mode 100644 index 00000000..01adcbda --- /dev/null +++ b/tests/draft2020-12/format.json @@ -0,0 +1,838 @@ +[ + { + "description": "email format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid email string is only an annotation by default", + "data": "2962", + "valid": true + } + ] + }, + { + "description": "idn-email format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid idn-email string is only an annotation by default", + "data": "2962", + "valid": true + } + ] + }, + { + "description": "regex format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid regex string is only an annotation by default", + "data": "^(abc]", + "valid": true + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv4" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid ipv4 string is only an annotation by default", + "data": "127.0.0.0.1", + "valid": true + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv6" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid ipv6 string is only an annotation by default", + "data": "12345::", + "valid": true + } + ] + }, + { + "description": "idn-hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid idn-hostname string is only an annotation by default", + "data": "ใ€ฎ์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + } + ] + }, + { + "description": "hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid hostname string is only an annotation by default", + "data": "-a-host-name-that-starts-with--", + "valid": true + } + ] + }, + { + "description": "date format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid date string is only an annotation by default", + "data": "06/19/1963", + "valid": true + } + ] + }, + { + "description": "date-time format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date-time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid date-time string is only an annotation by default", + "data": "1990-02-31T15:59:60.123-08:00", + "valid": true + } + ] + }, + { + "description": "time format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid time string is only an annotation by default", + "data": "08:30:06 PST", + "valid": true + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid json-pointer string is only an annotation by default", + "data": "/foo/bar~", + "valid": true + } + ] + }, + { + "description": "relative-json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "relative-json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid relative-json-pointer string is only an annotation by default", + "data": "/foo/bar", + "valid": true + } + ] + }, + { + "description": "iri format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid iri string is only an annotation by default", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": true + } + ] + }, + { + "description": "iri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid iri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": true + } + ] + }, + { + "description": "uri format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri string is only an annotation by default", + "data": "//foo.bar/?baz=qux#quux", + "valid": true + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\fileshare", + "valid": true + } + ] + }, + { + "description": "uri-template format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-template" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uri-template string is only an annotation by default", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": true + } + ] + }, + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid uuid string is only an annotation by default", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": true + } + ] + }, + { + "description": "duration format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "invalid duration string is only an annotation by default", + "data": "PT1D", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/id.json b/tests/draft2020-12/id.json new file mode 100644 index 00000000..0ae5fe68 --- /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/if-then-else.json b/tests/draft2020-12/if-then-else.json new file mode 100644 index 00000000..1c35d7e6 --- /dev/null +++ b/tests/draft2020-12/if-then-else.json @@ -0,0 +1,268 @@ +[ + { + "description": "ignore if without then or else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone if", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone if", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "ignore then without if", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "then": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone then", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone then", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "ignore else without if", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "else": { + "const": 0 + } + }, + "tests": [ + { + "description": "valid when valid against lone else", + "data": 0, + "valid": true + }, + { + "description": "valid when invalid against lone else", + "data": "hello", + "valid": true + } + ] + }, + { + "description": "if and then without else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + } + }, + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true + }, + { + "description": "invalid through then", + "data": -100, + "valid": false + }, + { + "description": "valid when if test fails", + "data": 3, + "valid": true + } + ] + }, + { + "description": "if and else without then", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "else": { + "multipleOf": 2 + } + }, + "tests": [ + { + "description": "valid when if test passes", + "data": -1, + "valid": true + }, + { + "description": "valid through else", + "data": 4, + "valid": true + }, + { + "description": "invalid through else", + "data": 3, + "valid": false + } + ] + }, + { + "description": "validate against correct branch, then vs else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + }, + "else": { + "multipleOf": 2 + } + }, + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true + }, + { + "description": "invalid through then", + "data": -100, + "valid": false + }, + { + "description": "valid through else", + "data": 4, + "valid": true + }, + { + "description": "invalid through else", + "data": 3, + "valid": false + } + ] + }, + { + "description": "non-interference across combined schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "if": { + "exclusiveMaximum": 0 + } + }, + { + "then": { + "minimum": -10 + } + }, + { + "else": { + "multipleOf": 2 + } + } + ] + }, + "tests": [ + { + "description": "valid, but would have been invalid through then", + "data": -100, + "valid": true + }, + { + "description": "valid, but would have been invalid through else", + "data": 3, + "valid": true + } + ] + }, + { + "description": "if with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": true, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": false, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/infinite-loop-detection.json b/tests/draft2020-12/infinite-loop-detection.json new file mode 100644 index 00000000..46f157a3 --- /dev/null +++ b/tests/draft2020-12/infinite-loop-detection.json @@ -0,0 +1,37 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/items.json b/tests/draft2020-12/items.json new file mode 100644 index 00000000..1ef18bdd --- /dev/null +++ b/tests/draft2020-12/items.json @@ -0,0 +1,284 @@ +[ + { + "description": "a schema given for items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": {"type": "integer"} + }, + "tests": [ + { + "description": "valid items", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [1, "x"], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": {"foo" : "bar"}, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": true + }, + "tests": [ + { + "description": "any array is valid", + "data": [ 1, "foo", true ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ 1, "foo", true ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "items and subitems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "item": { + "type": "array", + "items": false, + "prefixItems": [ + { "$ref": "#/$defs/sub-item" }, + { "$ref": "#/$defs/sub-item" } + ] + }, + "sub-item": { + "type": "object", + "required": ["foo"] + } + }, + "type": "array", + "items": false, + "prefixItems": [ + { "$ref": "#/$defs/item" }, + { "$ref": "#/$defs/item" }, + { "$ref": "#/$defs/item" } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ {"foo": null}, {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + {"foo": null}, + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ {}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ], + [ {"foo": null}, {"foo": null} ] + ], + "valid": false + }, + { + "description": "fewer items is valid", + "data": [ + [ {"foo": null} ], + [ {"foo": null} ] + ], + "valid": true + } + ] + }, + { + "description": "nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]], + "valid": false + }, + { + "description": "not deep enough", + "data": [[[1], [2],[3]], [[4], [5], [6]]], + "valid": false + } + ] + }, + { + "description": "prefixItems with no additional items allowed", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{}, {}, {}], + "items": false + }, + "tests": [ + { + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "equal number of items present", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ 1, 2, 3, 4 ], + "valid": false + } + ] + }, + { + "description": "items does not look in applicators, valid case", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { "prefixItems": [ { "minimum": 3 } ] } + ], + "items": { "minimum": 5 } + }, + "tests": [ + { + "description": "prefixItems in allOf does not constrain items, invalid case", + "data": [ 3, 5 ], + "valid": false + }, + { + "description": "prefixItems in allOf does not constrain items, valid case", + "data": [ 5, 5 ], + "valid": true + } + ] + }, + { + "description": "prefixItems validation adjusts the starting index for items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ { "type": "string" } ], + "items": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/maxContains.json b/tests/draft2020-12/maxContains.json new file mode 100644 index 00000000..8cd3ca74 --- /dev/null +++ b/tests/draft2020-12/maxContains.json @@ -0,0 +1,102 @@ +[ + { + "description": "maxContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "two items still valid against lone maxContains", + "data": [ 1, 2 ], + "valid": true + } + ] + }, + { + "description": "maxContains with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "all elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + }, + { + "description": "some elements match, valid maxContains", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "some elements match, invalid maxContains", + "data": [ 1, 2, 1 ], + "valid": false + } + ] + }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "maxContains": 1.0 + }, + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, + { + "description": "minContains < maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 1, + "maxContains": 3 + }, + "tests": [ + { + "description": "actual < minContains < maxContains", + "data": [ ], + "valid": false + }, + { + "description": "minContains < actual < maxContains", + "data": [ 1, 1 ], + "valid": true + }, + { + "description": "minContains < maxContains < actual", + "data": [ 1, 1, 1, 1 ], + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/maxItems.json b/tests/draft2020-12/maxItems.json new file mode 100644 index 00000000..f6a6b7c9 --- /dev/null +++ b/tests/draft2020-12/maxItems.json @@ -0,0 +1,50 @@ +[ + { + "description": "maxItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxItems": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/maxLength.json b/tests/draft2020-12/maxLength.json new file mode 100644 index 00000000..b6eb0340 --- /dev/null +++ b/tests/draft2020-12/maxLength.json @@ -0,0 +1,55 @@ +[ + { + "description": "maxLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two supplementary Unicode code points is long enough", + "data": "\uD83D\uDCA9\uD83D\uDCA9", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/maxProperties.json b/tests/draft2020-12/maxProperties.json new file mode 100644 index 00000000..73ae7316 --- /dev/null +++ b/tests/draft2020-12/maxProperties.json @@ -0,0 +1,79 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/maximum.json b/tests/draft2020-12/maximum.json new file mode 100644 index 00000000..b99a541e --- /dev/null +++ b/tests/draft2020-12/maximum.json @@ -0,0 +1,60 @@ +[ + { + "description": "maximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/minContains.json b/tests/draft2020-12/minContains.json new file mode 100644 index 00000000..ee72d7d6 --- /dev/null +++ b/tests/draft2020-12/minContains.json @@ -0,0 +1,224 @@ +[ + { + "description": "minContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone minContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "zero items still valid against lone minContains", + "data": [], + "valid": true + } + ] + }, + { + "description": "minContains=1 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "no elements match", + "data": [ 2 ], + "valid": false + }, + { + "description": "single element matches, valid minContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "all elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "some elements match, invalid minContains", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "all elements match, valid minContains (exactly as needed)", + "data": [ 1, 1 ], + "valid": true + }, + { + "description": "all elements match, valid minContains (more than needed)", + "data": [ 1, 1, 1 ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ 1, 2, 1 ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 2.0 + }, + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "both elements match, valid minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "maxContains = minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "maxContains": 2, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "all elements match, invalid maxContains", + "data": [ 1, 1, 1 ], + "valid": false + }, + { + "description": "all elements match, valid maxContains and minContains", + "data": [ 1, 1 ], + "valid": true + } + ] + }, + { + "description": "maxContains < minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "maxContains": 1, + "minContains": 3 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": false + }, + { + "description": "invalid minContains", + "data": [ 1 ], + "valid": false + }, + { + "description": "invalid maxContains", + "data": [ 1, 1, 1 ], + "valid": false + }, + { + "description": "invalid maxContains and minContains", + "data": [ 1, 1 ], + "valid": false + } + ] + }, + { + "description": "minContains = 0", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 0 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": true + }, + { + "description": "minContains = 0 makes contains always pass", + "data": [ 2 ], + "valid": true + } + ] + }, + { + "description": "minContains = 0 with maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": {"const": 1}, + "minContains": 0, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [ ], + "valid": true + }, + { + "description": "not more than maxContains", + "data": [ 1 ], + "valid": true + }, + { + "description": "too many", + "data": [ 1, 1 ], + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/minItems.json b/tests/draft2020-12/minItems.json new file mode 100644 index 00000000..9d6a8b6d --- /dev/null +++ b/tests/draft2020-12/minItems.json @@ -0,0 +1,50 @@ +[ + { + "description": "minItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minItems": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/minLength.json b/tests/draft2020-12/minLength.json new file mode 100644 index 00000000..e0930b6f --- /dev/null +++ b/tests/draft2020-12/minLength.json @@ -0,0 +1,55 @@ +[ + { + "description": "minLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one supplementary Unicode code point is not long enough", + "data": "\uD83D\uDCA9", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/minProperties.json b/tests/draft2020-12/minProperties.json new file mode 100644 index 00000000..a753ad35 --- /dev/null +++ b/tests/draft2020-12/minProperties.json @@ -0,0 +1,60 @@ +[ + { + "description": "minProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minProperties": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minProperties": 1.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/minimum.json b/tests/draft2020-12/minimum.json new file mode 100644 index 00000000..dc440527 --- /dev/null +++ b/tests/draft2020-12/minimum.json @@ -0,0 +1,75 @@ +[ + { + "description": "minimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/multipleOf.json b/tests/draft2020-12/multipleOf.json new file mode 100644 index 00000000..92d6979b --- /dev/null +++ b/tests/draft2020-12/multipleOf.json @@ -0,0 +1,97 @@ +[ + { + "description": "by int", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", "multipleOf": 1e-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/not.json b/tests/draft2020-12/not.json new file mode 100644 index 00000000..57e45ba3 --- /dev/null +++ b/tests/draft2020-12/not.json @@ -0,0 +1,153 @@ +[ + { + "description": "not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": {"type": "integer"} + }, + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true + }, + { + "description": "disallowed", + "data": 1, + "valid": false + } + ] + }, + { + "description": "not multiple types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": {"type": ["integer", "boolean"]} + }, + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true + }, + { + "description": "mismatch", + "data": 1, + "valid": false + }, + { + "description": "other mismatch", + "data": true, + "valid": false + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "tests": [ + { + "description": "match", + "data": 1, + "valid": true + }, + { + "description": "other match", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "mismatch", + "data": {"foo": "bar"}, + "valid": false + } + ] + }, + { + "description": "forbidden property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "not": {} + } + } + }, + "tests": [ + { + "description": "property present", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "property absent", + "data": {"bar": 1, "baz": 2}, + "valid": true + } + ] + }, + { + "description": "not with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": true + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "not with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": false + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "collect annotations inside a 'not', even if collection is disabled", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them", + "anyOf": [ + true, + { "properties": { "foo": true } } + ], + "unevaluatedProperties": false + } + }, + "tests": [ + { + "description": "unevaluated property", + "data": { "bar": 1 }, + "valid": true + }, + { + "description": "annotations are still collected inside a 'not'", + "data": { "foo": 1 }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/oneOf.json b/tests/draft2020-12/oneOf.json new file mode 100644 index 00000000..416c8e57 --- /dev/null +++ b/tests/draft2020-12/oneOf.json @@ -0,0 +1,293 @@ +[ + { + "description": "oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "oneOf" : [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [true, true, true] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [true, false, false] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [true, true, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [false, false, false] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": {"foo": "baz"}, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": {"foo": "baz", "bar": 2}, + "valid": false + }, + { + "description": "neither oneOf valid (complex)", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { "type": "number" }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "oneOf": [ + { "required": ["foo", "bar"] }, + { "required": ["foo", "baz"] } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "first valid - valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "second valid - valid", + "data": {"foo": 1, "baz": 3}, + "valid": true + }, + { + "description": "both valid - invalid", + "data": {"foo": 1, "bar": 2, "baz" : 3}, + "valid": false + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": ["bar"] + }, + { + "properties": { + "foo": true + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/bignum.json b/tests/draft2020-12/optional/bignum.json new file mode 100644 index 00000000..d69b29e8 --- /dev/null +++ b/tests/draft2020-12/optional/bignum.json @@ -0,0 +1,110 @@ +[ + { + "description": "integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/cross-draft.json b/tests/draft2020-12/optional/cross-draft.json new file mode 100644 index 00000000..5113bd64 --- /dev/null +++ b/tests/draft2020-12/optional/cross-draft.json @@ -0,0 +1,18 @@ +[ + { + "description": "refs to historic drafts are processed as historic drafts", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array", + "$ref": "http://localhost:1234/draft2019-09/ignore-prefixItems.json" + }, + "tests": [ + { + "description": "first item not a string is valid", + "comment": "if the implementation is not processing the $ref as a 2019-09 schema, this test will fail", + "data": [1, 2, 3], + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/dependencies-compatibility.json b/tests/draft2020-12/optional/dependencies-compatibility.json new file mode 100644 index 00000000..47d5bd79 --- /dev/null +++ b/tests/draft2020-12/optional/dependencies-compatibility.json @@ -0,0 +1,282 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": {"bar": []} + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": {"bar": 2}, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo\nbar": ["foo\rbar"], + "foo\"bar": ["foo'bar"] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo\tbar": {"minProperties": 4}, + "foo'bar": {"required": ["foo\"bar"]} + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": {"foo\"bar": 1} + }, + "valid": false + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false + }, + { + "description": "quoted quote invalid under dependent schema", + "data": {"foo'bar": 1}, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/ecmascript-regex.json b/tests/draft2020-12/optional/ecmascript-regex.json new file mode 100644 index 00000000..23b962e4 --- /dev/null +++ b/tests/draft2020-12/optional/ecmascript-regex.json @@ -0,0 +1,596 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\u0009", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\cC$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false + }, + { + "description": "matches", + "data": "\u0003", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\cc$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false + }, + { + "description": "matches", + "data": "\u0003", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "฿€", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "\u07c0", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "฿€", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "\u07c0", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "รฉ", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "รฉ", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "\\p{Letter}cole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^\\p{digit}+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/float-overflow.json b/tests/draft2020-12/optional/float-overflow.json new file mode 100644 index 00000000..f5ae8b18 --- /dev/null +++ b/tests/draft2020-12/optional/float-overflow.json @@ -0,0 +1,17 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/format-assertion.json b/tests/draft2020-12/optional/format-assertion.json new file mode 100644 index 00000000..03400370 --- /dev/null +++ b/tests/draft2020-12/optional/format-assertion.json @@ -0,0 +1,42 @@ +[ + { + "description": "schema that uses custom metaschema with format-assertion: false", + "schema": { + "$id": "https://schema/using/format-assertion/false", + "$schema": "http://localhost:1234/draft2020-12/format-assertion-false.json", + "format": "ipv4" + }, + "tests": [ + { + "description": "format-assertion: false: valid string", + "data": "127.0.0.1", + "valid": true + }, + { + "description": "format-assertion: false: invalid string", + "data": "not-an-ipv4", + "valid": false + } + ] + }, + { + "description": "schema that uses custom metaschema with format-assertion: true", + "schema": { + "$id": "https://schema/using/format-assertion/true", + "$schema": "http://localhost:1234/draft2020-12/format-assertion-true.json", + "format": "ipv4" + }, + "tests": [ + { + "description": "format-assertion: true: valid string", + "data": "127.0.0.1", + "valid": true + }, + { + "description": "format-assertion: true: invalid string", + "data": "not-an-ipv4", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/date-time.json b/tests/draft2020-12/optional/format/date-time.json new file mode 100644 index 00000000..8783d732 --- /dev/null +++ b/tests/draft2020-12/optional/format/date-time.json @@ -0,0 +1,136 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date-time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/date.json b/tests/draft2020-12/optional/format/date.json new file mode 100644 index 00000000..dfb1c80a --- /dev/null +++ b/tests/draft2020-12/optional/format/date.json @@ -0,0 +1,246 @@ +[ + { + "description": "validation of date strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1963-06-1เงช", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/duration.json b/tests/draft2020-12/optional/format/duration.json new file mode 100644 index 00000000..a3af56ef --- /dev/null +++ b/tests/draft2020-12/optional/format/duration.json @@ -0,0 +1,136 @@ +[ + { + "description": "validation of duration strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "duration" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid duration string", + "data": "P4DT12H30M5S", + "valid": true + }, + { + "description": "an invalid duration string", + "data": "PT1D", + "valid": false + }, + { + "description": "no elements present", + "data": "P", + "valid": false + }, + { + "description": "no time elements present", + "data": "P1YT", + "valid": false + }, + { + "description": "no date or time elements present", + "data": "PT", + "valid": false + }, + { + "description": "elements out of order", + "data": "P2D1Y", + "valid": false + }, + { + "description": "missing time separator", + "data": "P1D2H", + "valid": false + }, + { + "description": "time element in the date position", + "data": "P2S", + "valid": false + }, + { + "description": "four years duration", + "data": "P4Y", + "valid": true + }, + { + "description": "zero time, in seconds", + "data": "PT0S", + "valid": true + }, + { + "description": "zero time, in days", + "data": "P0D", + "valid": true + }, + { + "description": "one month duration", + "data": "P1M", + "valid": true + }, + { + "description": "one minute duration", + "data": "PT1M", + "valid": true + }, + { + "description": "one and a half days, in hours", + "data": "PT36H", + "valid": true + }, + { + "description": "one and a half days, in days and hours", + "data": "P1DT12H", + "valid": true + }, + { + "description": "two weeks", + "data": "P2W", + "valid": true + }, + { + "description": "weeks cannot be combined with other units", + "data": "P1Y2W", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "PเงจY", + "valid": false + }, + { + "description": "element without unit", + "data": "P1", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/email.json b/tests/draft2020-12/optional/format/email.json new file mode 100644 index 00000000..ee075893 --- /dev/null +++ b/tests/draft2020-12/optional/format/email.json @@ -0,0 +1,121 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "a quoted string with a space in the local part is valid", + "data": "\"joe bloggs\"@example.com", + "valid": true + }, + { + "description": "a quoted string with a double dot in the local part is valid", + "data": "\"joe..bloggs\"@example.com", + "valid": true + }, + { + "description": "a quoted string with a @ in the local part is valid", + "data": "\"joe@bloggs\"@example.com", + "valid": true + }, + { + "description": "an IPv4-address-literal after the @ is valid", + "data": "joe.bloggs@[127.0.0.1]", + "valid": true + }, + { + "description": "an IPv6-address-literal after the @ is valid", + "data": "joe.bloggs@[IPv6:::1]", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false + }, + { + "description": "an invalid domain", + "data": "joe.bloggs@invalid=domain.com", + "valid": false + }, + { + "description": "an invalid IPv4-address-literal", + "data": "joe.bloggs@[127.0.0.300]", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/hostname.json b/tests/draft2020-12/optional/format/hostname.json new file mode 100644 index 00000000..c8db9770 --- /dev/null +++ b/tests/draft2020-12/optional/format/hostname.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of host names", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/idn-email.json b/tests/draft2020-12/optional/format/idn-email.json new file mode 100644 index 00000000..50f3c23c --- /dev/null +++ b/tests/draft2020-12/optional/format/idn-email.json @@ -0,0 +1,61 @@ +[ + { + "description": "validation of an internationalized e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-email" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid idn e-mail (example@example.test in Hangul)", + "data": "์‹ค๋ก€@์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + }, + { + "description": "an invalid idn e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/idn-hostname.json b/tests/draft2020-12/optional/format/idn-hostname.json new file mode 100644 index 00000000..5549c055 --- /dev/null +++ b/tests/draft2020-12/optional/format/idn-hostname.json @@ -0,0 +1,307 @@ +[ + { + "description": "validation of internationalized host names", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-hostname" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name (example.test in Hangul)", + "data": "์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": true + }, + { + "description": "illegal first char U+302E Hangul single dot tone mark", + "data": "ใ€ฎ์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "contains illegal char U+302E Hangul single dot tone mark", + "data": "์‹คใ€ฎ๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€์‹ค๋ก€.ํ…Œ์ŠคํŠธ", + "valid": false + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-> $1.00 <--", + "valid": false + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0903hello", + "valid": false + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0300hello", + "valid": false + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0488hello", + "valid": false + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u00df\u03c2\u0f0b\u3007", + "valid": true + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u06fd\u06fe", + "valid": true + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u0640\u07fa", + "valid": false + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b", + "valid": false + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7a", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7", + "valid": false + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7l", + "valid": true + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375S", + "valid": false + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375", + "valid": false + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375\u03b2", + "valid": true + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05d0\u05f3\u05d1", + "valid": true + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05d0\u05f4\u05d1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def\u30fbabc", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u3041", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u30a1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u4e08", + "valid": true + }, + { + "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", + "valid": false + }, + { + "description": "Arabic-Indic digits not 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\u0628", + "valid": true + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "\u06f00", + "valid": true + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u094d\u200d\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "\u0915\u094d\u200c\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "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 + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/ipv4.json b/tests/draft2020-12/optional/format/ipv4.json new file mode 100644 index 00000000..c72b6fc2 --- /dev/null +++ b/tests/draft2020-12/optional/format/ipv4.json @@ -0,0 +1,87 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv4" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/ipv6.json b/tests/draft2020-12/optional/format/ipv6.json new file mode 100644 index 00000000..b9e570c9 --- /dev/null +++ b/tests/draft2020-12/optional/format/ipv6.json @@ -0,0 +1,211 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv6" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/iri-reference.json b/tests/draft2020-12/optional/format/iri-reference.json new file mode 100644 index 00000000..0c9483dc --- /dev/null +++ b/tests/draft2020-12/optional/format/iri-reference.json @@ -0,0 +1,76 @@ +[ + { + "description": "validation of IRI References", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IRI", + "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid protocol-relative IRI Reference", + "data": "//ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid relative IRI Reference", + "data": "/รขฯ€ฯ€", + "valid": true + }, + { + "description": "an invalid IRI Reference", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": false + }, + { + "description": "a valid IRI Reference", + "data": "รขฯ€ฯ€", + "valid": true + }, + { + "description": "a valid IRI fragment", + "data": "#ฦ’rรคgmรชnt", + "valid": true + }, + { + "description": "an invalid IRI fragment", + "data": "#ฦ’rรคg\\mรชnt", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/iri.json b/tests/draft2020-12/optional/format/iri.json new file mode 100644 index 00000000..311c9ef0 --- /dev/null +++ b/tests/draft2020-12/optional/format/iri.json @@ -0,0 +1,86 @@ +[ + { + "description": "validation of IRIs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IRI with anchor tag", + "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", + "valid": true + }, + { + "description": "a valid IRI with anchor tag and parentheses", + "data": "http://ฦ’รธรธ.com/blah_(wรฎkรฏpรฉdiรฅ)_blah#รŸitรฉ-1", + "valid": true + }, + { + "description": "a valid IRI with URL-encoded stuff", + "data": "http://ฦ’รธรธ.รŸรฅr/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid IRI with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid IRI based on IPv6", + "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", + "valid": true + }, + { + "description": "an invalid IRI based on IPv6", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": false + }, + { + "description": "an invalid relative IRI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid IRI", + "data": "\\\\WINDOWS\\filรซรŸรฅrรฉ", + "valid": false + }, + { + "description": "an invalid IRI though valid IRI reference", + "data": "รขฯ€ฯ€", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/json-pointer.json b/tests/draft2020-12/optional/format/json-pointer.json new file mode 100644 index 00000000..71ba9b60 --- /dev/null +++ b/tests/draft2020-12/optional/format/json-pointer.json @@ -0,0 +1,201 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/regex.json b/tests/draft2020-12/optional/format/regex.json new file mode 100644 index 00000000..a036c6de --- /dev/null +++ b/tests/draft2020-12/optional/format/regex.json @@ -0,0 +1,51 @@ +[ + { + "description": "validation of regular expressions", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/relative-json-pointer.json b/tests/draft2020-12/optional/format/relative-json-pointer.json new file mode 100644 index 00000000..3eaf9ce2 --- /dev/null +++ b/tests/draft2020-12/optional/format/relative-json-pointer.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of Relative JSON Pointers (RJP)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "relative-json-pointer" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid upwards RJP", + "data": "1", + "valid": true + }, + { + "description": "a valid downwards RJP", + "data": "0/foo/bar", + "valid": true + }, + { + "description": "a valid up and then down RJP, with array index", + "data": "2/0/baz/1/zip", + "valid": true + }, + { + "description": "a valid RJP taking the member or index name", + "data": "0#", + "valid": true + }, + { + "description": "an invalid RJP that is a valid JSON Pointer", + "data": "/foo/bar", + "valid": false + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/time.json b/tests/draft2020-12/optional/format/time.json new file mode 100644 index 00000000..8967932e --- /dev/null +++ b/tests/draft2020-12/optional/format/time.json @@ -0,0 +1,236 @@ +[ + { + "description": "validation of time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "time" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid time string", + "data": "08:30:06Z", + "valid": true + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true + }, + { + "description": "a valid time string with precise second fraction", + "data": "08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false + }, + { + "description": "an invalid offset indicator", + "data": "08:30:06 PST", + "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "01:01:01,1111", + "valid": false + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ:00:00Z", + "valid": false + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/unknown.json b/tests/draft2020-12/optional/format/unknown.json new file mode 100644 index 00000000..7fc35f53 --- /dev/null +++ b/tests/draft2020-12/optional/format/unknown.json @@ -0,0 +1,46 @@ +[ + { + "description": "unknown format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "unknown" + }, + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/uri-reference.json b/tests/draft2020-12/optional/format/uri-reference.json new file mode 100644 index 00000000..46f28e6c --- /dev/null +++ b/tests/draft2020-12/optional/format/uri-reference.json @@ -0,0 +1,76 @@ +[ + { + "description": "validation of URI References", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-reference" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/uri-template.json b/tests/draft2020-12/optional/format/uri-template.json new file mode 100644 index 00000000..08aab829 --- /dev/null +++ b/tests/draft2020-12/optional/format/uri-template.json @@ -0,0 +1,61 @@ +[ + { + "description": "format: uri-template", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-template" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/uri.json b/tests/draft2020-12/optional/format/uri.json new file mode 100644 index 00000000..84b5f15e --- /dev/null +++ b/tests/draft2020-12/optional/format/uri.json @@ -0,0 +1,141 @@ +[ + { + "description": "validation of URIs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/format/uuid.json b/tests/draft2020-12/optional/format/uuid.json new file mode 100644 index 00000000..d152643d --- /dev/null +++ b/tests/draft2020-12/optional/format/uuid.json @@ -0,0 +1,116 @@ +[ + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uuid" + }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "all upper-case", + "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", + "valid": true + }, + { + "description": "all lower-case", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", + "valid": true + }, + { + "description": "mixed case", + "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", + "valid": true + }, + { + "description": "all zeroes is valid", + "data": "00000000-0000-0000-0000-000000000000", + "valid": true + }, + { + "description": "wrong length", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": false + }, + { + "description": "missing section", + "data": "2eb8aa08-aa98-11ea-73b441d16380", + "valid": false + }, + { + "description": "bad characters (not hex)", + "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", + "valid": false + }, + { + "description": "no dashes", + "data": "2eb8aa08aa9811eab4aa73b441d16380", + "valid": false + }, + { + "description": "too few dashes", + "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", + "valid": false + }, + { + "description": "too many dashes", + "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", + "valid": false + }, + { + "description": "dashes in the wrong spot", + "data": "2eb8aa08aa9811eab4aa73b441d16380----", + "valid": false + }, + { + "description": "valid version 4", + "data": "98d80576-482e-427f-8434-7f86890ab222", + "valid": true + }, + { + "description": "valid version 5", + "data": "99c17cbb-656f-564a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 6", + "data": "99c17cbb-656f-664a-940f-1a4568f03487", + "valid": true + }, + { + "description": "hypothetical version 15", + "data": "99c17cbb-656f-f64a-940f-1a4568f03487", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/no-schema.json b/tests/draft2020-12/optional/no-schema.json new file mode 100644 index 00000000..676e6b53 --- /dev/null +++ b/tests/draft2020-12/optional/no-schema.json @@ -0,0 +1,26 @@ +[ + { + "description": "validation without $schema", + "comment": "minLength is the same across all drafts", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "a 3-character string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a 1-character string is not valid", + "data": "a", + "valid": false + }, + { + "description": "a non-string is valid", + "data": 5, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/optional/non-bmp-regex.json b/tests/draft2020-12/optional/non-bmp-regex.json new file mode 100644 index 00000000..d2efb3ef --- /dev/null +++ b/tests/draft2020-12/optional/non-bmp-regex.json @@ -0,0 +1,86 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^๐Ÿฒ*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/optional/refOfUnknownKeyword.json b/tests/draft2020-12/optional/refOfUnknownKeyword.json new file mode 100644 index 00000000..f91c1888 --- /dev/null +++ b/tests/draft2020-12/optional/refOfUnknownKeyword.json @@ -0,0 +1,46 @@ +[ + { + "description": "reference of a root arbitrary keyword ", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unknown-keyword": {"type": "integer"}, + "properties": { + "bar": {"$ref": "#/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "reference of an arbitrary keyword of a sub-schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"unknown-keyword": {"type": "integer"}}, + "bar": {"$ref": "#/properties/foo/unknown-keyword"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/pattern.json b/tests/draft2020-12/pattern.json new file mode 100644 index 00000000..af0b8d89 --- /dev/null +++ b/tests/draft2020-12/pattern.json @@ -0,0 +1,65 @@ +[ + { + "description": "pattern validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/patternProperties.json b/tests/draft2020-12/patternProperties.json new file mode 100644 index 00000000..81829c71 --- /dev/null +++ b/tests/draft2020-12/patternProperties.json @@ -0,0 +1,176 @@ +[ + { + "description": + "patternProperties validates properties matching a regex", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "f.*o": {"type": "integer"} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": {"foo": 1, "foooooo" : 2}, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": {"foo": "bar", "fooooo": 2}, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": {"foo": "bar", "foooooo" : "baz"}, + "valid": false + }, + { + "description": "ignores arrays", + "data": ["foo"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "a*": {"type": "integer"}, + "aaa*": {"maximum": 20} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"a": 21}, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": {"aaaa": 18}, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": {"a": 21, "aaaa": 18}, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": {"a": "bar"}, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": {"aaaa": 31}, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": {"aaa": "foo", "aaaa": 31}, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "[0-9]{2,}": { "type": "boolean" }, + "X_": { "type": "string" } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { "answer 1": "42" }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { "a31b": null }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { "a_x_3": 3 }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { "a_X_3": 3 }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": {"foobar":1}, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/prefixItems.json b/tests/draft2020-12/prefixItems.json new file mode 100644 index 00000000..0adfc069 --- /dev/null +++ b/tests/draft2020-12/prefixItems.json @@ -0,0 +1,104 @@ +[ + { + "description": "a schema given for prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + {"type": "integer"}, + {"type": "string"} + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "wrong types", + "data": [ "foo", 1 ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ 1 ], + "valid": true + }, + { + "description": "array with additional items", + "data": [ 1, "foo", true ], + "valid": true + }, + { + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "prefixItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [true, false] + }, + "tests": [ + { + "description": "array with one item is valid", + "data": [ 1 ], + "valid": true + }, + { + "description": "array with two items is invalid", + "data": [ 1, "foo" ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "additional items are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{"type": "integer"}] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [1, "foo", false], + "valid": true + } + ] + }, + { + "description": "prefixItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/properties.json b/tests/draft2020-12/properties.json new file mode 100644 index 00000000..eb66fa8b --- /dev/null +++ b/tests/draft2020-12/properties.json @@ -0,0 +1,242 @@ +[ + { + "description": "object properties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": {"foo": 1, "bar": "baz"}, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": {"foo": 1, "bar": {}}, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": {"foo": [], "bar": {}}, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": {"quux": []}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": + "properties, patternProperties, additionalProperties interaction", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"type": "array", "maxItems": 3}, + "bar": {"type": "array"} + }, + "patternProperties": {"f.o": {"minItems": 2}}, + "additionalProperties": {"type": "integer"} + }, + "tests": [ + { + "description": "property validates property", + "data": {"foo": [1, 2]}, + "valid": true + }, + { + "description": "property invalidates property", + "data": {"foo": [1, 2, 3, 4]}, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": {"foo": []}, + "valid": false + }, + { + "description": "patternProperty validates nonproperty", + "data": {"fxo": [1, 2]}, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": {"fxo": []}, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": {"bar": []}, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": {"quux": 3}, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": {"quux": "foo"}, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": {"foo": 1, "bar": 2}, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo\nbar": {"type": "number"}, + "foo\"bar": {"type": "number"}, + "foo\\bar": {"type": "number"}, + "foo\rbar": {"type": "number"}, + "foo\tbar": {"type": "number"}, + "foo\fbar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/propertyNames.json b/tests/draft2020-12/propertyNames.json new file mode 100644 index 00000000..7ecfb7ec --- /dev/null +++ b/tests/draft2020-12/propertyNames.json @@ -0,0 +1,85 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": {"maxLength": 3} + }, + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [1, 2, 3, 4], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": {"foo": 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 new file mode 100644 index 00000000..5f6be8c2 --- /dev/null +++ b/tests/draft2020-12/ref.json @@ -0,0 +1,1059 @@ +[ + { + "description": "root pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"$ref": "#"} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": {"foo": {"foo": false}}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": false}, + "valid": false + }, + { + "description": "recursive mismatch", + "data": {"foo": {"bar": false}}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {"type": "integer"}, + "bar": {"$ref": "#/properties/foo"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + {"type": "integer"}, + {"$ref": "#/prefixItems/0"} + ] + }, + "tests": [ + { + "description": "match array", + "data": [1, 2], + "valid": true + }, + { + "description": "mismatch array", + "data": [1, "foo"], + "valid": false + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, + "properties": { + "tilde": {"$ref": "#/$defs/tilde~0field"}, + "slash": {"$ref": "#/$defs/slash~1field"}, + "percent": {"$ref": "#/$defs/percent%25field"} + } + }, + "tests": [ + { + "description": "slash invalid", + "data": {"slash": "aoeu"}, + "valid": false + }, + { + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, + "valid": false + }, + { + "description": "percent invalid", + "data": {"percent": "aoeu"}, + "valid": false + }, + { + "description": "slash valid", + "data": {"slash": 123}, + "valid": true + }, + { + "description": "tilde valid", + "data": {"tilde": 123}, + "valid": true + }, + { + "description": "percent valid", + "data": {"percent": 123}, + "valid": true + } + ] + }, + { + "description": "nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "a": {"type": "integer"}, + "b": {"$ref": "#/$defs/a"}, + "c": {"$ref": "#/$defs/b"} + }, + "$ref": "#/$defs/c" + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref applies alongside sibling keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/$defs/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid, maxItems valid", + "data": { "foo": [] }, + "valid": true + }, + { + "description": "ref valid, maxItems invalid", + "data": { "foo": [1, 2, 3] }, + "valid": false + }, + { + "description": "ref invalid", + "data": { "foo": "string" }, + "valid": false + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "tests": [ + { + "description": "remote ref valid", + "data": {"minLength": 1}, + "valid": true + }, + { + "description": "remote ref invalid", + "data": {"minLength": -1}, + "valid": false + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "$ref": {"type": "string"} + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "$ref": {"$ref": "#/$defs/is-string"} + }, + "$defs": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": false + } + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": {"type": "string"}, + "nodes": { + "type": "array", + "items": {"$ref": "node"} + } + }, + "required": ["meta", "nodes"], + "$defs": { + "node": { + "$id": "http://localhost:1234/draft2020-12/node", + "description": "node", + "type": "object", + "properties": { + "value": {"type": "number"}, + "subtree": {"$ref": "tree"} + }, + "required": ["value"] + } + } + }, + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 1.1}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": true + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + {"value": "string is invalid"}, + {"value": 1.2} + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + {"value": 2.1}, + {"value": 2.2} + ] + } + } + ] + }, + "valid": false + } + ] + }, + { + "description": "refs with quote", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo\"bar": {"$ref": "#/$defs/foo%22bar"} + }, + "$defs": { + "foo\"bar": {"type": "number"} + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "ref creates new scope when adjacent to keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "A": { + "unevaluatedProperties": false + } + }, + "properties": { + "prop1": { + "type": "string" + } + }, + "$ref": "#/$defs/A" + }, + "tests": [ + { + "description": "referenced subschema doesn't see annotations from properties", + "data": { + "prop1": "match" + }, + "valid": false + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/$defs/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/$defs/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-relative-uri-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-refs-absolute-uris-defs2.json" + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/a.json", + "$defs": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "$defs": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/draft2020-12/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id1-int.json", + "$id": "/draft2020-12/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/draft2020-12/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json#/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id2#/$defs/smallint; another valid uri for this location: https://example.com/ref-and-id2/#bigint", + "$id": "https://example.com/draft2020-12/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 ยง2.2", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.1", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.2", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "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": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar"} + }, + "$defs": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "$defs": { + "bar": { + "$anchor": "something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN ref with nested pointer ref", + "schema": { + "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "foo": { + "$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": {"bar": {"type": "string"}}, + "$ref": "#/$defs/bar" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": "bar", + "valid": true + }, + { + "description": "a non-string is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "$ref": "http://example.com/ref/if", + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to then", + "schema": { + "$ref": "http://example.com/ref/then", + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to else", + "schema": { + "$ref": "http://example.com/ref/else", + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "$defs": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "$ref": "/absref/foobar.json" + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$defs": { + "": { + "$defs": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/refRemote.json b/tests/draft2020-12/refRemote.json new file mode 100644 index 00000000..2d4f99e7 --- /dev/null +++ b/tests/draft2020-12/refRemote.json @@ -0,0 +1,314 @@ +[ + { + "description": "remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/integer.json" + }, + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "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" + }, + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "anchor within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#foo" + }, + "tests": [ + { + "description": "remote anchor valid", + "data": 1, + "valid": true + }, + { + "description": "remote anchor invalid", + "data": "a", + "valid": false + } + ] + }, + { + "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" + }, + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "base URI change", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/", + "items": { + "$id": "baseUriChange/", + "items": {"$ref": "folderInteger.json"} + } + }, + "tests": [ + { + "description": "base URI change ref valid", + "data": [[1]], + "valid": true + }, + { + "description": "base URI change ref invalid", + "data": [["a"]], + "valid": false + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/scope_change_defs1.json", + "type" : "object", + "properties": {"list": {"$ref": "baseUriChangeFolder/"}}, + "$defs": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/scope_change_defs2.json", + "type" : "object", + "properties": {"list": {"$ref": "baseUriChangeFolderInSubschema/#/$defs/bar"}}, + "$defs": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "$defs": { + "bar": { + "type": "array", + "items": {"$ref": "folderInteger.json"} + } + } + } + } + }, + "tests": [ + { + "description": "number is valid", + "data": {"list": [1]}, + "valid": true + }, + { + "description": "string is invalid", + "data": {"list": ["a"]}, + "valid": false + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/object", + "type": "object", + "properties": { + "name": {"$ref": "name-defs.json#/$defs/orNull"} + } + }, + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false + } + ] + }, + { + "description": "remote ref with ref to defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/schema-remote-ref-ref-defs1.json", + "$ref": "ref-and-defs.json" + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#/$defs/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different $id", + "schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with different URN $id", + "schema": {"$ref": "http://localhost:1234/urn-ref-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "remote HTTP ref with nested absolute ref", + "schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"}, + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/required.json b/tests/draft2020-12/required.json new file mode 100644 index 00000000..b7cb99a6 --- /dev/null +++ b/tests/draft2020-12/required.json @@ -0,0 +1,158 @@ +[ + { + "description": "required validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "required": ["foo"] + }, + "tests": [ + { + "description": "present required property is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": {"bar": 1}, + "valid": false + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": ["__proto__", "toString", "constructor"] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/tests/draft2020-12/type.json b/tests/draft2020-12/type.json new file mode 100644 index 00000000..2123c408 --- /dev/null +++ b/tests/draft2020-12/type.json @@ -0,0 +1,501 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": ["integer", "string"] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": ["string"] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": ["array", "object"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": ["array", "object", "null"] + }, + "tests": [ + { + "description": "array is valid", + "data": [1,2,3], + "valid": true + }, + { + "description": "object is valid", + "data": {"foo": 123}, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json new file mode 100644 index 00000000..2615c4c4 --- /dev/null +++ b/tests/draft2020-12/unevaluatedItems.json @@ -0,0 +1,719 @@ +[ + { + "description": "unevaluatedItems true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": true + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": { "type": "string" } + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with valid unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with invalid unevaluated items", + "data": [42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with uniform items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { "type": "string" }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", "bar"], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with items and prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "type": "string" } + ], + "items": true, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": ["foo", 42], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": {"type": "number"}, + "unevaluatedItems": {"type": "string"} + }, + "tests": [ + { + "description": "valid under items", + "comment": "no elements are considered by unevaluatedItems", + "data": [5, 6, 7, 8], + "valid": true + }, + { + "description": "invalid under items", + "data": ["foo", "bar", "baz"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "type": "string" } + ], + "allOf": [ + { + "prefixItems": [ + true, + { "type": "number" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", 42], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", 42, true], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": {"type": "boolean"}, + "anyOf": [ + { "items": {"type": "string"} }, + true + ] + }, + "tests": [ + { + "description": "with only (valid) additional items", + "data": [true, false], + "valid": true + }, + { + "description": "with no additional items", + "data": ["yes", "no"], + "valid": true + }, + { + "description": "with invalid additional item", + "data": ["yes", false], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with nested prefixItems and items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + { "type": "string" } + ], + "items": true + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with nested unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + { "type": "string" } + ] + }, + { "unevaluatedItems": true } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no additional items", + "data": ["foo"], + "valid": true + }, + { + "description": "with additional items", + "data": ["foo", 42, true], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "const": "foo" } + ], + "anyOf": [ + { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + { + "prefixItems": [ + true, + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when one schema matches and has no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "when one schema matches and has unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + }, + { + "description": "when two schemas match and has no unevaluated items", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "when two schemas match and has unevaluated items", + "data": ["foo", "bar", "baz", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "const": "foo" } + ], + "oneOf": [ + { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + { + "prefixItems": [ + true, + { "const": "baz" } + ] + } + ], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": ["foo", "bar"], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo", "bar", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "const": "foo" } + ], + "not": { + "not": { + "prefixItems": [ + true, + { "const": "bar" } + ] + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with unevaluated items", + "data": ["foo", "bar"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { "const": "foo" } + ], + "if": { + "prefixItems": [ + true, + { "const": "bar" } + ] + }, + "then": { + "prefixItems": [ + true, + true, + { "const": "then" } + ] + }, + "else": { + "prefixItems": [ + true, + true, + true, + { "const": "else" } + ] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "when if matches and it has no unevaluated items", + "data": ["foo", "bar", "then"], + "valid": true + }, + { + "description": "when if matches and it has unevaluated items", + "data": ["foo", "bar", "then", "else"], + "valid": false + }, + { + "description": "when if doesn't match and it has no unevaluated items", + "data": ["foo", 42, 42, "else"], + "valid": true + }, + { + "description": "when if doesn't match and it has unevaluated items", + "data": ["foo", 42, 42, "else", 42], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [true], + "unevaluatedItems": false + }, + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true + }, + { + "description": "with unevaluated items", + "data": ["foo"], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bar", + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ true ] + }, + { "unevaluatedItems": false } + ] + }, + "tests": [ + { + "description": "always fails", + "data": [ 1 ], + "valid": false + } + ] + }, + { + "description": "item is evaluated in an uncle schema to unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "prefixItems": [ + { "type": "string" } + ], + "unevaluatedItems": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "prefixItems": [ + true, + { "type": "string" } + ] + } + } + } + ] + }, + "tests": [ + { + "description": "no extra items", + "data": { + "foo": [ + "test" + ] + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": [ + "test", + "test" + ] + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on adjacent contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [true], + "contains": {"type": "string"}, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "second item is evaluated by contains", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "contains fails, second item is not evaluated", + "data": [ 1, 2 ], + "valid": false + }, + { + "description": "contains passes, second item is not evaluated", + "data": [ 1, 2, "foo" ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems depends on multiple nested contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { "contains": { "multipleOf": 2 } }, + { "contains": { "multipleOf": 3 } } + ], + "unevaluatedItems": { "multipleOf": 5 } + }, + "tests": [ + { + "description": "5 not evaluated, passes unevaluatedItems", + "data": [ 2, 3, 4, 5, 6 ], + "valid": true + }, + { + "description": "7 not evaluated, fails unevaluatedItems", + "data": [ 2, 3, 4, 7, 8 ], + "valid": false + } + ] + }, + { + "description": "unevaluatedItems and contains interact to control item dependency relationship", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "contains": {"const": "a"} + }, + "then": { + "if": { + "contains": {"const": "b"} + }, + "then": { + "if": { + "contains": {"const": "c"} + } + } + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "empty array is valid", + "data": [], + "valid": true + }, + { + "description": "only a's are valid", + "data": [ "a", "a" ], + "valid": true + }, + { + "description": "a's and b's are valid", + "data": [ "a", "b", "a", "b", "a" ], + "valid": true + }, + { + "description": "a's, b's and c's are valid", + "data": [ "c", "a", "c", "c", "b", "a" ], + "valid": true + }, + { + "description": "only b's are invalid", + "data": [ "b", "b" ], + "valid": false + }, + { + "description": "only c's are invalid", + "data": [ "c", "c" ], + "valid": false + }, + { + "description": "only b's and c's are invalid", + "data": [ "c", "b", "c", "b", "c" ], + "valid": false + }, + { + "description": "only a's and c's are invalid", + "data": [ "c", "a", "c", "a", "c" ], + "valid": false + } + ] + }, + { + "description": "non-array instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "unevaluatedItems can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "prefixItems": [{"const": "a"}] + }, + "unevaluatedItems": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": [ "a" ], + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": [ "b" ], + "valid": false + } + + ] + } +] diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json new file mode 100644 index 00000000..f7fb420f --- /dev/null +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -0,0 +1,1475 @@ +[ + { + "description": "unevaluatedProperties true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": { + "type": "string", + "minLength": 3 + } + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with valid unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with invalid unevaluated properties", + "data": { + "foo": "fo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^foo": { "type": "string" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with adjacent additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "additionalProperties": true, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "properties": { + "bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "patternProperties": { + "^bar": { "type": "string" } + } + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with nested additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "additionalProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with nested unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": { + "type": "string", + "maxLength": 2 + } + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "anyOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + }, + { + "properties": { + "quux": { "const": "quux" } + }, + "required": ["quux"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when one matches and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when one matches and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "not-baz" + }, + "valid": false + }, + { + "description": "when two match and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": true + }, + { + "description": "when two match and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz", + "quux": "not-quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "oneOf": [ + { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + }, + { + "properties": { + "baz": { "const": "baz" } + }, + "required": ["baz"] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "quux": "quux" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "not": { + "not": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "if": { + "properties": { + "foo": { "const": "then" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "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" } + }, + "required": ["foo"] + }, + "else": { + "properties": { + "baz": { "type": "string" } + }, + "required": ["baz"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": false + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "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" } + }, + "required": ["foo"] + }, + "then": { + "properties": { + "bar": { "type": "string" } + }, + "required": ["bar"] + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": false + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with dependentSchemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": { "const": "bar" } + }, + "required": ["bar"] + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "allOf": [true], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "$ref": "#/$defs/bar", + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false, + "$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 can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins (reverse order)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "unevaluatedProperties": false + }, + { + "properties": { + "foo": true + } + } + ] + }, + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "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" } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + } + ] + }, + { + "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" } + }, + "allOf": [ + { + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, true with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": true + }, + { + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, false with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "unevaluatedProperties": true + }, + { + "properties": { + "foo": { "type": "string" } + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false + } + ] + }, + { + "description": "property is evaluated in an uncle schema to unevaluatedProperties", + "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" + } + }, + "unevaluatedProperties": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "properties": { + "faz": { + "type": "string" + } + } + } + } + } + ] + }, + "tests": [ + { + "description": "no extra properties", + "data": { + "foo": { + "bar": "test" + } + }, + "valid": true + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": { + "bar": "test", + "faz": "test" + } + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, allOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + }, + "unevaluatedProperties": false + } + ], + "anyOf": [ + { + "properties": { + "bar": true + } + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": false + } + ] + }, + { + "description": "in-place applicator siblings, anyOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + } + ], + "anyOf": [ + { + "properties": { + "bar": true + }, + "unevaluatedProperties": false + } + ] + }, + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties + single cyclic ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "x": { "$ref": "#" } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is valid", + "data": {}, + "valid": true + }, + { + "description": "Single is valid", + "data": { "x": {} }, + "valid": true + }, + { + "description": "Unevaluated on 1st level is invalid", + "data": { "x": {}, "y": {} }, + "valid": false + }, + { + "description": "Nested is valid", + "data": { "x": { "x": {} } }, + "valid": true + }, + { + "description": "Unevaluated on 2nd level is invalid", + "data": { "x": { "x": {}, "y": {} } }, + "valid": false + }, + { + "description": "Deep nested is valid", + "data": { "x": { "x": { "x": {} } } }, + "valid": true + }, + { + "description": "Unevaluated on 3rd level is invalid", + "data": { "x": { "x": { "x": {}, "y": {} } } }, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties + ref inside allOf / oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "one": { + "properties": { "a": true } + }, + "two": { + "required": ["x"], + "properties": { "x": true } + } + }, + "allOf": [ + { "$ref": "#/$defs/one" }, + { "properties": { "b": true } }, + { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { + "required": ["y"], + "properties": { "y": true } + } + ] + } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid (no x or y)", + "data": {}, + "valid": false + }, + { + "description": "a and b are invalid (no x or y)", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "x and y are invalid", + "data": { "x": 1, "y": 1 }, + "valid": false + }, + { + "description": "a and x are valid", + "data": { "a": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and y are valid", + "data": { "a": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x are valid", + "data": { "a": 1, "b": 1, "x": 1 }, + "valid": true + }, + { + "description": "a and b and y are valid", + "data": { "a": 1, "b": 1, "y": 1 }, + "valid": true + }, + { + "description": "a and b and x and y are invalid", + "data": { "a": 1, "b": 1, "x": 1, "y": 1 }, + "valid": false + } + ] + }, + { + "description": "dynamic evalation inside nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "one": { + "oneOf": [ + { "$ref": "#/$defs/two" }, + { "required": ["b"], "properties": { "b": true } }, + { "required": ["xx"], "patternProperties": { "x": true } }, + { "required": ["all"], "unevaluatedProperties": true } + ] + }, + "two": { + "oneOf": [ + { "required": ["c"], "properties": { "c": true } }, + { "required": ["d"], "properties": { "d": true } } + ] + } + }, + "oneOf": [ + { "$ref": "#/$defs/one" }, + { "required": ["a"], "properties": { "a": true } } + ], + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "Empty is invalid", + "data": {}, + "valid": false + }, + { + "description": "a is valid", + "data": { "a": 1 }, + "valid": true + }, + { + "description": "b is valid", + "data": { "b": 1 }, + "valid": true + }, + { + "description": "c is valid", + "data": { "c": 1 }, + "valid": true + }, + { + "description": "d is valid", + "data": { "d": 1 }, + "valid": true + }, + { + "description": "a + b is invalid", + "data": { "a": 1, "b": 1 }, + "valid": false + }, + { + "description": "a + c is invalid", + "data": { "a": 1, "c": 1 }, + "valid": false + }, + { + "description": "a + d is invalid", + "data": { "a": 1, "d": 1 }, + "valid": false + }, + { + "description": "b + c is invalid", + "data": { "b": 1, "c": 1 }, + "valid": false + }, + { + "description": "b + d is invalid", + "data": { "b": 1, "d": 1 }, + "valid": false + }, + { + "description": "c + d is invalid", + "data": { "c": 1, "d": 1 }, + "valid": false + }, + { + "description": "xx is valid", + "data": { "xx": 1 }, + "valid": true + }, + { + "description": "xx + foox is valid", + "data": { "xx": 1, "foox": 1 }, + "valid": true + }, + { + "description": "xx + foo is invalid", + "data": { "xx": 1, "foo": 1 }, + "valid": false + }, + { + "description": "xx + a is invalid", + "data": { "xx": 1, "a": 1 }, + "valid": false + }, + { + "description": "xx + b is invalid", + "data": { "xx": 1, "b": 1 }, + "valid": false + }, + { + "description": "xx + c is invalid", + "data": { "xx": 1, "c": 1 }, + "valid": false + }, + { + "description": "xx + d is invalid", + "data": { "xx": 1, "d": 1 }, + "valid": false + }, + { + "description": "all is valid", + "data": { "all": 1 }, + "valid": true + }, + { + "description": "all + foo is valid", + "data": { "all": 1, "foo": 1 }, + "valid": true + }, + { + "description": "all + a is invalid", + "data": { "all": 1, "a": 1 }, + "valid": false + } + ] + }, + { + "description": "non-object instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null valued properties", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "unevaluatedProperties not affected by propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": {"maxLength": 1}, + "unevaluatedProperties": { + "type": "number" + } + }, + "tests": [ + { + "description": "allows only number properties", + "data": {"a": 1}, + "valid": true + }, + { + "description": "string property is invalid", + "data": {"a": "b"}, + "valid": false + } + ] + }, + { + "description": "unevaluatedProperties can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "patternProperties": { + "foo": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "valid in case if is evaluated", + "data": { + "foo": "a" + }, + "valid": true + }, + { + "description": "invalid in case if is evaluated", + "data": { + "bar": "a" + }, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/uniqueItems.json b/tests/draft2020-12/uniqueItems.json new file mode 100644 index 00000000..4ea3bf98 --- /dev/null +++ b/tests/draft2020-12/uniqueItems.json @@ -0,0 +1,419 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": false + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1, "{}"], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [{}, [1], true, null, {}, 1], + "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [false, false], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [true, true], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [false, true, "foo", "foo"], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [true, false, "foo", "foo"], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, + "items": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [false, false], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [true, true], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "items": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/unknownKeyword.json b/tests/draft2020-12/unknownKeyword.json new file mode 100644 index 00000000..28b0c4ce --- /dev/null +++ b/tests/draft2020-12/unknownKeyword.json @@ -0,0 +1,57 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { "$ref": "#/$defs/id_in_unknown0" }, + { "$ref": "#/$defs/id_in_unknown1" }, + { "$ref": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft2020-12/vocabulary.json b/tests/draft2020-12/vocabulary.json new file mode 100644 index 00000000..1acb96a9 --- /dev/null +++ b/tests/draft2020-12/vocabulary.json @@ -0,0 +1,57 @@ +[ + { + "description": "schema that uses custom metaschema with with no validation vocabulary", + "schema": { + "$id": "https://schema/using/no/validation", + "$schema": "http://localhost:1234/draft2020-12/metaschema-no-validation.json", + "properties": { + "badProperty": false, + "numberProperty": { + "minimum": 10 + } + } + }, + "tests": [ + { + "description": "applicator vocabulary still works", + "data": { + "badProperty": "this property should not exist" + }, + "valid": false + }, + { + "description": "no validation: valid number", + "data": { + "numberProperty": 20 + }, + "valid": true + }, + { + "description": "no validation: invalid number, but it still validates", + "data": { + "numberProperty": 1 + }, + "valid": true + } + ] + }, + { + "description": "ignore unrecognized optional vocabulary", + "schema": { + "$schema": "http://localhost:1234/draft2020-12/metaschema-optional-vocabulary.json", + "type": "number" + }, + "tests": [ + { + "description": "string value", + "data": "foobar", + "valid": false + }, + { + "description": "number value", + "data": 20, + "valid": true + } + ] + } +] diff --git a/tests/draft3/additionalItems.json b/tests/draft3/additionalItems.json index 6d4bff51..0cb66870 100644 --- a/tests/draft3/additionalItems.json +++ b/tests/draft3/additionalItems.json @@ -19,7 +19,7 @@ ] }, { - "description": "items is schema, no additionalItems", + "description": "when items is schema, additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -33,14 +33,29 @@ ] }, { - "description": "array of items with no additionalItems", + "description": "array of items with no additionalItems permitted", "schema": { "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { - "description": "no additional items present", + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", + "data": [ 1, 2 ], + "valid": true + }, + { + "description": "equal number of items present", "data": [ 1, 2, 3 ], "valid": true }, @@ -70,13 +85,44 @@ }, { "description": "additionalItems are allowed by default", - "schema": {"items": []}, + "schema": {"items": [{"type": "integer"}]}, "tests": [ { - "description": "only the first items are validated", + "description": "only the first item is validated", "data": [1, "foo", false], "valid": true } ] + }, + { + "description": "additionalItems does not look in applicators", + "schema": { + "extends": [ + { "items": [ { "type": "integer" } ] } + ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in extends are not examined", + "data": [ 1, null ], + "valid": true + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft3/additionalProperties.json b/tests/draft3/additionalProperties.json index bfb0844a..af7bfc6f 100644 --- a/tests/draft3/additionalProperties.json +++ b/tests/draft3/additionalProperties.json @@ -60,8 +60,7 @@ ] }, { - "description": - "additionalProperties allows a schema which should validate", + "description": "additionalProperties with schema", "schema": { "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} @@ -115,7 +114,7 @@ ] }, { - "description": "additionalProperties should not look in applicators", + "description": "additionalProperties does not look in applicators", "schema": { "extends": [ {"properties": {"foo": {}}} @@ -124,10 +123,25 @@ }, "tests": [ { - "description": "properties defined in extends are not allowed", + "description": "properties defined in extends are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft3/default.json b/tests/draft3/default.json index 17629779..289a9b66 100644 --- a/tests/draft3/default.json +++ b/tests/draft3/default.json @@ -45,5 +45,35 @@ "valid": true } ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft3/dependencies.json b/tests/draft3/dependencies.json index d7e09256..0ffa6bf4 100644 --- a/tests/draft3/dependencies.json +++ b/tests/draft3/dependencies.json @@ -98,6 +98,11 @@ "data": {"foo": 1, "bar": 2}, "valid": true }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, { "description": "wrong type", "data": {"foo": "quux", "bar": 2}, diff --git a/tests/draft3/enum.json b/tests/draft3/enum.json index fc3e0707..5a1ab3b6 100644 --- a/tests/draft3/enum.json +++ b/tests/draft3/enum.json @@ -36,6 +36,27 @@ } ] }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { "enum": [6, null] }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, { "description": "enums in properties", "schema": { @@ -51,6 +72,16 @@ "data": {"foo":"foo", "bar":"bar"}, "valid": true }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, @@ -67,5 +98,21 @@ "valid": false } ] + }, + { + "description": "nul characters in strings", + "schema": { "enum": [ "hello\u0000there" ] }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft3/format.json b/tests/draft3/format.json index 82793362..a5447c90 100644 --- a/tests/draft3/format.json +++ b/tests/draft3/format.json @@ -1,359 +1,359 @@ [ { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "description": "email format", + "schema": { "format": "email" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IP addresses", - "schema": {"format": "ip-address"}, + "description": "ip-address format", + "schema": { "format": "ip-address" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "description": "ipv6 format", + "schema": { "format": "ipv6" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of hostnames", - "schema": {"format": "host-name"}, + "description": "host-name format", + "schema": { "format": "host-name" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "description": "date-time format", + "schema": { "format": "date-time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of regular expressions", - "schema": {"format": "regex"}, + "description": "regex format", + "schema": { "format": "regex" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date strings", - "schema": {"format": "date"}, + "description": "date format", + "schema": { "format": "date" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of time strings", - "schema": {"format": "time"}, + "description": "time format", + "schema": { "format": "time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of CSS colors", - "schema": {"format": "color"}, + "description": "color format", + "schema": { "format": "color" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URIs", - "schema": {"format": "uri"}, + "description": "uri format", + "schema": { "format": "uri" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } diff --git a/tests/draft3/infinite-loop-detection.json b/tests/draft3/infinite-loop-detection.json new file mode 100644 index 00000000..090f49a0 --- /dev/null +++ b/tests/draft3/infinite-loop-detection.json @@ -0,0 +1,32 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + }, + "extends": { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft3/items.json b/tests/draft3/items.json index f5e18a13..e8bda222 100644 --- a/tests/draft3/items.json +++ b/tests/draft3/items.json @@ -42,5 +42,37 @@ "valid": false } ] + }, + { + "description": "items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft3/maximum.json b/tests/draft3/maximum.json index 86c7b89c..ccb79c6c 100644 --- a/tests/draft3/maximum.json +++ b/tests/draft3/maximum.json @@ -8,6 +8,63 @@ "data": 2.6, "valid": true }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": {"maximum": 300}, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + }, + { + "description": "maximum validation (explicit false exclusivity)", + "schema": {"maximum": 3.0, "exclusiveMaximum": false}, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, { "description": "above the maximum is invalid", "data": 3.5, diff --git a/tests/draft3/minimum.json b/tests/draft3/minimum.json index 5ac9feef..d579536e 100644 --- a/tests/draft3/minimum.json +++ b/tests/draft3/minimum.json @@ -8,6 +8,11 @@ "data": 2.6, "valid": true }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, { "description": "below the minimum is invalid", "data": 0.6, @@ -59,7 +64,17 @@ "valid": true }, { - "description": "below the minimum is invalid", + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", "data": -3, "valid": false }, diff --git a/tests/draft3/optional/bignum.json b/tests/draft3/optional/bignum.json index ccc7c17f..1bc8eb21 100644 --- a/tests/draft3/optional/bignum.json +++ b/tests/draft3/optional/bignum.json @@ -1,30 +1,13 @@ [ { "description": "integer", - "schema": {"type": "integer"}, + "schema": { "type": "integer" }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true - } - ] - }, - { - "description": "number", - "schema": {"type": "number"}, - "tests": [ - { - "description": "a bignum is a number", - "data": 98249283749234923498293171823948729348710298301928331, - "valid": true - } - ] - }, - { - "description": "integer", - "schema": {"type": "integer"}, - "tests": [ + }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, @@ -34,8 +17,13 @@ }, { "description": "number", - "schema": {"type": "number"}, + "schema": { "type": "number" }, "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, @@ -45,7 +33,7 @@ }, { "description": "string", - "schema": {"type": "string"}, + "schema": { "type": "string" }, "tests": [ { "description": "a bignum is not a string", @@ -55,8 +43,8 @@ ] }, { - "description": "integer comparison", - "schema": {"maximum": 18446744073709551615}, + "description": "maximum integer comparison", + "schema": { "maximum": 18446744073709551615 }, "tests": [ { "description": "comparison works for high numbers", @@ -80,8 +68,8 @@ ] }, { - "description": "integer comparison", - "schema": {"minimum": -18446744073709551615}, + "description": "minimum integer comparison", + "schema": { "minimum": -18446744073709551615 }, "tests": [ { "description": "comparison works for very negative numbers", diff --git a/tests/draft3/optional/format.json b/tests/draft3/optional/format.json deleted file mode 100644 index 9864589d..00000000 --- a/tests/draft3/optional/format.json +++ /dev/null @@ -1,227 +0,0 @@ -[ - { - "description": "validation of regular expressions", - "schema": {"format": "regex"}, - "tests": [ - { - "description": "a valid regular expression", - "data": "([abc])+\\s+$", - "valid": true - }, - { - "description": "a regular expression with unclosed parens is invalid", - "data": "^(abc]", - "valid": false - } - ] - }, - { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, - "tests": [ - { - "description": "a valid date-time string", - "data": "1963-06-19T08:30:06.283185Z", - "valid": true - }, - { - "description": "an invalid date-time string", - "data": "06/19/1963 08:30:06 PST", - "valid": false - }, - { - "description": "case-insensitive T and Z", - "data": "1963-06-19t08:30:06.283185z", - "valid": true - }, - { - "description": "only RFC3339 not all of ISO 8601 are valid", - "data": "2013-350T01:01:01", - "valid": false - } - ] - }, - { - "description": "validation of date strings", - "schema": {"format": "date"}, - "tests": [ - { - "description": "a valid date string", - "data": "1963-06-19", - "valid": true - }, - { - "description": "an invalid date string", - "data": "06/19/1963", - "valid": false - } - ] - }, - { - "description": "validation of time strings", - "schema": {"format": "time"}, - "tests": [ - { - "description": "a valid time string", - "data": "08:30:06", - "valid": true - }, - { - "description": "an invalid time string", - "data": "8:30 AM", - "valid": false - } - ] - }, - { - "description": "validation of URIs", - "schema": {"format": "uri"}, - "tests": [ - { - "description": "a valid URI", - "data": "http://foo.bar/?baz=qux#quux", - "valid": true - }, - { - "description": "an invalid protocol-relative URI Reference", - "data": "//foo.bar/?baz=qux#quux", - "valid": false - }, - { - "description": "an invalid URI", - "data": "\\\\WINDOWS\\fileshare", - "valid": false - }, - { - "description": "an invalid URI though valid URI reference", - "data": "abc", - "valid": false - } - ] - }, - { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, - "tests": [ - { - "description": "a valid e-mail address", - "data": "joe.bloggs@example.com", - "valid": true - }, - { - "description": "an invalid e-mail address", - "data": "2962", - "valid": false - } - ] - }, - { - "description": "validation of IP addresses", - "schema": {"format": "ip-address"}, - "tests": [ - { - "description": "a valid IP address", - "data": "192.168.0.1", - "valid": true - }, - { - "description": "an IP address with too many components", - "data": "127.0.0.0.1", - "valid": false - }, - { - "description": "an IP address with out-of-range values", - "data": "256.256.256.256", - "valid": false - } - ] - }, - { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, - "tests": [ - { - "description": "a valid IPv6 address", - "data": "::1", - "valid": true - }, - { - "description": "an IPv6 address with out-of-range values", - "data": "12345::", - "valid": false - }, - { - "description": "an IPv6 address with too many components", - "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", - "valid": false - }, - { - "description": "an IPv6 address containing illegal characters", - "data": "::laptop", - "valid": false - } - ] - }, - { - "description": "validation of host names", - "schema": {"format": "host-name"}, - "tests": [ - { - "description": "a valid host name", - "data": "www.example.com", - "valid": true - }, - { - "description": "a host name starting with an illegal character", - "data": "-a-host-name-that-starts-with--", - "valid": false - }, - { - "description": "a host name containing illegal characters", - "data": "not_a_valid_host_name", - "valid": false - }, - { - "description": "a host name with a component too long", - "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", - "valid": false - } - ] - }, - { - "description": "validation of CSS colors", - "schema": {"format": "color"}, - "tests": [ - { - "description": "a valid CSS color name", - "data": "fuchsia", - "valid": true - }, - { - "description": "a valid six-digit CSS color code", - "data": "#CC8899", - "valid": true - }, - { - "description": "a valid three-digit CSS color code", - "data": "#C89", - "valid": true - }, - { - "description": "an invalid CSS color code", - "data": "#00332520", - "valid": false - }, - { - "description": "an invalid CSS color name", - "data": "puce", - "valid": false - }, - { - "description": "a CSS color name containing invalid characters", - "data": "light_grayish_red-violet", - "valid": false - } - ] - } -] diff --git a/tests/draft3/optional/format/color.json b/tests/draft3/optional/format/color.json new file mode 100644 index 00000000..0c0b5348 --- /dev/null +++ b/tests/draft3/optional/format/color.json @@ -0,0 +1,38 @@ +[ + { + "description": "validation of CSS colors", + "schema": { "format": "color" }, + "tests": [ + { + "description": "a valid CSS color name", + "data": "fuchsia", + "valid": true + }, + { + "description": "a valid six-digit CSS color code", + "data": "#CC8899", + "valid": true + }, + { + "description": "a valid three-digit CSS color code", + "data": "#C89", + "valid": true + }, + { + "description": "an invalid CSS color code", + "data": "#00332520", + "valid": false + }, + { + "description": "an invalid CSS color name", + "data": "puce", + "valid": false + }, + { + "description": "a CSS color name containing invalid characters", + "data": "light_grayish_red-violet", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/date-time.json b/tests/draft3/optional/format/date-time.json new file mode 100644 index 00000000..1f1e6fb3 --- /dev/null +++ b/tests/draft3/optional/format/date-time.json @@ -0,0 +1,38 @@ +[ + { + "description": "validation of date-time strings", + "schema": { "format": "date-time" }, + "tests": [ + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/date.json b/tests/draft3/optional/format/date.json new file mode 100644 index 00000000..796bc463 --- /dev/null +++ b/tests/draft3/optional/format/date.json @@ -0,0 +1,168 @@ +[ + { + "description": "validation of date strings", + "schema": { "format": "date" }, + "tests": [ + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false + }, + { + "description": "invalidates non-padded month dates", + "data": "1998-1-20", + "valid": false + }, + { + "description": "invalidates non-padded day dates", + "data": "1998-01-1", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/email.json b/tests/draft3/optional/format/email.json new file mode 100644 index 00000000..059615ad --- /dev/null +++ b/tests/draft3/optional/format/email.json @@ -0,0 +1,53 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { "format": "email" }, + "tests": [ + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/host-name.json b/tests/draft3/optional/format/host-name.json new file mode 100644 index 00000000..d418f376 --- /dev/null +++ b/tests/draft3/optional/format/host-name.json @@ -0,0 +1,63 @@ +[ + { + "description": "validation of host names", + "schema": { "format": "host-name" }, + "tests": [ + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/ip-address.json b/tests/draft3/optional/format/ip-address.json new file mode 100644 index 00000000..91cac9fa --- /dev/null +++ b/tests/draft3/optional/format/ip-address.json @@ -0,0 +1,23 @@ +[ + { + "description": "validation of IP addresses", + "schema": { "format": "ip-address" }, + "tests": [ + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/ipv6.json b/tests/draft3/optional/format/ipv6.json new file mode 100644 index 00000000..c3ef3790 --- /dev/null +++ b/tests/draft3/optional/format/ipv6.json @@ -0,0 +1,68 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { "format": "ipv6" }, + "tests": [ + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/regex.json b/tests/draft3/optional/format/regex.json new file mode 100644 index 00000000..8a377638 --- /dev/null +++ b/tests/draft3/optional/format/regex.json @@ -0,0 +1,18 @@ +[ + { + "description": "validation of regular expressions", + "schema": { "format": "regex" }, + "tests": [ + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/time.json b/tests/draft3/optional/format/time.json new file mode 100644 index 00000000..36c823e6 --- /dev/null +++ b/tests/draft3/optional/format/time.json @@ -0,0 +1,18 @@ +[ + { + "description": "validation of time strings", + "schema": { "format": "time" }, + "tests": [ + { + "description": "a valid time string", + "data": "08:30:06", + "valid": true + }, + { + "description": "an invalid time string", + "data": "8:30 AM", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/format/uri.json b/tests/draft3/optional/format/uri.json new file mode 100644 index 00000000..f024b624 --- /dev/null +++ b/tests/draft3/optional/format/uri.json @@ -0,0 +1,28 @@ +[ + { + "description": "validation of URIs", + "schema": { "format": "uri" }, + "tests": [ + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/non-bmp-regex.json b/tests/draft3/optional/non-bmp-regex.json new file mode 100644 index 00000000..dd67af2b --- /dev/null +++ b/tests/draft3/optional/non-bmp-regex.json @@ -0,0 +1,82 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { "pattern": "^๐Ÿฒ*$" }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft3/pattern.json b/tests/draft3/pattern.json index 25e72997..92db0f97 100644 --- a/tests/draft3/pattern.json +++ b/tests/draft3/pattern.json @@ -14,9 +14,34 @@ "valid": false }, { - "description": "ignores non-strings", + "description": "ignores booleans", "data": true, "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true } ] }, diff --git a/tests/draft3/patternProperties.json b/tests/draft3/patternProperties.json index 2ca9aaeb..b0f2a8e4 100644 --- a/tests/draft3/patternProperties.json +++ b/tests/draft3/patternProperties.json @@ -111,5 +111,20 @@ "valid": false } ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] } ] diff --git a/tests/draft3/properties.json b/tests/draft3/properties.json index a830c67e..cd238011 100644 --- a/tests/draft3/properties.json +++ b/tests/draft3/properties.json @@ -93,5 +93,20 @@ "valid": false } ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft3/ref.json b/tests/draft3/ref.json index 31414ad6..609eaa46 100644 --- a/tests/draft3/ref.json +++ b/tests/draft3/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilda~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilda": {"$ref": "#/tilda~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ @@ -91,8 +93,8 @@ "valid": false }, { - "description": "tilda invalid", - "data": {"tilda": "aoeu"}, + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, "valid": false }, { @@ -106,8 +108,8 @@ "valid": true }, { - "description": "tilda valid", - "data": {"tilda": 123}, + "description": "tilde valid", + "data": {"tilde": 123}, "valid": true }, { @@ -173,6 +175,67 @@ } ] }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, + { + "description": "$ref prevents a sibling id from changing the base uri", + "schema": { + "id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "id": "foo.json", + "type": "number" + } + }, + "extends": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-03/schema#"}, @@ -188,5 +251,28 @@ "valid": false } ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "definitions": { + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/definitions/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/definitions/a_string" }, + "valid": true + } + ] } ] diff --git a/tests/draft3/refRemote.json b/tests/draft3/refRemote.json index 4ca80473..de0cb43a 100644 --- a/tests/draft3/refRemote.json +++ b/tests/draft3/refRemote.json @@ -54,7 +54,7 @@ "schema": { "id": "http://localhost:1234/", "items": { - "id": "folder/", + "id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, diff --git a/tests/draft3/type.json b/tests/draft3/type.json index 49c9b40a..8447bc8e 100644 --- a/tests/draft3/type.json +++ b/tests/draft3/type.json @@ -54,6 +54,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is a number", + "data": 1.0, + "valid": true + }, { "description": "a float is a number", "data": 1.1, @@ -430,8 +435,7 @@ ] }, { - "description": - "when types includes a schema it should fully validate the schema", + "description": "applies a nested schema", "schema": { "type": [ "integer", diff --git a/tests/draft3/uniqueItems.json b/tests/draft3/uniqueItems.json index 59e3542c..c48c6a06 100644 --- a/tests/draft3/uniqueItems.json +++ b/tests/draft3/uniqueItems.json @@ -13,11 +13,26 @@ "data": [1, 1], "valid": false }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], "valid": false }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -54,6 +69,11 @@ "data": [["foo"], ["foo"]], "valid": false }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, { "description": "1 and true are unique", "data": [1, true], @@ -64,6 +84,26 @@ "data": [0, false], "valid": true }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, { "description": "unique heterogeneous types are valid", "data": [{}, [1], true, null, 1], @@ -73,13 +113,23 @@ "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, { "description": "uniqueItems with an array of items", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], + "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true }, "tests": [ @@ -128,8 +178,8 @@ { "description": "uniqueItems with an array of items and additionalItems=false", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], - "uniqueItems": true, + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, "additionalItems": false }, "tests": [ @@ -159,5 +209,166 @@ "valid": false } ] + }, + { + "description": "uniqueItems=false validation", + "schema": { "uniqueItems": false }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] } ] diff --git a/tests/draft4/additionalItems.json b/tests/draft4/additionalItems.json index abecc578..deb44fd3 100644 --- a/tests/draft4/additionalItems.json +++ b/tests/draft4/additionalItems.json @@ -19,7 +19,7 @@ ] }, { - "description": "items is schema, no additionalItems", + "description": "when items is schema, additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -33,14 +33,24 @@ ] }, { - "description": "array of items with no additionalItems", + "description": "array of items with no additionalItems permitted", "schema": { "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { - "description": "fewer number of items present", + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", "data": [ 1, 2 ], "valid": true }, @@ -83,5 +93,72 @@ "valid": true } ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" } ] } + ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, null ], + "valid": true + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" }, { "type": "string" } ] } + ], + "items": [ {"type": "integer" } ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, "hello" ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ { "type": "string" } ], + "additionalItems": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft4/additionalProperties.json b/tests/draft4/additionalProperties.json index ffeac6b3..0f8e1627 100644 --- a/tests/draft4/additionalProperties.json +++ b/tests/draft4/additionalProperties.json @@ -60,8 +60,7 @@ ] }, { - "description": - "additionalProperties allows a schema which should validate", + "description": "additionalProperties with schema", "schema": { "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} @@ -115,7 +114,7 @@ ] }, { - "description": "additionalProperties should not look in applicators", + "description": "additionalProperties does not look in applicators", "schema": { "allOf": [ {"properties": {"foo": {}}} @@ -124,10 +123,25 @@ }, "tests": [ { - "description": "properties defined in allOf are not allowed", + "description": "properties defined in allOf are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft4/allOf.json b/tests/draft4/allOf.json index ce9fdd46..fc7dec59 100644 --- a/tests/draft4/allOf.json +++ b/tests/draft4/allOf.json @@ -181,5 +181,81 @@ "valid": false } ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] } ] diff --git a/tests/draft4/default.json b/tests/draft4/default.json index 17629779..289a9b66 100644 --- a/tests/draft4/default.json +++ b/tests/draft4/default.json @@ -45,5 +45,35 @@ "valid": true } ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft4/definitions.json b/tests/draft4/definitions.json index cf935a32..482823be 100644 --- a/tests/draft4/definitions.json +++ b/tests/draft4/definitions.json @@ -1,6 +1,6 @@ [ { - "description": "valid definition", + "description": "validate definition against metaschema", "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, "tests": [ { @@ -11,13 +11,7 @@ } }, "valid": true - } - ] - }, - { - "description": "invalid definition", - "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, - "tests": [ + }, { "description": "invalid definition schema", "data": { diff --git a/tests/draft4/dependencies.json b/tests/draft4/dependencies.json index 51eeddf3..9045ddc2 100644 --- a/tests/draft4/dependencies.json +++ b/tests/draft4/dependencies.json @@ -190,5 +190,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft4/enum.json b/tests/draft4/enum.json index 32d79026..f085097b 100644 --- a/tests/draft4/enum.json +++ b/tests/draft4/enum.json @@ -33,6 +33,37 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { "enum": [6, null] }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false } ] }, @@ -52,6 +83,16 @@ "data": {"foo":"foo", "bar":"bar"}, "valid": true }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, @@ -175,5 +216,21 @@ "valid": true } ] + }, + { + "description": "nul characters in strings", + "schema": { "enum": [ "hello\u0000there" ] }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft4/format.json b/tests/draft4/format.json index 61e4b62a..5bd83cc6 100644 --- a/tests/draft4/format.json +++ b/tests/draft4/format.json @@ -1,215 +1,215 @@ [ { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "description": "email format", + "schema": { "format": "email" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "description": "ipv4 format", + "schema": { "format": "ipv4" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "description": "ipv6 format", + "schema": { "format": "ipv6" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of hostnames", - "schema": {"format": "hostname"}, + "description": "hostname format", + "schema": { "format": "hostname" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "description": "date-time format", + "schema": { "format": "date-time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URIs", - "schema": {"format": "uri"}, + "description": "uri format", + "schema": { "format": "uri" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } diff --git a/tests/draft4/id.json b/tests/draft4/id.json new file mode 100644 index 00000000..1c91d33e --- /dev/null +++ b/tests/draft4/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": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "id": "https://localhost:1234/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/definitions/id_in_enum" }, + { "$ref": "https://localhost:1234/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false + } + ] + } + +] diff --git a/tests/draft4/infinite-loop-detection.json b/tests/draft4/infinite-loop-detection.json new file mode 100644 index 00000000..f98c74fc --- /dev/null +++ b/tests/draft4/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft4/items.json b/tests/draft4/items.json index 7bf9f02b..16ea0704 100644 --- a/tests/draft4/items.json +++ b/tests/draft4/items.json @@ -191,5 +191,37 @@ "valid": false } ] + }, + { + "description": "items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft4/maxProperties.json b/tests/draft4/maxProperties.json index 513731e4..aa7209f5 100644 --- a/tests/draft4/maxProperties.json +++ b/tests/draft4/maxProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { "maxProperties": 0 }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] } ] diff --git a/tests/draft4/maximum.json b/tests/draft4/maximum.json index 02581f62..ccb79c6c 100644 --- a/tests/draft4/maximum.json +++ b/tests/draft4/maximum.json @@ -25,6 +25,32 @@ } ] }, + { + "description": "maximum validation with unsigned integer", + "schema": {"maximum": 300}, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + }, { "description": "maximum validation (explicit false exclusivity)", "schema": {"maximum": 3.0, "exclusiveMaximum": false}, diff --git a/tests/draft4/minimum.json b/tests/draft4/minimum.json index 6becf2a8..22d310e1 100644 --- a/tests/draft4/minimum.json +++ b/tests/draft4/minimum.json @@ -90,7 +90,17 @@ "valid": true }, { - "description": "below the minimum is invalid", + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", "data": -3, "valid": false }, diff --git a/tests/draft4/multipleOf.json b/tests/draft4/multipleOf.json index ca3b7618..ed2df4a7 100644 --- a/tests/draft4/multipleOf.json +++ b/tests/draft4/multipleOf.json @@ -56,5 +56,27 @@ "valid": false } ] + }, + { + "description": "float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/tests/draft4/oneOf.json b/tests/draft4/oneOf.json index 9dfffe13..fb63b089 100644 --- a/tests/draft4/oneOf.json +++ b/tests/draft4/oneOf.json @@ -158,5 +158,73 @@ "valid": false } ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": {}, + "baz": {} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] } ] diff --git a/tests/draft4/optional/bignum.json b/tests/draft4/optional/bignum.json index ccc7c17f..1bc8eb21 100644 --- a/tests/draft4/optional/bignum.json +++ b/tests/draft4/optional/bignum.json @@ -1,30 +1,13 @@ [ { "description": "integer", - "schema": {"type": "integer"}, + "schema": { "type": "integer" }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true - } - ] - }, - { - "description": "number", - "schema": {"type": "number"}, - "tests": [ - { - "description": "a bignum is a number", - "data": 98249283749234923498293171823948729348710298301928331, - "valid": true - } - ] - }, - { - "description": "integer", - "schema": {"type": "integer"}, - "tests": [ + }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, @@ -34,8 +17,13 @@ }, { "description": "number", - "schema": {"type": "number"}, + "schema": { "type": "number" }, "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, @@ -45,7 +33,7 @@ }, { "description": "string", - "schema": {"type": "string"}, + "schema": { "type": "string" }, "tests": [ { "description": "a bignum is not a string", @@ -55,8 +43,8 @@ ] }, { - "description": "integer comparison", - "schema": {"maximum": 18446744073709551615}, + "description": "maximum integer comparison", + "schema": { "maximum": 18446744073709551615 }, "tests": [ { "description": "comparison works for high numbers", @@ -80,8 +68,8 @@ ] }, { - "description": "integer comparison", - "schema": {"minimum": -18446744073709551615}, + "description": "minimum integer comparison", + "schema": { "minimum": -18446744073709551615 }, "tests": [ { "description": "comparison works for very negative numbers", diff --git a/tests/draft4/optional/ecmascript-regex.json b/tests/draft4/optional/ecmascript-regex.json index d82e0feb..c431baca 100644 --- a/tests/draft4/optional/ecmascript-regex.json +++ b/tests/draft4/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { @@ -18,32 +7,32 @@ }, "tests": [ { - "description": "matches in Python, but should not in jsonschema", - "data": "abc\n", + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", "valid": false }, { - "description": "should match", + "description": "matches", "data": "abc", "valid": true } ] }, { - "description": "ECMA 262 regex converts \\a to ascii BEL", + "description": "ECMA 262 regex converts \\t to horizontal tab", "schema": { "type": "string", - "pattern": "^\\a$" + "pattern": "^\\t$" }, "tests": [ { "description": "does not match", - "data": "\\a", + "data": "\\t", "valid": false }, { "description": "matches", - "data": "\u0007", + "data": "\u0009", "valid": true } ] @@ -154,7 +143,7 @@ ] }, { - "description": "ECMA 262 \\w matches everything but ascii letters", + "description": "ECMA 262 \\W matches everything but ascii letters", "schema": { "type": "string", "pattern": "^\\W$" @@ -173,7 +162,7 @@ ] }, { - "description": "ECMA 262 \\s matches ascii whitespace only", + "description": "ECMA 262 \\s matches whitespace", "schema": { "type": "string", "pattern": "^\\s$" @@ -185,14 +174,59 @@ "valid": true }, { - "description": "latin-1 non-breaking-space does not match (unlike e.g. Python)", + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", "valid": false } ] }, { - "description": "ECMA 262 \\S matches everything but ascii whitespace", + "description": "ECMA 262 \\S matches everything but whitespace", "schema": { "type": "string", "pattern": "^\\S$" @@ -204,8 +238,313 @@ "valid": false }, { - "description": "latin-1 non-breaking-space matches (unlike e.g. Python)", + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { "pattern": "\\p{Letter}cole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { "pattern": "\\wcole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { "pattern": "[a-z]cole" }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { "pattern": "^\\d+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { "pattern": "^\\p{digit}+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, "valid": true } ] diff --git a/tests/draft4/optional/float-overflow.json b/tests/draft4/optional/float-overflow.json new file mode 100644 index 00000000..47fd5baa --- /dev/null +++ b/tests/draft4/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "number", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft4/optional/format.json b/tests/draft4/optional/format.json deleted file mode 100644 index 4bf4ea8e..00000000 --- a/tests/draft4/optional/format.json +++ /dev/null @@ -1,253 +0,0 @@ -[ - { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, - "tests": [ - { - "description": "a valid date-time string", - "data": "1963-06-19T08:30:06.283185Z", - "valid": true - }, - { - "description": "a valid date-time string without second fraction", - "data": "1963-06-19T08:30:06Z", - "valid": true - }, - { - "description": "a valid date-time string with plus offset", - "data": "1937-01-01T12:00:27.87+00:20", - "valid": true - }, - { - "description": "a valid date-time string with minus offset", - "data": "1990-12-31T15:59:50.123-08:00", - "valid": true - }, - { - "description": "a invalid day in date-time string", - "data": "1990-02-31T15:59:60.123-08:00", - "valid": false - }, - { - "description": "an invalid offset in date-time string", - "data": "1990-12-31T15:59:60-24:00", - "valid": false - }, - { - "description": "an invalid date-time string", - "data": "06/19/1963 08:30:06 PST", - "valid": false - }, - { - "description": "case-insensitive T and Z", - "data": "1963-06-19t08:30:06.283185z", - "valid": true - }, - { - "description": "only RFC3339 not all of ISO 8601 are valid", - "data": "2013-350T01:01:01", - "valid": false - } - ] - }, - { - "description": "validation of URIs", - "schema": {"format": "uri"}, - "tests": [ - { - "description": "a valid URL with anchor tag", - "data": "http://foo.bar/?baz=qux#quux", - "valid": true - }, - { - "description": "a valid URL with anchor tag and parantheses", - "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", - "valid": true - }, - { - "description": "a valid URL with URL-encoded stuff", - "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", - "valid": true - }, - { - "description": "a valid puny-coded URL ", - "data": "http://xn--nw2a.xn--j6w193g/", - "valid": true - }, - { - "description": "a valid URL with many special characters", - "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", - "valid": true - }, - { - "description": "a valid URL based on IPv4", - "data": "http://223.255.255.254", - "valid": true - }, - { - "description": "a valid URL with ftp scheme", - "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", - "valid": true - }, - { - "description": "a valid URL for a simple text file", - "data": "http://www.ietf.org/rfc/rfc2396.txt", - "valid": true - }, - { - "description": "a valid URL ", - "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", - "valid": true - }, - { - "description": "a valid mailto URI", - "data": "mailto:John.Doe@example.com", - "valid": true - }, - { - "description": "a valid newsgroup URI", - "data": "news:comp.infosystems.www.servers.unix", - "valid": true - }, - { - "description": "a valid tel URI", - "data": "tel:+1-816-555-1212", - "valid": true - }, - { - "description": "a valid URN", - "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", - "valid": true - }, - { - "description": "an invalid protocol-relative URI Reference", - "data": "//foo.bar/?baz=qux#quux", - "valid": false - }, - { - "description": "an invalid relative URI Reference", - "data": "/abc", - "valid": false - }, - { - "description": "an invalid URI", - "data": "\\\\WINDOWS\\fileshare", - "valid": false - }, - { - "description": "an invalid URI though valid URI reference", - "data": "abc", - "valid": false - }, - { - "description": "an invalid URI with spaces", - "data": "http:// shouldfail.com", - "valid": false - }, - { - "description": "an invalid URI with spaces and missing scheme", - "data": ":// should fail", - "valid": false - } - ] - }, - { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, - "tests": [ - { - "description": "a valid e-mail address", - "data": "joe.bloggs@example.com", - "valid": true - }, - { - "description": "an invalid e-mail address", - "data": "2962", - "valid": false - } - ] - }, - { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, - "tests": [ - { - "description": "a valid IP address", - "data": "192.168.0.1", - "valid": true - }, - { - "description": "an IP address with too many components", - "data": "127.0.0.0.1", - "valid": false - }, - { - "description": "an IP address with out-of-range values", - "data": "256.256.256.256", - "valid": false - }, - { - "description": "an IP address without 4 components", - "data": "127.0", - "valid": false - }, - { - "description": "an IP address as an integer", - "data": "0x7f000001", - "valid": false - } - ] - }, - { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, - "tests": [ - { - "description": "a valid IPv6 address", - "data": "::1", - "valid": true - }, - { - "description": "an IPv6 address with out-of-range values", - "data": "12345::", - "valid": false - }, - { - "description": "an IPv6 address with too many components", - "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", - "valid": false - }, - { - "description": "an IPv6 address containing illegal characters", - "data": "::laptop", - "valid": false - } - ] - }, - { - "description": "validation of host names", - "schema": {"format": "hostname"}, - "tests": [ - { - "description": "a valid host name", - "data": "www.example.com", - "valid": true - }, - { - "description": "a host name starting with an illegal character", - "data": "-a-host-name-that-starts-with--", - "valid": false - }, - { - "description": "a host name containing illegal characters", - "data": "not_a_valid_host_name", - "valid": false - }, - { - "description": "a host name with a component too long", - "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", - "valid": false - } - ] - } -] diff --git a/tests/draft4/optional/format/date-time.json b/tests/draft4/optional/format/date-time.json new file mode 100644 index 00000000..09112737 --- /dev/null +++ b/tests/draft4/optional/format/date-time.json @@ -0,0 +1,133 @@ +[ + { + "description": "validation of date-time strings", + "schema": { "format": "date-time" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/format/email.json b/tests/draft4/optional/format/email.json new file mode 100644 index 00000000..d6761a46 --- /dev/null +++ b/tests/draft4/optional/format/email.json @@ -0,0 +1,83 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { "format": "email" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/format/hostname.json b/tests/draft4/optional/format/hostname.json new file mode 100644 index 00000000..8a67fda8 --- /dev/null +++ b/tests/draft4/optional/format/hostname.json @@ -0,0 +1,98 @@ +[ + { + "description": "validation of host names", + "schema": { "format": "hostname" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/format/ipv4.json b/tests/draft4/optional/format/ipv4.json new file mode 100644 index 00000000..4706581f --- /dev/null +++ b/tests/draft4/optional/format/ipv4.json @@ -0,0 +1,84 @@ +[ + { + "description": "validation of IP addresses", + "schema": { "format": "ipv4" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/format/ipv6.json b/tests/draft4/optional/format/ipv6.json new file mode 100644 index 00000000..94368f2a --- /dev/null +++ b/tests/draft4/optional/format/ipv6.json @@ -0,0 +1,208 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { "format": "ipv6" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/format/unknown.json b/tests/draft4/optional/format/unknown.json new file mode 100644 index 00000000..12339ae5 --- /dev/null +++ b/tests/draft4/optional/format/unknown.json @@ -0,0 +1,43 @@ +[ + { + "description": "unknown format", + "schema": { "format": "unknown" }, + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true + } + ] + } +] diff --git a/tests/draft4/optional/format/uri.json b/tests/draft4/optional/format/uri.json new file mode 100644 index 00000000..4b48d406 --- /dev/null +++ b/tests/draft4/optional/format/uri.json @@ -0,0 +1,138 @@ +[ + { + "description": "validation of URIs", + "schema": { "format": "uri" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/non-bmp-regex.json b/tests/draft4/optional/non-bmp-regex.json new file mode 100644 index 00000000..dd67af2b --- /dev/null +++ b/tests/draft4/optional/non-bmp-regex.json @@ -0,0 +1,82 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { "pattern": "^๐Ÿฒ*$" }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft4/pattern.json b/tests/draft4/pattern.json index 25e72997..92db0f97 100644 --- a/tests/draft4/pattern.json +++ b/tests/draft4/pattern.json @@ -14,9 +14,34 @@ "valid": false }, { - "description": "ignores non-strings", + "description": "ignores booleans", "data": true, "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true } ] }, diff --git a/tests/draft4/patternProperties.json b/tests/draft4/patternProperties.json index 5f741dfc..51c8af3d 100644 --- a/tests/draft4/patternProperties.json +++ b/tests/draft4/patternProperties.json @@ -116,5 +116,20 @@ "valid": false } ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] } ] diff --git a/tests/draft4/properties.json b/tests/draft4/properties.json index 688527bc..195159e6 100644 --- a/tests/draft4/properties.json +++ b/tests/draft4/properties.json @@ -132,5 +132,74 @@ "valid": false } ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index 51e750fb..b53bd2ab 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilda~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilda": {"$ref": "#/tilda~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ @@ -91,8 +93,8 @@ "valid": false }, { - "description": "tilda invalid", - "data": {"tilda": "aoeu"}, + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, "valid": false }, { @@ -106,8 +108,8 @@ "valid": true }, { - "description": "tilda valid", - "data": {"tilda": 123}, + "description": "tilde valid", + "data": {"tilde": 123}, "valid": true }, { @@ -125,7 +127,7 @@ "b": {"$ref": "#/definitions/a"}, "c": {"$ref": "#/definitions/b"} }, - "$ref": "#/definitions/c" + "allOf": [{ "$ref": "#/definitions/c" }] }, "tests": [ { @@ -173,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling id from changing the base uri", + "schema": { + "id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, @@ -209,6 +247,31 @@ } ] }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, { "description": "Recursive references between schemas", "schema": { @@ -351,15 +414,21 @@ ] }, { - "description": "Location-independent identifier with absolute URI", + "description": "Location-independent identifier with base URI change in subschema", "schema": { + "id": "http://localhost:1234/root", "allOf": [{ - "$ref": "http://localhost:1234/bar#foo" + "$ref": "http://localhost:1234/nested.json#foo" }], "definitions": { "A": { - "id": "http://localhost:1234/bar#foo", - "type": "integer" + "id": "nested.json", + "definitions": { + "B": { + "id": "#foo", + "type": "integer" + } + } } } }, @@ -377,33 +446,145 @@ ] }, { - "description": "Location-independent identifier with base URI change in subschema", + "description": "naive replacement of $ref with its destination is not correct", "schema": { - "id": "http://localhost:1234/root", - "allOf": [{ - "$ref": "http://localhost:1234/nested.json#foo" - }], "definitions": { - "A": { - "id": "nested.json", - "definitions": { - "B": { - "id": "#foo", - "type": "integer" + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/definitions/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/definitions/a_string" }, + "valid": true + } + ] + }, + { + "description": "id must be resolved against nearest parent, not just immediate parent", + "schema": { + "id": "http://example.com/a.json", + "definitions": { + "x": { + "id": "http://example.com/b/c.json", + "not": { + "definitions": { + "y": { + "id": "d.json", + "type": "number" + } } } } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false } + ] + }, + { + "description": "id with file URI still resolves pointers - *nix", + "schema": { + "id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] }, "tests": [ { + "description": "number is valid", "data": 1, - "description": "match", "valid": true }, { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "id with file URI still resolves pointers - windows", + "schema": { + "id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", "data": "a", - "description": "mismatch", "valid": false } ] diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 8611fadc..412c9ff8 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -54,7 +54,7 @@ "schema": { "id": "http://localhost:1234/", "items": { - "id": "folder/", + "id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "id": "folder/", + "id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "id": "folder/", + "id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", @@ -167,5 +167,23 @@ "valid": false } ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierDraft4.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft4/required.json b/tests/draft4/required.json index 9b05318f..6ccfdc2d 100644 --- a/tests/draft4/required.json +++ b/tests/draft4/required.json @@ -85,5 +85,51 @@ "valid": false } ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { "required": ["__proto__", "toString", "constructor"] }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft4/type.json b/tests/draft4/type.json index ea33b182..df46677b 100644 --- a/tests/draft4/type.json +++ b/tests/draft4/type.json @@ -54,6 +54,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is a number", + "data": 1.0, + "valid": true + }, { "description": "a float is a number", "data": 1.1, diff --git a/tests/draft4/uniqueItems.json b/tests/draft4/uniqueItems.json index d312ad71..d2730c60 100644 --- a/tests/draft4/uniqueItems.json +++ b/tests/draft4/uniqueItems.json @@ -13,6 +13,11 @@ "data": [1, 1], "valid": false }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], @@ -28,6 +33,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -38,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ @@ -64,6 +84,11 @@ "data": [["foo"], ["foo"]], "valid": false }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, { "description": "1 and true are unique", "data": [1, true], @@ -74,22 +99,62 @@ "data": [0, false], "valid": true }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, { "description": "unique heterogeneous types are valid", - "data": [{}, [1], true, null, 1], + "data": [{}, [1], true, null, 1, "{}"], "valid": true }, { "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, { "description": "uniqueItems with an array of items", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], + "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true }, "tests": [ @@ -138,8 +203,8 @@ { "description": "uniqueItems with an array of items and additionalItems=false", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], - "uniqueItems": true, + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, "additionalItems": false }, "tests": [ @@ -169,5 +234,176 @@ "valid": false } ] + }, + { + "description": "uniqueItems=false validation", + "schema": { "uniqueItems": false }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] } ] diff --git a/tests/draft6/additionalItems.json b/tests/draft6/additionalItems.json index abecc578..cae72361 100644 --- a/tests/draft6/additionalItems.json +++ b/tests/draft6/additionalItems.json @@ -19,7 +19,30 @@ ] }, { - "description": "items is schema, no additionalItems", + "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [1,2,3], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [1,"2","3"], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -33,14 +56,24 @@ ] }, { - "description": "array of items with no additionalItems", + "description": "array of items with no additionalItems permitted", "schema": { "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { - "description": "fewer number of items present", + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", "data": [ 1, 2 ], "valid": true }, @@ -83,5 +116,72 @@ "valid": true } ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" } ] } + ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, null ], + "valid": true + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" }, { "type": "string" } ] } + ], + "items": [ {"type": "integer" } ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, "hello" ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ { "type": "string" } ], + "additionalItems": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft6/additionalProperties.json b/tests/draft6/additionalProperties.json index ffeac6b3..0f8e1627 100644 --- a/tests/draft6/additionalProperties.json +++ b/tests/draft6/additionalProperties.json @@ -60,8 +60,7 @@ ] }, { - "description": - "additionalProperties allows a schema which should validate", + "description": "additionalProperties with schema", "schema": { "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} @@ -115,7 +114,7 @@ ] }, { - "description": "additionalProperties should not look in applicators", + "description": "additionalProperties does not look in applicators", "schema": { "allOf": [ {"properties": {"foo": {}}} @@ -124,10 +123,25 @@ }, "tests": [ { - "description": "properties defined in allOf are not allowed", + "description": "properties defined in allOf are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft6/allOf.json b/tests/draft6/allOf.json index eb612091..ec9319e1 100644 --- a/tests/draft6/allOf.json +++ b/tests/draft6/allOf.json @@ -214,5 +214,81 @@ "valid": false } ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] } ] diff --git a/tests/draft6/const.json b/tests/draft6/const.json index c089625d..1c2cafcc 100644 --- a/tests/draft6/const.json +++ b/tests/draft6/const.json @@ -126,7 +126,91 @@ ] }, { - "description": "const with 0 does not match false", + "description": "const with [false] does not match [0]", + "schema": {"const": [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": "const with [true] does not match [1]", + "schema": {"const": [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": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": {"const": {"a": false}}, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": {"const": {"a": true}}, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, "tests": [ { @@ -143,6 +227,21 @@ "description": "float zero is valid", "data": 0.0, "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false } ] }, @@ -166,5 +265,78 @@ "valid": true } ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": {"const": -2.0}, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": {"const": 9007199254740992}, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { "const": "hello\u0000there" }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft6/contains.json b/tests/draft6/contains.json index 67ecbd99..bd93654f 100644 --- a/tests/draft6/contains.json +++ b/tests/draft6/contains.json @@ -96,5 +96,49 @@ "valid": true } ] + }, + { + "description": "items + contains", + "schema": { + "items": { "multipleOf": 2 }, + "contains": { "multipleOf": 3 } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ 2, 4, 8 ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ 3, 6, 9 ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ 6, 12 ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ 1, 5 ], + "valid": false + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft6/default.json b/tests/draft6/default.json index 17629779..289a9b66 100644 --- a/tests/draft6/default.json +++ b/tests/draft6/default.json @@ -45,5 +45,35 @@ "valid": true } ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft6/definitions.json b/tests/draft6/definitions.json index 7f3b8997..d772fde3 100644 --- a/tests/draft6/definitions.json +++ b/tests/draft6/definitions.json @@ -1,6 +1,6 @@ [ { - "description": "valid definition", + "description": "validate definition against metaschema", "schema": {"$ref": "http://json-schema.org/draft-06/schema#"}, "tests": [ { @@ -11,13 +11,7 @@ } }, "valid": true - } - ] - }, - { - "description": "invalid definition", - "schema": {"$ref": "http://json-schema.org/draft-06/schema#"}, - "tests": [ + }, { "description": "invalid definition schema", "data": { diff --git a/tests/draft6/dependencies.json b/tests/draft6/dependencies.json index 8dd78aa5..c0bd809f 100644 --- a/tests/draft6/dependencies.json +++ b/tests/draft6/dependencies.json @@ -57,6 +57,11 @@ "description": "object with one property", "data": {"bar": 2}, "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true } ] }, @@ -169,31 +174,6 @@ } ] }, - { - "description": "empty array of dependencies", - "schema": { - "dependencies": { - "foo": [] - } - }, - "tests": [ - { - "description": "object with property is valid", - "data": { "foo": 1 }, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "non-object is valid", - "data": 1, - "valid": true - } - ] - }, { "description": "dependencies with escaped characters", "schema": { @@ -264,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft6/enum.json b/tests/draft6/enum.json index 32d79026..f085097b 100644 --- a/tests/draft6/enum.json +++ b/tests/draft6/enum.json @@ -33,6 +33,37 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { "enum": [6, null] }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false } ] }, @@ -52,6 +83,16 @@ "data": {"foo":"foo", "bar":"bar"}, "valid": true }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, @@ -175,5 +216,21 @@ "valid": true } ] + }, + { + "description": "nul characters in strings", + "schema": { "enum": [ "hello\u0000there" ] }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft6/format.json b/tests/draft6/format.json index 32e81524..2df2a9f0 100644 --- a/tests/draft6/format.json +++ b/tests/draft6/format.json @@ -1,323 +1,323 @@ [ { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "description": "email format", + "schema": { "format": "email" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "description": "ipv4 format", + "schema": { "format": "ipv4" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "description": "ipv6 format", + "schema": { "format": "ipv6" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of hostnames", - "schema": {"format": "hostname"}, + "description": "hostname format", + "schema": { "format": "hostname" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "description": "date-time format", + "schema": { "format": "date-time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of JSON pointers", - "schema": {"format": "json-pointer"}, + "description": "json-pointer format", + "schema": { "format": "json-pointer" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URIs", - "schema": {"format": "uri"}, + "description": "uri format", + "schema": { "format": "uri" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI references", - "schema": {"format": "uri-reference"}, + "description": "uri-reference format", + "schema": { "format": "uri-reference" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI templates", - "schema": {"format": "uri-template"}, + "description": "uri-template format", + "schema": { "format": "uri-template" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } diff --git a/tests/draft6/id.json b/tests/draft6/id.json new file mode 100644 index 00000000..03d30fcb --- /dev/null +++ b/tests/draft6/id.json @@ -0,0 +1,134 @@ +[ + { + "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": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/definitions/id_in_enum" }, + { "$ref": "https://localhost:1234/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "definitions": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "oneOf": [ + { + "const": "skip not_a_real_anchor" + }, + { + "allOf": [ + { + "not": { + "const": "skip not_a_real_anchor" + } + }, + { + "$ref": "#/definitions/const_not_anchor" + } + ] + } + ] + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "definitions": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "oneOf": [ + { + "const":"skip not_a_real_id" + }, + { + "allOf": [ + { + "not": { + "const": "skip not_a_real_id" + } + }, + { + "$ref": "#/definitions/const_not_id" + } + ] + } + ] + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft6/infinite-loop-detection.json b/tests/draft6/infinite-loop-detection.json new file mode 100644 index 00000000..f98c74fc --- /dev/null +++ b/tests/draft6/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft6/items.json b/tests/draft6/items.json index 67f11840..7ed6781b 100644 --- a/tests/draft6/items.json +++ b/tests/draft6/items.json @@ -246,5 +246,37 @@ "valid": false } ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft6/maxItems.json b/tests/draft6/maxItems.json index 3b53a6b3..f0c36ab2 100644 --- a/tests/draft6/maxItems.json +++ b/tests/draft6/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft6/maxLength.json b/tests/draft6/maxLength.json index 811d35b2..748b4daa 100644 --- a/tests/draft6/maxLength.json +++ b/tests/draft6/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft6/maxProperties.json b/tests/draft6/maxProperties.json index 513731e4..acec1420 100644 --- a/tests/draft6/maxProperties.json +++ b/tests/draft6/maxProperties.json @@ -34,5 +34,37 @@ "valid": true } ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { "maxProperties": 0 }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] } ] diff --git a/tests/draft6/maximum.json b/tests/draft6/maximum.json index 8150984e..6844a39e 100644 --- a/tests/draft6/maximum.json +++ b/tests/draft6/maximum.json @@ -24,5 +24,31 @@ "valid": true } ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": {"maximum": 300}, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] } ] diff --git a/tests/draft6/minItems.json b/tests/draft6/minItems.json index ed511881..d3b18720 100644 --- a/tests/draft6/minItems.json +++ b/tests/draft6/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft6/minLength.json b/tests/draft6/minLength.json index 3f09158d..64db9480 100644 --- a/tests/draft6/minLength.json +++ b/tests/draft6/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft6/minProperties.json b/tests/draft6/minProperties.json index 49a0726e..9f74f789 100644 --- a/tests/draft6/minProperties.json +++ b/tests/draft6/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft6/minimum.json b/tests/draft6/minimum.json index 2a9c42b3..21ae50e0 100644 --- a/tests/draft6/minimum.json +++ b/tests/draft6/minimum.json @@ -45,7 +45,17 @@ "valid": true }, { - "description": "below the minimum is invalid", + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", "data": -3, "valid": false }, diff --git a/tests/draft6/multipleOf.json b/tests/draft6/multipleOf.json index ca3b7618..e606979b 100644 --- a/tests/draft6/multipleOf.json +++ b/tests/draft6/multipleOf.json @@ -56,5 +56,27 @@ "valid": false } ] + }, + { + "description": "float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/tests/draft6/oneOf.json b/tests/draft6/oneOf.json index 57640b7a..eeb7ae86 100644 --- a/tests/draft6/oneOf.json +++ b/tests/draft6/oneOf.json @@ -202,5 +202,73 @@ "valid": false } ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": ["bar"] + }, + { + "properties": { + "foo": true + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] } ] diff --git a/tests/draft6/optional/bignum.json b/tests/draft6/optional/bignum.json index fac275e2..94b4a4e6 100644 --- a/tests/draft6/optional/bignum.json +++ b/tests/draft6/optional/bignum.json @@ -1,30 +1,13 @@ [ { "description": "integer", - "schema": {"type": "integer"}, + "schema": { "type": "integer" }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true - } - ] - }, - { - "description": "number", - "schema": {"type": "number"}, - "tests": [ - { - "description": "a bignum is a number", - "data": 98249283749234923498293171823948729348710298301928331, - "valid": true - } - ] - }, - { - "description": "integer", - "schema": {"type": "integer"}, - "tests": [ + }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, @@ -34,8 +17,13 @@ }, { "description": "number", - "schema": {"type": "number"}, + "schema": { "type": "number" }, "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, @@ -45,7 +33,7 @@ }, { "description": "string", - "schema": {"type": "string"}, + "schema": { "type": "string" }, "tests": [ { "description": "a bignum is not a string", @@ -55,8 +43,8 @@ ] }, { - "description": "integer comparison", - "schema": {"maximum": 18446744073709551615}, + "description": "maximum integer comparison", + "schema": { "maximum": 18446744073709551615 }, "tests": [ { "description": "comparison works for high numbers", @@ -79,8 +67,8 @@ ] }, { - "description": "integer comparison", - "schema": {"minimum": -18446744073709551615}, + "description": "minimum integer comparison", + "schema": { "minimum": -18446744073709551615 }, "tests": [ { "description": "comparison works for very negative numbers", diff --git a/tests/draft6/optional/ecmascript-regex.json b/tests/draft6/optional/ecmascript-regex.json index d82e0feb..c4886aaa 100644 --- a/tests/draft6/optional/ecmascript-regex.json +++ b/tests/draft6/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { @@ -18,32 +7,32 @@ }, "tests": [ { - "description": "matches in Python, but should not in jsonschema", - "data": "abc\n", + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", "valid": false }, { - "description": "should match", + "description": "matches", "data": "abc", "valid": true } ] }, { - "description": "ECMA 262 regex converts \\a to ascii BEL", + "description": "ECMA 262 regex converts \\t to horizontal tab", "schema": { "type": "string", - "pattern": "^\\a$" + "pattern": "^\\t$" }, "tests": [ { "description": "does not match", - "data": "\\a", + "data": "\\t", "valid": false }, { "description": "matches", - "data": "\u0007", + "data": "\u0009", "valid": true } ] @@ -154,7 +143,7 @@ ] }, { - "description": "ECMA 262 \\w matches everything but ascii letters", + "description": "ECMA 262 \\W matches everything but ascii letters", "schema": { "type": "string", "pattern": "^\\W$" @@ -173,7 +162,7 @@ ] }, { - "description": "ECMA 262 \\s matches ascii whitespace only", + "description": "ECMA 262 \\s matches whitespace", "schema": { "type": "string", "pattern": "^\\s$" @@ -185,14 +174,59 @@ "valid": true }, { - "description": "latin-1 non-breaking-space does not match (unlike e.g. Python)", + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", "valid": false } ] }, { - "description": "ECMA 262 \\S matches everything but ascii whitespace", + "description": "ECMA 262 \\S matches everything but whitespace", "schema": { "type": "string", "pattern": "^\\S$" @@ -204,8 +238,313 @@ "valid": false }, { - "description": "latin-1 non-breaking-space matches (unlike e.g. Python)", + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { "pattern": "\\p{Letter}cole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { "pattern": "\\wcole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { "pattern": "[a-z]cole" }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { "pattern": "^\\d+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { "pattern": "^\\p{digit}+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, "valid": true } ] diff --git a/tests/draft6/optional/float-overflow.json b/tests/draft6/optional/float-overflow.json new file mode 100644 index 00000000..52ff9827 --- /dev/null +++ b/tests/draft6/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft6/optional/format.json b/tests/draft6/optional/format.json deleted file mode 100644 index 3dd265fe..00000000 --- a/tests/draft6/optional/format.json +++ /dev/null @@ -1,491 +0,0 @@ -[ - { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, - "tests": [ - { - "description": "a valid date-time string", - "data": "1963-06-19T08:30:06.283185Z", - "valid": true - }, - { - "description": "a valid date-time string without second fraction", - "data": "1963-06-19T08:30:06Z", - "valid": true - }, - { - "description": "a valid date-time string with plus offset", - "data": "1937-01-01T12:00:27.87+00:20", - "valid": true - }, - { - "description": "a valid date-time string with minus offset", - "data": "1990-12-31T15:59:50.123-08:00", - "valid": true - }, - { - "description": "a invalid day in date-time string", - "data": "1990-02-31T15:59:60.123-08:00", - "valid": false - }, - { - "description": "an invalid offset in date-time string", - "data": "1990-12-31T15:59:60-24:00", - "valid": false - }, - { - "description": "an invalid closing Z after time-zone offset", - "data": "1963-06-19T08:30:06.28123+01:00Z", - "valid": false - }, - { - "description": "an invalid date-time string", - "data": "06/19/1963 08:30:06 PST", - "valid": false - }, - { - "description": "case-insensitive T and Z", - "data": "1963-06-19t08:30:06.283185z", - "valid": true - }, - { - "description": "only RFC3339 not all of ISO 8601 are valid", - "data": "2013-350T01:01:01", - "valid": false - } - ] - }, - { - "description": "validation of URIs", - "schema": {"format": "uri"}, - "tests": [ - { - "description": "a valid URL with anchor tag", - "data": "http://foo.bar/?baz=qux#quux", - "valid": true - }, - { - "description": "a valid URL with anchor tag and parantheses", - "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", - "valid": true - }, - { - "description": "a valid URL with URL-encoded stuff", - "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", - "valid": true - }, - { - "description": "a valid puny-coded URL ", - "data": "http://xn--nw2a.xn--j6w193g/", - "valid": true - }, - { - "description": "a valid URL with many special characters", - "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", - "valid": true - }, - { - "description": "a valid URL based on IPv4", - "data": "http://223.255.255.254", - "valid": true - }, - { - "description": "a valid URL with ftp scheme", - "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", - "valid": true - }, - { - "description": "a valid URL for a simple text file", - "data": "http://www.ietf.org/rfc/rfc2396.txt", - "valid": true - }, - { - "description": "a valid URL ", - "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", - "valid": true - }, - { - "description": "a valid mailto URI", - "data": "mailto:John.Doe@example.com", - "valid": true - }, - { - "description": "a valid newsgroup URI", - "data": "news:comp.infosystems.www.servers.unix", - "valid": true - }, - { - "description": "a valid tel URI", - "data": "tel:+1-816-555-1212", - "valid": true - }, - { - "description": "a valid URN", - "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", - "valid": true - }, - { - "description": "an invalid protocol-relative URI Reference", - "data": "//foo.bar/?baz=qux#quux", - "valid": false - }, - { - "description": "an invalid relative URI Reference", - "data": "/abc", - "valid": false - }, - { - "description": "an invalid URI", - "data": "\\\\WINDOWS\\fileshare", - "valid": false - }, - { - "description": "an invalid URI though valid URI reference", - "data": "abc", - "valid": false - }, - { - "description": "an invalid URI with spaces", - "data": "http:// shouldfail.com", - "valid": false - }, - { - "description": "an invalid URI with spaces and missing scheme", - "data": ":// should fail", - "valid": false - } - ] - }, - { - "description": "validation of URI References", - "schema": {"format": "uri-reference"}, - "tests": [ - { - "description": "a valid URI", - "data": "http://foo.bar/?baz=qux#quux", - "valid": true - }, - { - "description": "a valid protocol-relative URI Reference", - "data": "//foo.bar/?baz=qux#quux", - "valid": true - }, - { - "description": "a valid relative URI Reference", - "data": "/abc", - "valid": true - }, - { - "description": "an invalid URI Reference", - "data": "\\\\WINDOWS\\fileshare", - "valid": false - }, - { - "description": "a valid URI Reference", - "data": "abc", - "valid": true - }, - { - "description": "a valid URI fragment", - "data": "#fragment", - "valid": true - }, - { - "description": "an invalid URI fragment", - "data": "#frag\\ment", - "valid": false - } - ] - }, - { - "description": "format: uri-template", - "schema": {"format": "uri-template"}, - "tests": [ - { - "description": "a valid uri-template", - "data": "http://example.com/dictionary/{term:1}/{term}", - "valid": true - }, - { - "description": "an invalid uri-template", - "data": "http://example.com/dictionary/{term:1}/{term", - "valid": false - }, - { - "description": "a valid uri-template without variables", - "data": "http://example.com/dictionary", - "valid": true - }, - { - "description": "a valid relative uri-template", - "data": "dictionary/{term:1}/{term}", - "valid": true - } - ] - }, - { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, - "tests": [ - { - "description": "a valid e-mail address", - "data": "joe.bloggs@example.com", - "valid": true - }, - { - "description": "an invalid e-mail address", - "data": "2962", - "valid": false - } - ] - }, - { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, - "tests": [ - { - "description": "a valid IP address", - "data": "192.168.0.1", - "valid": true - }, - { - "description": "an IP address with too many components", - "data": "127.0.0.0.1", - "valid": false - }, - { - "description": "an IP address with out-of-range values", - "data": "256.256.256.256", - "valid": false - }, - { - "description": "an IP address without 4 components", - "data": "127.0", - "valid": false - }, - { - "description": "an IP address as an integer", - "data": "0x7f000001", - "valid": false - } - ] - }, - { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, - "tests": [ - { - "description": "a valid IPv6 address", - "data": "::1", - "valid": true - }, - { - "description": "an IPv6 address with out-of-range values", - "data": "12345::", - "valid": false - }, - { - "description": "an IPv6 address with too many components", - "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", - "valid": false - }, - { - "description": "an IPv6 address containing illegal characters", - "data": "::laptop", - "valid": false - } - ] - }, - { - "description": "validation of host names", - "schema": {"format": "hostname"}, - "tests": [ - { - "description": "a valid host name", - "data": "www.example.com", - "valid": true - }, - { - "description": "a host name starting with an illegal character", - "data": "-a-host-name-that-starts-with--", - "valid": false - }, - { - "description": "a host name containing illegal characters", - "data": "not_a_valid_host_name", - "valid": false - }, - { - "description": "a host name with a component too long", - "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", - "valid": false - } - ] - }, - { - "description": "validation of JSON-pointers (JSON String Representation)", - "schema": {"format": "json-pointer"}, - "tests": [ - { - "description": "a valid JSON-pointer", - "data": "/foo/bar~0/baz~1/%a", - "valid": true - }, - { - "description": "not a valid JSON-pointer (~ not escaped)", - "data": "/foo/bar~", - "valid": false - }, - { - "description": "valid JSON-pointer with empty segment", - "data": "/foo//bar", - "valid": true - }, - { - "description": "valid JSON-pointer with the last empty segment", - "data": "/foo/bar/", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #1", - "data": "", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #2", - "data": "/foo", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #3", - "data": "/foo/0", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #4", - "data": "/", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #5", - "data": "/a~1b", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #6", - "data": "/c%d", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #7", - "data": "/e^f", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #8", - "data": "/g|h", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #9", - "data": "/i\\j", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #10", - "data": "/k\"l", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #11", - "data": "/ ", - "valid": true - }, - { - "description": "valid JSON-pointer as stated in RFC 6901 #12", - "data": "/m~0n", - "valid": true - }, - { - "description": "valid JSON-pointer used adding to the last array position", - "data": "/foo/-", - "valid": true - }, - { - "description": "valid JSON-pointer (- used as object member name)", - "data": "/foo/-/bar", - "valid": true - }, - { - "description": "valid JSON-pointer (multiple escaped characters)", - "data": "/~1~0~0~1~1", - "valid": true - }, - { - "description": "valid JSON-pointer (escaped with fraction part) #1", - "data": "/~1.1", - "valid": true - }, - { - "description": "valid JSON-pointer (escaped with fraction part) #2", - "data": "/~0.1", - "valid": true - }, - { - "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", - "data": "#", - "valid": false - }, - { - "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", - "data": "#/", - "valid": false - }, - { - "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", - "data": "#a", - "valid": false - }, - { - "description": "not a valid JSON-pointer (some escaped, but not all) #1", - "data": "/~0~", - "valid": false - }, - { - "description": "not a valid JSON-pointer (some escaped, but not all) #2", - "data": "/~0/~", - "valid": false - }, - { - "description": "not a valid JSON-pointer (wrong escape character) #1", - "data": "/~2", - "valid": false - }, - { - "description": "not a valid JSON-pointer (wrong escape character) #2", - "data": "/~-1", - "valid": false - }, - { - "description": "not a valid JSON-pointer (multiple characters not escaped)", - "data": "/~~", - "valid": false - }, - { - "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", - "data": "a", - "valid": false - }, - { - "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", - "data": "0", - "valid": false - }, - { - "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", - "data": "a/a", - "valid": false - } - ] - } -] diff --git a/tests/draft6/optional/format/date-time.json b/tests/draft6/optional/format/date-time.json new file mode 100644 index 00000000..09112737 --- /dev/null +++ b/tests/draft6/optional/format/date-time.json @@ -0,0 +1,133 @@ +[ + { + "description": "validation of date-time strings", + "schema": { "format": "date-time" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/email.json b/tests/draft6/optional/format/email.json new file mode 100644 index 00000000..d6761a46 --- /dev/null +++ b/tests/draft6/optional/format/email.json @@ -0,0 +1,83 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { "format": "email" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/hostname.json b/tests/draft6/optional/format/hostname.json new file mode 100644 index 00000000..8a67fda8 --- /dev/null +++ b/tests/draft6/optional/format/hostname.json @@ -0,0 +1,98 @@ +[ + { + "description": "validation of host names", + "schema": { "format": "hostname" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/ipv4.json b/tests/draft6/optional/format/ipv4.json new file mode 100644 index 00000000..4706581f --- /dev/null +++ b/tests/draft6/optional/format/ipv4.json @@ -0,0 +1,84 @@ +[ + { + "description": "validation of IP addresses", + "schema": { "format": "ipv4" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/ipv6.json b/tests/draft6/optional/format/ipv6.json new file mode 100644 index 00000000..94368f2a --- /dev/null +++ b/tests/draft6/optional/format/ipv6.json @@ -0,0 +1,208 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { "format": "ipv6" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/json-pointer.json b/tests/draft6/optional/format/json-pointer.json new file mode 100644 index 00000000..a0346b57 --- /dev/null +++ b/tests/draft6/optional/format/json-pointer.json @@ -0,0 +1,198 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { "format": "json-pointer" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/unknown.json b/tests/draft6/optional/format/unknown.json new file mode 100644 index 00000000..12339ae5 --- /dev/null +++ b/tests/draft6/optional/format/unknown.json @@ -0,0 +1,43 @@ +[ + { + "description": "unknown format", + "schema": { "format": "unknown" }, + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true + } + ] + } +] diff --git a/tests/draft6/optional/format/uri-reference.json b/tests/draft6/optional/format/uri-reference.json new file mode 100644 index 00000000..7cdf228d --- /dev/null +++ b/tests/draft6/optional/format/uri-reference.json @@ -0,0 +1,73 @@ +[ + { + "description": "validation of URI References", + "schema": { "format": "uri-reference" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/format/uri-template.json b/tests/draft6/optional/format/uri-template.json new file mode 100644 index 00000000..df355c55 --- /dev/null +++ b/tests/draft6/optional/format/uri-template.json @@ -0,0 +1,58 @@ +[ + { + "description": "format: uri-template", + "schema": { "format": "uri-template" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true + } + ] + } +] diff --git a/tests/draft6/optional/format/uri.json b/tests/draft6/optional/format/uri.json new file mode 100644 index 00000000..4b48d406 --- /dev/null +++ b/tests/draft6/optional/format/uri.json @@ -0,0 +1,138 @@ +[ + { + "description": "validation of URIs", + "schema": { "format": "uri" }, + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/non-bmp-regex.json b/tests/draft6/optional/non-bmp-regex.json new file mode 100644 index 00000000..dd67af2b --- /dev/null +++ b/tests/draft6/optional/non-bmp-regex.json @@ -0,0 +1,82 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { "pattern": "^๐Ÿฒ*$" }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/zeroTerminatedFloats.json b/tests/draft6/optional/zeroTerminatedFloats.json deleted file mode 100644 index 1bcdf960..00000000 --- a/tests/draft6/optional/zeroTerminatedFloats.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "description": "some languages do not distinguish between different types of numeric value", - "schema": { - "type": "integer" - }, - "tests": [ - { - "description": "a float without fractional part is an integer", - "data": 1.0, - "valid": true - } - ] - } -] diff --git a/tests/draft6/pattern.json b/tests/draft6/pattern.json index 25e72997..92db0f97 100644 --- a/tests/draft6/pattern.json +++ b/tests/draft6/pattern.json @@ -14,9 +14,34 @@ "valid": false }, { - "description": "ignores non-strings", + "description": "ignores booleans", "data": true, "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true } ] }, diff --git a/tests/draft6/patternProperties.json b/tests/draft6/patternProperties.json index 1d04a167..c276e647 100644 --- a/tests/draft6/patternProperties.json +++ b/tests/draft6/patternProperties.json @@ -141,11 +141,31 @@ "data": {"foo": 1, "bar": 2}, "valid": false }, + { + "description": "object with a property matching both true and false is invalid", + "data": {"foobar":1}, + "valid": false + }, { "description": "empty object is valid", "data": {}, "valid": true } ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] } ] diff --git a/tests/draft6/properties.json b/tests/draft6/properties.json index b86c1819..5b971ca0 100644 --- a/tests/draft6/properties.json +++ b/tests/draft6/properties.json @@ -163,5 +163,74 @@ "valid": false } ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft6/propertyNames.json b/tests/draft6/propertyNames.json index 8423690d..f0788e64 100644 --- a/tests/draft6/propertyNames.json +++ b/tests/draft6/propertyNames.json @@ -43,6 +43,35 @@ } ] }, + { + "description": "propertyNames validation with pattern", + "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": {"propertyNames": true}, diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 53f3a9e9..8a8908a4 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilda~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilda": {"$ref": "#/tilda~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ @@ -91,8 +93,8 @@ "valid": false }, { - "description": "tilda invalid", - "data": {"tilda": "aoeu"}, + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, "valid": false }, { @@ -106,8 +108,8 @@ "valid": true }, { - "description": "tilda valid", - "data": {"tilda": 123}, + "description": "tilde valid", + "data": {"tilde": 123}, "valid": true }, { @@ -125,7 +127,7 @@ "b": {"$ref": "#/definitions/a"}, "c": {"$ref": "#/definitions/b"} }, - "$ref": "#/definitions/c" + "allOf": [{ "$ref": "#/definitions/c" }] }, "tests": [ { @@ -173,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-06/schema#"}, @@ -209,10 +247,35 @@ } ] }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, { "description": "$ref to boolean schema true", "schema": { - "$ref": "#/definitions/bool", + "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": true } @@ -228,7 +291,7 @@ { "description": "$ref to boolean schema false", "schema": { - "$ref": "#/definitions/bool", + "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": false } @@ -383,15 +446,21 @@ ] }, { - "description": "Location-independent identifier with absolute URI", + "description": "Location-independent identifier with base URI change in subschema", "schema": { + "$id": "http://localhost:1234/root", "allOf": [{ - "$ref": "http://localhost:1234/bar#foo" + "$ref": "http://localhost:1234/nested.json#foo" }], "definitions": { "A": { - "$id": "http://localhost:1234/bar#foo", - "type": "integer" + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } } } }, @@ -409,35 +478,425 @@ ] }, { - "description": "Location-independent identifier with base URI change in subschema", + "description": "naive replacement of $ref with its destination is not correct", "schema": { - "$id": "http://localhost:1234/root", - "allOf": [{ - "$ref": "http://localhost:1234/nested.json#foo" - }], "definitions": { - "A": { - "$id": "nested.json", + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/definitions/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/definitions/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", "definitions": { - "B": { - "$id": "#foo", - "type": "integer" + "inner": { + "properties": { + "bar": { "type": "string" } + } } - } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] } + }, + "allOf": [ { "$ref": "schema-relative-uri-defs2.json" } ] + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] + } + }, + "allOf": [ { "$ref": "schema-refs-absolute-uris-defs2.json" } ] }, "tests": [ { - "data": 1, - "description": "match", + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, "valid": true }, { - "data": "a", - "description": "mismatch", + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 ยง2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.2", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, "valid": false } ] - } + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "definitions": { + "bar": { + "$id": "#something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { "$ref": "/absref/foobar.json" } + ] + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + } ] diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 819d3267..c2b20024 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -54,7 +54,7 @@ "schema": { "$id": "http://localhost:1234/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", @@ -167,5 +167,73 @@ "valid": false } ] + }, + { + "description": "remote ref with ref to definitions", + "schema": { + "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", + "allOf": [ + { "$ref": "ref-and-definitions.json" } + ] + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$id": "http://localhost:1234/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] } ] diff --git a/tests/draft6/required.json b/tests/draft6/required.json index abf18f34..8d8087af 100644 --- a/tests/draft6/required.json +++ b/tests/draft6/required.json @@ -101,5 +101,51 @@ "valid": false } ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { "required": ["__proto__", "toString", "constructor"] }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft6/type.json b/tests/draft6/type.json index ea33b182..83046470 100644 --- a/tests/draft6/type.json +++ b/tests/draft6/type.json @@ -8,6 +8,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true + }, { "description": "a float is not an integer", "data": 1.1, @@ -54,6 +59,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, { "description": "a float is a number", "data": 1.1, diff --git a/tests/draft6/uniqueItems.json b/tests/draft6/uniqueItems.json index d312ad71..d2730c60 100644 --- a/tests/draft6/uniqueItems.json +++ b/tests/draft6/uniqueItems.json @@ -13,6 +13,11 @@ "data": [1, 1], "valid": false }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], @@ -28,6 +33,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -38,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ @@ -64,6 +84,11 @@ "data": [["foo"], ["foo"]], "valid": false }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, { "description": "1 and true are unique", "data": [1, true], @@ -74,22 +99,62 @@ "data": [0, false], "valid": true }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, { "description": "unique heterogeneous types are valid", - "data": [{}, [1], true, null, 1], + "data": [{}, [1], true, null, 1, "{}"], "valid": true }, { "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, { "description": "uniqueItems with an array of items", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], + "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true }, "tests": [ @@ -138,8 +203,8 @@ { "description": "uniqueItems with an array of items and additionalItems=false", "schema": { - "items": [{"type": "boolean"}, {"type": "boolean"}], - "uniqueItems": true, + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": true, "additionalItems": false }, "tests": [ @@ -169,5 +234,176 @@ "valid": false } ] + }, + { + "description": "uniqueItems=false validation", + "schema": { "uniqueItems": false }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] } ] diff --git a/tests/draft6/unknownKeyword.json b/tests/draft6/unknownKeyword.json new file mode 100644 index 00000000..1f58d97e --- /dev/null +++ b/tests/draft6/unknownKeyword.json @@ -0,0 +1,56 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "definitions": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { "$ref": "#/definitions/id_in_unknown0" }, + { "$ref": "#/definitions/id_in_unknown1" }, + { "$ref": "https://localhost:1234/unknownKeyword/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft7/additionalItems.json b/tests/draft7/additionalItems.json index abecc578..cae72361 100644 --- a/tests/draft7/additionalItems.json +++ b/tests/draft7/additionalItems.json @@ -19,7 +19,30 @@ ] }, { - "description": "items is schema, no additionalItems", + "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [1,2,3], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [1,"2","3"], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", "schema": { "items": {}, "additionalItems": false @@ -33,14 +56,24 @@ ] }, { - "description": "array of items with no additionalItems", + "description": "array of items with no additionalItems permitted", "schema": { "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { - "description": "fewer number of items present", + "description": "empty array", + "data": [ ], + "valid": true + }, + { + "description": "fewer number of items present (1)", + "data": [ 1 ], + "valid": true + }, + { + "description": "fewer number of items present (2)", "data": [ 1, 2 ], "valid": true }, @@ -83,5 +116,72 @@ "valid": true } ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" } ] } + ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, null ], + "valid": true + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { "items": [ { "type": "integer" }, { "type": "string" } ] } + ], + "items": [ {"type": "integer" } ], + "additionalItems": { "type": "boolean" } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ 1, "hello" ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ { "type": "string" } ], + "additionalItems": { "type": "integer" } + }, + "tests": [ + { + "description": "valid items", + "data": [ "x", 2, 3 ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ "x", "y" ], + "valid": false + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft7/additionalProperties.json b/tests/draft7/additionalProperties.json index ffeac6b3..0f8e1627 100644 --- a/tests/draft7/additionalProperties.json +++ b/tests/draft7/additionalProperties.json @@ -60,8 +60,7 @@ ] }, { - "description": - "additionalProperties allows a schema which should validate", + "description": "additionalProperties with schema", "schema": { "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} @@ -115,7 +114,7 @@ ] }, { - "description": "additionalProperties should not look in applicators", + "description": "additionalProperties does not look in applicators", "schema": { "allOf": [ {"properties": {"foo": {}}} @@ -124,10 +123,25 @@ }, "tests": [ { - "description": "properties defined in allOf are not allowed", + "description": "properties defined in allOf are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] } ] diff --git a/tests/draft7/allOf.json b/tests/draft7/allOf.json index eb612091..ec9319e1 100644 --- a/tests/draft7/allOf.json +++ b/tests/draft7/allOf.json @@ -214,5 +214,81 @@ "valid": false } ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ { "multipleOf": 2 } ], + "anyOf": [ { "multipleOf": 3 } ], + "oneOf": [ { "multipleOf": 5 } ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] } ] diff --git a/tests/draft7/const.json b/tests/draft7/const.json index c089625d..1c2cafcc 100644 --- a/tests/draft7/const.json +++ b/tests/draft7/const.json @@ -126,7 +126,91 @@ ] }, { - "description": "const with 0 does not match false", + "description": "const with [false] does not match [0]", + "schema": {"const": [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": "const with [true] does not match [1]", + "schema": {"const": [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": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": {"const": {"a": false}}, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": {"const": {"a": true}}, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, "tests": [ { @@ -143,6 +227,21 @@ "description": "float zero is valid", "data": 0.0, "valid": true + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false } ] }, @@ -166,5 +265,78 @@ "valid": true } ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": {"const": -2.0}, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": {"const": 9007199254740992}, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { "const": "hello\u0000there" }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft7/contains.json b/tests/draft7/contains.json index 67ecbd99..2b1a5152 100644 --- a/tests/draft7/contains.json +++ b/tests/draft7/contains.json @@ -96,5 +96,70 @@ "valid": true } ] + }, + { + "description": "items + contains", + "schema": { + "items": { "multipleOf": 2 }, + "contains": { "multipleOf": 3 } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ 2, 4, 8 ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ 3, 6, 9 ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ 6, 12 ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ 1, 5 ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "contains": { + "if": false, + "else": true + } + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": ["foo"], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft7/default.json b/tests/draft7/default.json index 17629779..289a9b66 100644 --- a/tests/draft7/default.json +++ b/tests/draft7/default.json @@ -45,5 +45,35 @@ "valid": true } ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { "alpha": 5 }, + "valid": false + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] } ] diff --git a/tests/draft7/definitions.json b/tests/draft7/definitions.json index 43604065..afe396e4 100644 --- a/tests/draft7/definitions.json +++ b/tests/draft7/definitions.json @@ -1,6 +1,6 @@ [ { - "description": "valid definition", + "description": "validate definition against metaschema", "schema": {"$ref": "http://json-schema.org/draft-07/schema#"}, "tests": [ { @@ -11,13 +11,7 @@ } }, "valid": true - } - ] - }, - { - "description": "invalid definition", - "schema": {"$ref": "http://json-schema.org/draft-07/schema#"}, - "tests": [ + }, { "description": "invalid definition schema", "data": { diff --git a/tests/draft7/dependencies.json b/tests/draft7/dependencies.json index 8dd78aa5..c0bd809f 100644 --- a/tests/draft7/dependencies.json +++ b/tests/draft7/dependencies.json @@ -57,6 +57,11 @@ "description": "object with one property", "data": {"bar": 2}, "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true } ] }, @@ -169,31 +174,6 @@ } ] }, - { - "description": "empty array of dependencies", - "schema": { - "dependencies": { - "foo": [] - } - }, - "tests": [ - { - "description": "object with property is valid", - "data": { "foo": 1 }, - "valid": true - }, - { - "description": "empty object is valid", - "data": {}, - "valid": true - }, - { - "description": "non-object is valid", - "data": 1, - "valid": true - } - ] - }, { "description": "dependencies with escaped characters", "schema": { @@ -264,5 +244,43 @@ "valid": false } ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": {"foo": 1}, + "valid": false + }, + { + "description": "matches dependency", + "data": {"bar": 1}, + "valid": true + }, + { + "description": "matches both", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "no dependency", + "data": {"baz": 1}, + "valid": true + } + ] } ] diff --git a/tests/draft7/enum.json b/tests/draft7/enum.json index 32d79026..f085097b 100644 --- a/tests/draft7/enum.json +++ b/tests/draft7/enum.json @@ -33,6 +33,37 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { "enum": [6, null] }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false } ] }, @@ -52,6 +83,16 @@ "data": {"foo":"foo", "bar":"bar"}, "valid": true }, + { + "description": "wrong foo value", + "data": {"foo":"foot", "bar":"bar"}, + "valid": false + }, + { + "description": "wrong bar value", + "data": {"foo":"foo", "bar":"bart"}, + "valid": false + }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, @@ -175,5 +216,21 @@ "valid": true } ] + }, + { + "description": "nul characters in strings", + "schema": { "enum": [ "hello\u0000there" ] }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] } ] diff --git a/tests/draft7/format.json b/tests/draft7/format.json index 93305f5c..e2447d60 100644 --- a/tests/draft7/format.json +++ b/tests/draft7/format.json @@ -1,611 +1,611 @@ [ { - "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "description": "email format", + "schema": { "format": "email" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IDN e-mail addresses", - "schema": {"format": "idn-email"}, + "description": "idn-email format", + "schema": { "format": "idn-email" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of regexes", - "schema": {"format": "regex"}, + "description": "regex format", + "schema": { "format": "regex" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "description": "ipv4 format", + "schema": { "format": "ipv4" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "description": "ipv6 format", + "schema": { "format": "ipv6" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IDN hostnames", - "schema": {"format": "idn-hostname"}, + "description": "idn-hostname format", + "schema": { "format": "idn-hostname" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of hostnames", - "schema": {"format": "hostname"}, + "description": "hostname format", + "schema": { "format": "hostname" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date strings", - "schema": {"format": "date"}, + "description": "date format", + "schema": { "format": "date" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "description": "date-time format", + "schema": { "format": "date-time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of time strings", - "schema": {"format": "time"}, + "description": "time format", + "schema": { "format": "time" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of JSON pointers", - "schema": {"format": "json-pointer"}, + "description": "json-pointer format", + "schema": { "format": "json-pointer" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of relative JSON pointers", - "schema": {"format": "relative-json-pointer"}, + "description": "relative-json-pointer format", + "schema": { "format": "relative-json-pointer" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IRIs", - "schema": {"format": "iri"}, + "description": "iri format", + "schema": { "format": "iri" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of IRI references", - "schema": {"format": "iri-reference"}, + "description": "iri-reference format", + "schema": { "format": "iri-reference" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URIs", - "schema": {"format": "uri"}, + "description": "uri format", + "schema": { "format": "uri" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI references", - "schema": {"format": "uri-reference"}, + "description": "uri-reference format", + "schema": { "format": "uri-reference" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { - "description": "validation of URI templates", - "schema": {"format": "uri-template"}, + "description": "uri-template format", + "schema": { "format": "uri-template" }, "tests": [ { - "description": "ignores integers", + "description": "all string formats ignore integers", "data": 12, "valid": true }, { - "description": "ignores floats", + "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { - "description": "ignores objects", + "description": "all string formats ignore objects", "data": {}, "valid": true }, { - "description": "ignores arrays", + "description": "all string formats ignore arrays", "data": [], "valid": true }, { - "description": "ignores booleans", + "description": "all string formats ignore booleans", "data": false, "valid": true }, { - "description": "ignores null", + "description": "all string formats ignore nulls", "data": null, "valid": true } diff --git a/tests/draft7/id.json b/tests/draft7/id.json new file mode 100644 index 00000000..6be81b8d --- /dev/null +++ b/tests/draft7/id.json @@ -0,0 +1,114 @@ +[ + { + "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": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { "$ref": "#/definitions/id_in_enum" }, + { "$ref": "https://localhost:1234/id/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + }, + "valid": true + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "definitions": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else" : { + "$ref": "#/definitions/const_not_anchor" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "definitions": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else" : { + "$ref": "#/definitions/const_not_id" + } + }, + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/draft7/if-then-else.json b/tests/draft7/if-then-else.json index be732816..284e9191 100644 --- a/tests/draft7/if-then-else.json +++ b/tests/draft7/if-then-else.json @@ -184,5 +184,75 @@ "valid": true } ] + }, + { + "description": "if with boolean schema true", + "schema": { + "if": true, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "if": false, + "then": { "const": "then" }, + "else": { "const": "else" } + }, + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] } ] diff --git a/tests/draft7/infinite-loop-detection.json b/tests/draft7/infinite-loop-detection.json new file mode 100644 index 00000000..f98c74fc --- /dev/null +++ b/tests/draft7/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft7/items.json b/tests/draft7/items.json index 67f11840..7ed6781b 100644 --- a/tests/draft7/items.json +++ b/tests/draft7/items.json @@ -246,5 +246,37 @@ "valid": false } ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ null ], + "valid": true + } + ] } ] diff --git a/tests/draft7/maxItems.json b/tests/draft7/maxItems.json index 3b53a6b3..f0c36ab2 100644 --- a/tests/draft7/maxItems.json +++ b/tests/draft7/maxItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "maxItems validation with a decimal", + "schema": {"maxItems": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + } + ] } ] diff --git a/tests/draft7/maxLength.json b/tests/draft7/maxLength.json index 811d35b2..748b4daa 100644 --- a/tests/draft7/maxLength.json +++ b/tests/draft7/maxLength.json @@ -29,5 +29,21 @@ "valid": true } ] + }, + { + "description": "maxLength validation with a decimal", + "schema": {"maxLength": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] } ] diff --git a/tests/draft7/maxProperties.json b/tests/draft7/maxProperties.json index 513731e4..acec1420 100644 --- a/tests/draft7/maxProperties.json +++ b/tests/draft7/maxProperties.json @@ -34,5 +34,37 @@ "valid": true } ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": {"maxProperties": 2.0}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { "maxProperties": 0 }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { "foo": 1 }, + "valid": false + } + ] } ] diff --git a/tests/draft7/maximum.json b/tests/draft7/maximum.json index 8150984e..6844a39e 100644 --- a/tests/draft7/maximum.json +++ b/tests/draft7/maximum.json @@ -24,5 +24,31 @@ "valid": true } ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": {"maximum": 300}, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] } ] diff --git a/tests/draft7/minItems.json b/tests/draft7/minItems.json index ed511881..d3b18720 100644 --- a/tests/draft7/minItems.json +++ b/tests/draft7/minItems.json @@ -24,5 +24,21 @@ "valid": true } ] + }, + { + "description": "minItems validation with a decimal", + "schema": {"minItems": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + } + ] } ] diff --git a/tests/draft7/minLength.json b/tests/draft7/minLength.json index 3f09158d..64db9480 100644 --- a/tests/draft7/minLength.json +++ b/tests/draft7/minLength.json @@ -29,5 +29,21 @@ "valid": false } ] + }, + { + "description": "minLength validation with a decimal", + "schema": {"minLength": 2.0}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] } ] diff --git a/tests/draft7/minProperties.json b/tests/draft7/minProperties.json index 49a0726e..9f74f789 100644 --- a/tests/draft7/minProperties.json +++ b/tests/draft7/minProperties.json @@ -34,5 +34,21 @@ "valid": true } ] + }, + { + "description": "minProperties validation with a decimal", + "schema": {"minProperties": 1.0}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft7/minimum.json b/tests/draft7/minimum.json index 2a9c42b3..21ae50e0 100644 --- a/tests/draft7/minimum.json +++ b/tests/draft7/minimum.json @@ -45,7 +45,17 @@ "valid": true }, { - "description": "below the minimum is invalid", + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", "data": -3, "valid": false }, diff --git a/tests/draft7/multipleOf.json b/tests/draft7/multipleOf.json index ca3b7618..e606979b 100644 --- a/tests/draft7/multipleOf.json +++ b/tests/draft7/multipleOf.json @@ -56,5 +56,27 @@ "valid": false } ] + }, + { + "description": "float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": {"type": "integer", "multipleOf": 1e-8}, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] } ] diff --git a/tests/draft7/oneOf.json b/tests/draft7/oneOf.json index 57640b7a..eeb7ae86 100644 --- a/tests/draft7/oneOf.json +++ b/tests/draft7/oneOf.json @@ -202,5 +202,73 @@ "valid": false } ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": ["bar"] + }, + { + "properties": { + "foo": true + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": {"bar": 8}, + "valid": true + }, + { + "description": "second oneOf valid", + "data": {"foo": "foo"}, + "valid": true + }, + { + "description": "both oneOf valid", + "data": {"foo": "foo", "bar": 8}, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": {"baz": "quux"}, + "valid": false + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] } ] diff --git a/tests/draft7/optional/bignum.json b/tests/draft7/optional/bignum.json index fac275e2..94b4a4e6 100644 --- a/tests/draft7/optional/bignum.json +++ b/tests/draft7/optional/bignum.json @@ -1,30 +1,13 @@ [ { "description": "integer", - "schema": {"type": "integer"}, + "schema": { "type": "integer" }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true - } - ] - }, - { - "description": "number", - "schema": {"type": "number"}, - "tests": [ - { - "description": "a bignum is a number", - "data": 98249283749234923498293171823948729348710298301928331, - "valid": true - } - ] - }, - { - "description": "integer", - "schema": {"type": "integer"}, - "tests": [ + }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, @@ -34,8 +17,13 @@ }, { "description": "number", - "schema": {"type": "number"}, + "schema": { "type": "number" }, "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, @@ -45,7 +33,7 @@ }, { "description": "string", - "schema": {"type": "string"}, + "schema": { "type": "string" }, "tests": [ { "description": "a bignum is not a string", @@ -55,8 +43,8 @@ ] }, { - "description": "integer comparison", - "schema": {"maximum": 18446744073709551615}, + "description": "maximum integer comparison", + "schema": { "maximum": 18446744073709551615 }, "tests": [ { "description": "comparison works for high numbers", @@ -79,8 +67,8 @@ ] }, { - "description": "integer comparison", - "schema": {"minimum": -18446744073709551615}, + "description": "minimum integer comparison", + "schema": { "minimum": -18446744073709551615 }, "tests": [ { "description": "comparison works for very negative numbers", diff --git a/tests/draft7/optional/cross-draft.json b/tests/draft7/optional/cross-draft.json new file mode 100644 index 00000000..8ff53736 --- /dev/null +++ b/tests/draft7/optional/cross-draft.json @@ -0,0 +1,25 @@ +[ + { + "description": "refs to future drafts are processed as future drafts", + "schema": { + "type": "object", + "allOf": [ + { "properties": { "foo": true } }, + { "$ref": "http://localhost:1234/draft2019-09/dependentRequired.json" } + ] + }, + "tests": [ + { + "description": "missing bar is invalid", + "comment": "if the implementation is not processing the $ref as a 2019-09 schema, this test will fail", + "data": {"foo": "any value"}, + "valid": false + }, + { + "description": "present bar is valid", + "data": {"foo": "any value", "bar": "also any value"}, + "valid": true + } + ] + } +] diff --git a/tests/draft7/optional/ecmascript-regex.json b/tests/draft7/optional/ecmascript-regex.json index d82e0feb..c4886aaa 100644 --- a/tests/draft7/optional/ecmascript-regex.json +++ b/tests/draft7/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { @@ -18,32 +7,32 @@ }, "tests": [ { - "description": "matches in Python, but should not in jsonschema", - "data": "abc\n", + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", "valid": false }, { - "description": "should match", + "description": "matches", "data": "abc", "valid": true } ] }, { - "description": "ECMA 262 regex converts \\a to ascii BEL", + "description": "ECMA 262 regex converts \\t to horizontal tab", "schema": { "type": "string", - "pattern": "^\\a$" + "pattern": "^\\t$" }, "tests": [ { "description": "does not match", - "data": "\\a", + "data": "\\t", "valid": false }, { "description": "matches", - "data": "\u0007", + "data": "\u0009", "valid": true } ] @@ -154,7 +143,7 @@ ] }, { - "description": "ECMA 262 \\w matches everything but ascii letters", + "description": "ECMA 262 \\W matches everything but ascii letters", "schema": { "type": "string", "pattern": "^\\W$" @@ -173,7 +162,7 @@ ] }, { - "description": "ECMA 262 \\s matches ascii whitespace only", + "description": "ECMA 262 \\s matches whitespace", "schema": { "type": "string", "pattern": "^\\s$" @@ -185,14 +174,59 @@ "valid": true }, { - "description": "latin-1 non-breaking-space does not match (unlike e.g. Python)", + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true + }, + { + "description": "Form feed matches", + "data": "\u000c", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", "data": "\u00a0", + "valid": true + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true + }, + { + "description": "line feed matches (line terminator)", + "data": "\u000a", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": "\u2003", + "valid": true + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "\u2013", "valid": false } ] }, { - "description": "ECMA 262 \\S matches everything but ascii whitespace", + "description": "ECMA 262 \\S matches everything but whitespace", "schema": { "type": "string", "pattern": "^\\S$" @@ -204,8 +238,313 @@ "valid": false }, { - "description": "latin-1 non-breaking-space matches (unlike e.g. Python)", + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false + }, + { + "description": "Form feed does not match", + "data": "\u000c", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", "data": "\u00a0", + "valid": false + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false + }, + { + "description": "line feed does not match (line terminator)", + "data": "\u000a", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": "\u2003", + "valid": false + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "\u2013", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { "pattern": "\\p{Letter}cole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { "pattern": "\\wcole" }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ร‰TAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ร‰COLE, L'ร‰GLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ร‰TAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { "pattern": "[a-z]cole" }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'รฉcole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance รฉtaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'รฉglise et la patinoire; mais la vraie vie รฉtait sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { "pattern": "^\\d+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { "pattern": "^\\p{digit}+$" }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "เงชเงจ", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": { "L'ร‰COLE": "PAS DE VRAIE VIE" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { "l'รฉcole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": { "l'\u00e9cole": "pas de vraie vie" }, + "valid": false + }, + { + "description": "ascii characters match", + "data": { "l'ecole": "pas de vraie vie" }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, + "valid": false + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { "42": "life, the universe, and everything" }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { "-%#": "spending the year dead for tax reasons" }, + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { "เงชเงจ": "khajit has wares if you have coin" }, "valid": true } ] diff --git a/tests/draft7/optional/float-overflow.json b/tests/draft7/optional/float-overflow.json new file mode 100644 index 00000000..52ff9827 --- /dev/null +++ b/tests/draft7/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft7/optional/format/date-time.json b/tests/draft7/optional/format/date-time.json index dfccee6e..09112737 100644 --- a/tests/draft7/optional/format/date-time.json +++ b/tests/draft7/optional/format/date-time.json @@ -1,8 +1,38 @@ [ { "description": "validation of date-time strings", - "schema": {"format": "date-time"}, + "schema": { "format": "date-time" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid date-time string", "data": "1963-06-19T08:30:06.283185Z", @@ -24,13 +54,43 @@ "valid": true }, { - "description": "a invalid day in date-time string", - "data": "1990-02-31T15:59:60.123-08:00", + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", "valid": false }, { "description": "an invalid offset in date-time string", - "data": "1990-12-31T15:59:60-24:00", + "data": "1990-12-31T15:59:59-24:00", + "valid": false + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", "valid": false }, { @@ -47,6 +107,26 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in date portion", + "data": "1963-06-1เงชT00:00:00Z", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in time portion", + "data": "1963-06-11T0เงช:00:00Z", + "valid": false } ] } diff --git a/tests/draft7/optional/format/date.json b/tests/draft7/optional/format/date.json index cd23baae..d723124a 100644 --- a/tests/draft7/optional/format/date.json +++ b/tests/draft7/optional/format/date.json @@ -1,15 +1,180 @@ [ { "description": "validation of date strings", - "schema": {"format": "date"}, + "schema": { "format": "date" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid date string", "data": "1963-06-19", "valid": true }, { - "description": "an invalid date-time string", + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false + }, + { + "description": "an invalid date string", "data": "06/19/1963", "valid": false }, @@ -17,6 +182,61 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350", "valid": false + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1963-06-1เงช", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false } ] } diff --git a/tests/draft7/optional/format/email.json b/tests/draft7/optional/format/email.json index c837c84b..d6761a46 100644 --- a/tests/draft7/optional/format/email.json +++ b/tests/draft7/optional/format/email.json @@ -1,8 +1,38 @@ [ { "description": "validation of e-mail addresses", - "schema": {"format": "email"}, + "schema": { "format": "email" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid e-mail address", "data": "joe.bloggs@example.com", @@ -12,6 +42,41 @@ "description": "an invalid e-mail address", "data": "2962", "valid": false + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false } ] } diff --git a/tests/draft7/optional/format/hostname.json b/tests/draft7/optional/format/hostname.json index d22e57db..8a67fda8 100644 --- a/tests/draft7/optional/format/hostname.json +++ b/tests/draft7/optional/format/hostname.json @@ -1,8 +1,38 @@ [ { "description": "validation of host names", - "schema": {"format": "hostname"}, + "schema": { "format": "hostname" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid host name", "data": "www.example.com", @@ -27,6 +57,41 @@ "description": "a host name with a component too long", "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", "valid": false + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false } ] } diff --git a/tests/draft7/optional/format/idn-email.json b/tests/draft7/optional/format/idn-email.json index 637409ea..6e213745 100644 --- a/tests/draft7/optional/format/idn-email.json +++ b/tests/draft7/optional/format/idn-email.json @@ -1,8 +1,38 @@ [ { "description": "validation of an internationalized e-mail addresses", - "schema": {"format": "idn-email"}, + "schema": { "format": "idn-email" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid idn e-mail (example@example.test in Hangul)", "data": "์‹ค๋ก€@์‹ค๋ก€.ํ…Œ์ŠคํŠธ", @@ -12,6 +42,16 @@ "description": "an invalid idn e-mail address", "data": "2962", "valid": false + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false } ] } diff --git a/tests/draft7/optional/format/idn-hostname.json b/tests/draft7/optional/format/idn-hostname.json index 3291820e..6c8f86a3 100644 --- a/tests/draft7/optional/format/idn-hostname.json +++ b/tests/draft7/optional/format/idn-hostname.json @@ -1,8 +1,38 @@ [ { "description": "validation of internationalized host names", - "schema": {"format": "idn-hostname"}, + "schema": { "format": "idn-hostname" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid host name (example.test in Hangul)", "data": "์‹ค๋ก€.ํ…Œ์ŠคํŠธ", @@ -22,6 +52,252 @@ "description": "a host name with a component too long", "data": "์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค์‹ค๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€๋ก€ํ…Œ์ŠคํŠธ๋ก€๋ก€์‹ค๋ก€.ํ…Œ์ŠคํŠธ", "valid": false + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-> $1.00 <--", + "valid": false + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0903hello", + "valid": false + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0300hello", + "valid": false + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "\u0488hello", + "valid": false + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u00df\u03c2\u0f0b\u3007", + "valid": true + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u06fd\u06fe", + "valid": true + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "\u0640\u07fa", + "valid": false + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b", + "valid": false + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "\u00b7l", + "valid": false + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7a", + "valid": false + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7", + "valid": false + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l\u00b7l", + "valid": true + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375S", + "valid": false + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375", + "valid": false + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "\u03b1\u0375\u03b2", + "valid": true + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05f3\u05d1", + "valid": false + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "\u05d0\u05f3\u05d1", + "valid": true + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05f4\u05d1", + "valid": false + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "\u05d0\u05f4\u05d1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def\u30fbabc", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb", + "valid": false + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u3041", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u30a1", + "valid": true + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "\u30fb\u4e08", + "valid": true + }, + { + "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", + "valid": false + }, + { + "description": "Arabic-Indic digits not 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\u0628", + "valid": true + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "\u06f00", + "valid": true + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u200d\u0937", + "valid": false + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "\u0915\u094d\u200d\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "\u0915\u094d\u200c\u0937", + "valid": true + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "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 } ] } diff --git a/tests/draft7/optional/format/ipv4.json b/tests/draft7/optional/format/ipv4.json index 661148a7..4706581f 100644 --- a/tests/draft7/optional/format/ipv4.json +++ b/tests/draft7/optional/format/ipv4.json @@ -1,8 +1,38 @@ [ { "description": "validation of IP addresses", - "schema": {"format": "ipv4"}, + "schema": { "format": "ipv4" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IP address", "data": "192.168.0.1", @@ -27,6 +57,27 @@ "description": "an IP address as an integer", "data": "0x7f000001", "valid": false + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ7.0.0.1", + "valid": false } ] } diff --git a/tests/draft7/optional/format/ipv6.json b/tests/draft7/optional/format/ipv6.json index f67559b3..94368f2a 100644 --- a/tests/draft7/optional/format/ipv6.json +++ b/tests/draft7/optional/format/ipv6.json @@ -1,8 +1,38 @@ [ { "description": "validation of IPv6 addresses", - "schema": {"format": "ipv6"}, + "schema": { "format": "ipv6" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IPv6 address", "data": "::1", @@ -13,6 +43,16 @@ "data": "12345::", "valid": false }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false + }, { "description": "an IPv6 address with too many components", "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", @@ -22,6 +62,146 @@ "description": "an IPv6 address containing illegal characters", "data": "::laptop", "valid": false + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:เงช", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงช' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16เงช.0.1", + "valid": false } ] } diff --git a/tests/draft7/optional/format/iri-reference.json b/tests/draft7/optional/format/iri-reference.json index 1fd779c2..c6b4c22a 100644 --- a/tests/draft7/optional/format/iri-reference.json +++ b/tests/draft7/optional/format/iri-reference.json @@ -1,8 +1,38 @@ [ { "description": "validation of IRI References", - "schema": {"format": "iri-reference"}, + "schema": { "format": "iri-reference" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IRI", "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", diff --git a/tests/draft7/optional/format/iri.json b/tests/draft7/optional/format/iri.json index ed54094c..a0d12aed 100644 --- a/tests/draft7/optional/format/iri.json +++ b/tests/draft7/optional/format/iri.json @@ -1,15 +1,45 @@ [ { "description": "validation of IRIs", - "schema": {"format": "iri"}, + "schema": { "format": "iri" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid IRI with anchor tag", "data": "http://ฦ’รธรธ.รŸรฅr/?โˆ‚รฉล“=ฯ€รฎx#ฯ€รฎรผx", "valid": true }, { - "description": "a valid IRI with anchor tag and parantheses", + "description": "a valid IRI with anchor tag and parentheses", "data": "http://ฦ’รธรธ.com/blah_(wรฎkรฏpรฉdiรฅ)_blah#รŸitรฉ-1", "valid": true }, diff --git a/tests/draft7/optional/format/json-pointer.json b/tests/draft7/optional/format/json-pointer.json index 65c2f064..a0346b57 100644 --- a/tests/draft7/optional/format/json-pointer.json +++ b/tests/draft7/optional/format/json-pointer.json @@ -1,8 +1,38 @@ [ { "description": "validation of JSON-pointers (JSON String Representation)", - "schema": {"format": "json-pointer"}, + "schema": { "format": "json-pointer" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid JSON-pointer", "data": "/foo/bar~0/baz~1/%a", diff --git a/tests/draft7/optional/format/regex.json b/tests/draft7/optional/format/regex.json index d99d021e..34491770 100644 --- a/tests/draft7/optional/format/regex.json +++ b/tests/draft7/optional/format/regex.json @@ -1,8 +1,38 @@ [ { "description": "validation of regular expressions", - "schema": {"format": "regex"}, + "schema": { "format": "regex" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid regular expression", "data": "([abc])+\\s+$", diff --git a/tests/draft7/optional/format/relative-json-pointer.json b/tests/draft7/optional/format/relative-json-pointer.json index ceeb743a..e50e505f 100644 --- a/tests/draft7/optional/format/relative-json-pointer.json +++ b/tests/draft7/optional/format/relative-json-pointer.json @@ -1,15 +1,45 @@ [ { "description": "validation of Relative JSON Pointers (RJP)", - "schema": {"format": "relative-json-pointer"}, + "schema": { "format": "relative-json-pointer" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid upwards RJP", "data": "1", "valid": true }, { - "description": "a valid downwards RJP", + "description": "a valid downwards RJP", "data": "0/foo/bar", "valid": true }, @@ -27,6 +57,41 @@ "description": "an invalid RJP that is a valid JSON Pointer", "data": "/foo/bar", "valid": false + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false + }, + { + "description": "empty string", + "data": "", + "valid": false + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true } ] } diff --git a/tests/draft7/optional/format/time.json b/tests/draft7/optional/format/time.json index 4ec8a01a..014ecd8d 100644 --- a/tests/draft7/optional/format/time.json +++ b/tests/draft7/optional/format/time.json @@ -1,15 +1,200 @@ [ { "description": "validation of time strings", - "schema": {"format": "time"}, + "schema": { "format": "time" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid time string", + "data": "08:30:06Z", + "valid": true + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true + }, + { + "description": "a valid time string with precise second fraction", "data": "08:30:06.283185Z", "valid": true }, { - "description": "an invalid time string", + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false + }, + { + "description": "an invalid offset indicator", "data": "08:30:06 PST", "valid": false }, @@ -17,6 +202,31 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "01:01:01,1111", "valid": false + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false + }, + { + "description": "invalid non-ASCII 'เงจ' (a Bengali 2)", + "data": "1เงจ:00:00Z", + "valid": false + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false } ] } diff --git a/tests/draft7/optional/format/unknown.json b/tests/draft7/optional/format/unknown.json new file mode 100644 index 00000000..12339ae5 --- /dev/null +++ b/tests/draft7/optional/format/unknown.json @@ -0,0 +1,43 @@ +[ + { + "description": "unknown format", + "schema": { "format": "unknown" }, + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true + } + ] + } +] diff --git a/tests/draft7/optional/format/uri-reference.json b/tests/draft7/optional/format/uri-reference.json index e4c9eef6..7cdf228d 100644 --- a/tests/draft7/optional/format/uri-reference.json +++ b/tests/draft7/optional/format/uri-reference.json @@ -1,8 +1,38 @@ [ { "description": "validation of URI References", - "schema": {"format": "uri-reference"}, + "schema": { "format": "uri-reference" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid URI", "data": "http://foo.bar/?baz=qux#quux", diff --git a/tests/draft7/optional/format/uri-template.json b/tests/draft7/optional/format/uri-template.json index 33ab76ee..df355c55 100644 --- a/tests/draft7/optional/format/uri-template.json +++ b/tests/draft7/optional/format/uri-template.json @@ -1,8 +1,38 @@ [ { "description": "format: uri-template", - "schema": {"format": "uri-template"}, + "schema": { "format": "uri-template" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid uri-template", "data": "http://example.com/dictionary/{term:1}/{term}", diff --git a/tests/draft7/optional/format/uri.json b/tests/draft7/optional/format/uri.json index 25cc40c8..4b48d406 100644 --- a/tests/draft7/optional/format/uri.json +++ b/tests/draft7/optional/format/uri.json @@ -1,15 +1,45 @@ [ { "description": "validation of URIs", - "schema": {"format": "uri"}, + "schema": { "format": "uri" }, "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true + }, { "description": "a valid URL with anchor tag", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { - "description": "a valid URL with anchor tag and parantheses", + "description": "a valid URL with anchor tag and parentheses", "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", "valid": true }, @@ -97,6 +127,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft7/optional/non-bmp-regex.json b/tests/draft7/optional/non-bmp-regex.json new file mode 100644 index 00000000..dd67af2b --- /dev/null +++ b/tests/draft7/optional/non-bmp-regex.json @@ -0,0 +1,82 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { "pattern": "^๐Ÿฒ*$" }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "๐Ÿฒ", + "valid": true + }, + { + "description": "matches two", + "data": "๐Ÿฒ๐Ÿฒ", + "valid": true + }, + { + "description": "doesn't match one", + "data": "๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match two", + "data": "๐Ÿ‰๐Ÿ‰", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^๐Ÿฒ*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { "": 1 }, + "valid": true + }, + { + "description": "matches single", + "data": { "๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "matches two", + "data": { "๐Ÿฒ๐Ÿฒ": 1 }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { "๐Ÿฒ": "hello" }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { "๐Ÿฒ๐Ÿฒ": "hello" }, + "valid": false + } + ] + } +] diff --git a/tests/draft7/optional/zeroTerminatedFloats.json b/tests/draft7/optional/zeroTerminatedFloats.json deleted file mode 100644 index 1bcdf960..00000000 --- a/tests/draft7/optional/zeroTerminatedFloats.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "description": "some languages do not distinguish between different types of numeric value", - "schema": { - "type": "integer" - }, - "tests": [ - { - "description": "a float without fractional part is an integer", - "data": 1.0, - "valid": true - } - ] - } -] diff --git a/tests/draft7/pattern.json b/tests/draft7/pattern.json index 25e72997..92db0f97 100644 --- a/tests/draft7/pattern.json +++ b/tests/draft7/pattern.json @@ -14,9 +14,34 @@ "valid": false }, { - "description": "ignores non-strings", + "description": "ignores booleans", "data": true, "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true } ] }, diff --git a/tests/draft7/patternProperties.json b/tests/draft7/patternProperties.json index 1d04a167..c276e647 100644 --- a/tests/draft7/patternProperties.json +++ b/tests/draft7/patternProperties.json @@ -141,11 +141,31 @@ "data": {"foo": 1, "bar": 2}, "valid": false }, + { + "description": "object with a property matching both true and false is invalid", + "data": {"foobar":1}, + "valid": false + }, { "description": "empty object is valid", "data": {}, "valid": true } ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foobar": null}, + "valid": true + } + ] } ] diff --git a/tests/draft7/properties.json b/tests/draft7/properties.json index b86c1819..5b971ca0 100644 --- a/tests/draft7/properties.json +++ b/tests/draft7/properties.json @@ -163,5 +163,74 @@ "valid": false } ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": {"type": "null"} + } + }, + "tests": [ + { + "description": "allows null values", + "data": {"foo": null}, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": {"type": "number"}, + "toString": { + "properties": { "length": { "type": "string" } } + }, + "constructor": {"type": "number"} + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString not valid", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft7/propertyNames.json b/tests/draft7/propertyNames.json index 8423690d..f0788e64 100644 --- a/tests/draft7/propertyNames.json +++ b/tests/draft7/propertyNames.json @@ -43,6 +43,35 @@ } ] }, + { + "description": "propertyNames validation with pattern", + "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": {"propertyNames": true}, diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 44b8ed22..82631726 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilda~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilda": {"$ref": "#/tilda~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ @@ -91,8 +93,8 @@ "valid": false }, { - "description": "tilda invalid", - "data": {"tilda": "aoeu"}, + "description": "tilde invalid", + "data": {"tilde": "aoeu"}, "valid": false }, { @@ -106,8 +108,8 @@ "valid": true }, { - "description": "tilda valid", - "data": {"tilda": 123}, + "description": "tilde valid", + "data": {"tilde": 123}, "valid": true }, { @@ -125,7 +127,7 @@ "b": {"$ref": "#/definitions/a"}, "c": {"$ref": "#/definitions/b"} }, - "$ref": "#/definitions/c" + "allOf": [{ "$ref": "#/definitions/c" }] }, "tests": [ { @@ -173,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-07/schema#"}, @@ -209,10 +247,35 @@ } ] }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": {"$ref": "#/definitions/is-string"} + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": {"$ref": "a"}, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": {"$ref": 2}, + "valid": false + } + ] + }, { "description": "$ref to boolean schema true", "schema": { - "$ref": "#/definitions/bool", + "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": true } @@ -228,7 +291,7 @@ { "description": "$ref to boolean schema false", "schema": { - "$ref": "#/definitions/bool", + "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": false } @@ -383,15 +446,21 @@ ] }, { - "description": "Location-independent identifier with absolute URI", + "description": "Location-independent identifier with base URI change in subschema", "schema": { + "$id": "http://localhost:1234/root", "allOf": [{ - "$ref": "http://localhost:1234/bar#foo" + "$ref": "http://localhost:1234/nested.json#foo" }], "definitions": { "A": { - "$id": "http://localhost:1234/bar#foo", - "type": "integer" + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } } } }, @@ -409,33 +478,537 @@ ] }, { - "description": "Location-independent identifier with base URI change in subschema", + "description": "naive replacement of $ref with its destination is not correct", "schema": { - "$id": "http://localhost:1234/root", - "allOf": [{ - "$ref": "http://localhost:1234/nested.json#foo" - }], "definitions": { - "A": { - "$id": "nested.json", + "a_string": { "type": "string" } + }, + "enum": [ + { "$ref": "#/definitions/a_string" } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { "type": "string" }, + "valid": false + }, + { + "description": "match the enum exactly", + "data": { "$ref": "#/definitions/a_string" }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", "definitions": { - "B": { - "$id": "#foo", - "type": "integer" + "inner": { + "properties": { + "bar": { "type": "string" } + } } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] + } + }, + "allOf": [ { "$ref": "schema-relative-uri-defs2.json" } ] + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { "type": "string" } + } + } + }, + "allOf": [ { "$ref": "#/definitions/inner" } ] + } + }, + "allOf": [ { "$ref": "schema-refs-absolute-uris-defs2.json" } ] + }, + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$id": "http://example.com/a.json", + "definitions": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "definitions": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"} + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": {"foo": 37}, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 ยง2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 ยง2.3.2", + "$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": {"$ref": "#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/definitions/bar"} + }, + "definitions": { + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"} + }, + "definitions": { + "bar": { + "$id": "#something", + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": {"foo": "bar"}, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": {"foo": 12}, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/if"}, + { + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" } } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true } + ] + }, + { + "description": "ref to then", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/then"}, + { + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref to else", + "schema": { + "allOf": [ + {"$ref": "http://example.com/ref/else"}, + { + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + } + ] + }, + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { "$ref": "/absref/foobar.json" } + ] + }, + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] }, "tests": [ { + "description": "number is valid", "data": 1, - "description": "match", "valid": true }, { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { "type": "number" } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", "data": "a", - "description": "mismatch", "valid": false } ] diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index 819d3267..c2b20024 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -54,7 +54,7 @@ "schema": { "$id": "http://localhost:1234/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", @@ -167,5 +167,73 @@ "valid": false } ] + }, + { + "description": "remote ref with ref to definitions", + "schema": { + "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", + "allOf": [ + { "$ref": "ref-and-definitions.json" } + ] + }, + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + }, + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$id": "http://localhost:1234/some-id", + "properties": { + "name": {"$ref": "nested/foo-ref-string.json"} + } + }, + "tests": [ + { + "description": "number is invalid", + "data": { + "name": {"foo": 1} + }, + "valid": false + }, + { + "description": "string is valid", + "data": { + "name": {"foo": "a"} + }, + "valid": true + } + ] } ] diff --git a/tests/draft7/required.json b/tests/draft7/required.json index abf18f34..8d8087af 100644 --- a/tests/draft7/required.json +++ b/tests/draft7/required.json @@ -101,5 +101,51 @@ "valid": false } ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { "required": ["__proto__", "toString", "constructor"] }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false + }, + { + "description": "__proto__ present", + "data": { "__proto__": "foo" }, + "valid": false + }, + { + "description": "toString present", + "data": { "toString": { "length": 37 } }, + "valid": false + }, + { + "description": "constructor present", + "data": { "constructor": { "length": 37 } }, + "valid": false + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { "length": "foo" }, + "constructor": 37 + }, + "valid": true + } + ] } ] diff --git a/tests/draft7/type.json b/tests/draft7/type.json index ea33b182..83046470 100644 --- a/tests/draft7/type.json +++ b/tests/draft7/type.json @@ -8,6 +8,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true + }, { "description": "a float is not an integer", "data": 1.1, @@ -54,6 +59,11 @@ "data": 1, "valid": true }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, { "description": "a float is a number", "data": 1.1, diff --git a/tests/draft7/uniqueItems.json b/tests/draft7/uniqueItems.json index d0a94d8c..d2730c60 100644 --- a/tests/draft7/uniqueItems.json +++ b/tests/draft7/uniqueItems.json @@ -13,6 +13,11 @@ "data": [1, 1], "valid": false }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [1, 2, 1], + "valid": false + }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], @@ -28,6 +33,16 @@ "data": [1, true], "valid": true }, + { + "description": "unique array of strings is valid", + "data": ["foo", "bar", "baz"], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": ["foo", "bar", "foo"], + "valid": false + }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], @@ -38,6 +53,11 @@ "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, + { + "description": "property order of array of objects is ignored", + "data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], + "valid": false + }, { "description": "unique array of nested objects is valid", "data": [ @@ -64,6 +84,11 @@ "data": [["foo"], ["foo"]], "valid": false }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [["foo"], ["bar"], ["foo"]], + "valid": false + }, { "description": "1 and true are unique", "data": [1, true], @@ -74,15 +99,55 @@ "data": [0, false], "valid": true }, + { + "description": "[1] and [true] are unique", + "data": [[1], [true]], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [[0], [false]], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [[[1], "foo"], [[true], "foo"]], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [[[0], "foo"], [[false], "foo"]], + "valid": true + }, { "description": "unique heterogeneous types are valid", - "data": [{}, [1], true, null, 1], + "data": [{}, [1], true, null, 1, "{}"], "valid": true }, { "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "different objects are unique", + "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], + "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, @@ -169,5 +234,176 @@ "valid": false } ] + }, + { + "description": "uniqueItems=false validation", + "schema": { "uniqueItems": false }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [1, 1], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [0, false], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [1, true], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [["foo"], ["foo"]], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [{}, [1], true, null, {}, 1], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [false, true, "foo", "bar"], + "valid": true + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [true, false, "foo", "bar"], + "valid": true + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [false, true, "foo", "foo"], + "valid": true + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [true, false, "foo", "foo"], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [{"type": "boolean"}, {"type": "boolean"}], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [false, true], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [true, false], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [false, false], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [true, true], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [false, true, null], + "valid": false + } + ] } ] diff --git a/tests/draft7/unknownKeyword.json b/tests/draft7/unknownKeyword.json new file mode 100644 index 00000000..1f58d97e --- /dev/null +++ b/tests/draft7/unknownKeyword.json @@ -0,0 +1,56 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "definitions": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { "$ref": "#/definitions/id_in_unknown0" }, + { "$ref": "#/definitions/id_in_unknown1" }, + { "$ref": "https://localhost:1234/unknownKeyword/my_identifier.json" } + ] + }, + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false + } + ] + } +] diff --git a/tests/latest b/tests/latest index 90f70dba..9a4784dd 120000 --- a/tests/latest +++ b/tests/latest @@ -1 +1 @@ -draft2019-09 \ No newline at end of file +draft2020-12 \ No newline at end of file diff --git a/tox.ini b/tox.ini index 9c4e9499..dcc0dce6 100644 --- a/tox.ini +++ b/tox.ini @@ -5,5 +5,5 @@ skipsdist = True [testenv:sanity] # used just for validating the structure of the test case files themselves -deps = jsonschema +deps = jsonschema==4.18.0a4 commands = {envpython} bin/jsonschema_suite check