Skip to content

Commit

Permalink
Squashed 'json/' changes from 0788c226a..6afa9b38d
Browse files Browse the repository at this point in the history
6afa9b38d Merge pull request #664 from santhosh-tekuri/empty-tokens
e4bceb1ad Bump the python-jsonschema version used for the sanity check.
8025fc0d5 Merge pull request #128 from iainbeeston/foundations-of-json-schema-paper
cf7677078 Make all root $ids absolute URIs
07fd389a3 Added test cases from Foundations of JSON Schema research paper
1008edcee ref: test empty tokens in json-pointer
9beb3cfba Merge pull request #627 from json-schema-org/ether/output-readme-fixes
f2b0490ba minor edit to trigger gh action
c305ce54f Merge pull request #669 from hauner/typo
5e2845c1e Merge pull request #668 from hauner/if-without-then-else-creates-annotations
2f1df2293 typo
c1fae0022 test unevaluated* can see annotations from if without then/else
987a4c8fc Merge pull request #666 from json-schema-org/gregsdennis/file-refs
90b2a58ce fix *nix uris
68d18c6ac rename tests to fix sanity check
e9166bcbe fix indentation
1d1ec749a add file-id ref tests
fb60ed17c Merge pull request #663 from json-schema-org/ether/restore-format-tests
f32cd8b80 Revert "Revert "by default, "format" only annotates, not validates""
47958f82d Merge pull request #654 from santhosh-tekuri/output-escape
5262997e1 Merge pull request #661 from santhosh-tekuri/2019-output
ce2c16573 output-tests: correct 2019 output-schema.json
c9d943856 output: ensure ~ and / are escaped in json-pointer
f6b2324bf minor spelling and markdown formatting fixes; `valid` has also been removed from the tests

git-subtree-dir: json
git-subtree-split: 6afa9b38d84d45550ec703123eb4e8ec67a8ae75
  • Loading branch information
Julian committed Apr 25, 2023
1 parent c8c0bdd commit b695cd7
Show file tree
Hide file tree
Showing 33 changed files with 1,239 additions and 56 deletions.
14 changes: 14 additions & 0 deletions bin/jsonschema_suite
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@ class SanityTests(unittest.TestCase):
"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",
Expand Down Expand Up @@ -528,6 +535,13 @@ class SanityTests(unittest.TestCase):
"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",
},
}

Expand Down
8 changes: 4 additions & 4 deletions output-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ These tests are intended to validate that implementations are correctly generati

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 between 2019-09 and 2020-12, the tests are replicated for 2020-12 because the `$schema` is different and implementations may (but shouldn't) produce different output.*
_**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.
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/2020 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.
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 the same as the validation tests in `tests/`, however an `output` property has been added to each test case.
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.

Expand Down
38 changes: 38 additions & 0 deletions output-tests/draft2019-09/content/escape.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
]
}
]
2 changes: 1 addition & 1 deletion output-tests/draft2019-09/output-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{
"properties": {
"keywordLocation": {
"pattern": "/\\$dynamicRef/"
"pattern": "/\\$recursiveRef/"
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions output-tests/draft2020-12/content/escape.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/draft-next/dependentSchemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,43 @@
"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
}
]
}
]
Loading

0 comments on commit b695cd7

Please sign in to comment.