Skip to content

Commit

Permalink
Fully support JSON Schema 2019-09 on every command
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Aug 9, 2024
1 parent ffc621f commit 8da8967
Show file tree
Hide file tree
Showing 52 changed files with 1,316 additions and 599 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa 7e26abce7a4e31e86a16ef2851702a56773ca527
jsontoolkit https://github.com/sourcemeta/jsontoolkit 43efc7fb2cc2fa4a4546a2e9a9f5fefabbfa065f
jsontoolkit https://github.com/sourcemeta/jsontoolkit c590926d29ee76d00f2bc7d13b2e51ac66cc2d7e
hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc
17 changes: 17 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ local development and when running on CI/CD pipelines. For example:
> and Code: Designing Data Products with JSON
> Schema](https://www.oreilly.com/library/view/unifying-business-data/9781098144999/).
Version support
---------------

We aim to fully support _every_ version of JSON Schema.

| Dialect | Support |
|---------------------|---------|
| JSON Schema 2020-12 | Partial |
| JSON Schema 2019-09 | Full |
| JSON Schema Draft 7 | Full |
| JSON Schema Draft 6 | Full |
| JSON Schema Draft 4 | Full |
| JSON Schema Draft 3 | Partial |
| JSON Schema Draft 2 | Partial |
| JSON Schema Draft 1 | Partial |
| JSON Schema Draft 0 | Partial |

What our users are saying
-------------------------

Expand Down
6 changes: 3 additions & 3 deletions docs/compile.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Compile
=======

> [!WARNING]
> Only JSON Schema Draft 4, Draft 6, and Draft 7 are supported at this point in
> time. We have plans to support *every* dialect of JSON Schema from Draft 0 to
> Draft 2020-12 soon.
> Only JSON Schema Draft 4, Draft 6, Draft 7, and 2019-09 are supported at this
> point in time. We have plans to support *every* dialect of JSON Schema from
> Draft 0 to Draft 2020-12 soon.
```sh
jsonschema compile <schema.json>
Expand Down
5 changes: 5 additions & 0 deletions docs/metaschema.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Metaschema
==========

> [!WARNING]
> Only JSON Schema Draft 4, Draft 6, Draft 7, and 2019-09 are supported at this
> point in time. We have plans to support *every* dialect of JSON Schema from
> Draft 0 to Draft 2020-12 soon.
```sh
jsonschema metaschema [schemas-or-directories...]
[--verbose/-v] [--http/-h] [--extension/-e <extension>]
Expand Down
6 changes: 3 additions & 3 deletions docs/test.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Testing
=======

> [!WARNING]
> Only JSON Schema Draft 4, Draft 6, and Draft 7 are supported at this point in
> time. We have plans to support *every* dialect of JSON Schema from Draft 0 to
> Draft 2020-12 soon.
> Only JSON Schema Draft 4, Draft 6, Draft 7, and 2019-09 are supported at this
> point in time. We have plans to support *every* dialect of JSON Schema from
> Draft 0 to Draft 2020-12 soon.
```sh
jsonschema test [schemas-or-directories...]
Expand Down
6 changes: 3 additions & 3 deletions docs/validate.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Validating
==========

> [!WARNING]
> Only JSON Schema Draft 4, Draft 6, and Draft 7 are supported at this point in
> time. We have plans to support *every* dialect of JSON Schema from Draft 0 to
> Draft 2020-12 soon.
> Only JSON Schema Draft 4, Draft 6, Draft 7, and 2019-09 are supported at this
> point in time. We have plans to support *every* dialect of JSON Schema from
> Draft 0 to Draft 2020-12 soon.
```sh
jsonschema validate <schema.json> <instance.json|.jsonl...> [--http/-h]
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ add_jsonschema_test_unix(validate/pass_verbose)
add_jsonschema_test_unix(validate/pass_draft4)
add_jsonschema_test_unix(validate/pass_draft6)
add_jsonschema_test_unix(validate/pass_draft7)
add_jsonschema_test_unix(validate/pass_2019_09)
add_jsonschema_test_unix(validate/fail_draft4)
add_jsonschema_test_unix(validate/fail_draft6)
add_jsonschema_test_unix(validate/fail_draft7)
add_jsonschema_test_unix(validate/fail_2019_09)
add_jsonschema_test_unix(validate/pass_jsonl)
add_jsonschema_test_unix(validate/pass_jsonl_verbose)
add_jsonschema_test_unix(validate/fail_jsonl_invalid_entry)
Expand Down
10 changes: 10 additions & 0 deletions test/compile/pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cat << 'EOF' > "$TMP/expected.json"
"category": "logical",
"type": "and",
"value": null,
"schemaResource": "",
"absoluteKeywordLocation": "#/properties",
"relativeSchemaLocation": "/properties",
"relativeInstanceLocation": "",
Expand All @@ -32,12 +33,14 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": [],
"children": [
{
"category": "internal",
"type": "container",
"value": null,
"schemaResource": "",
"absoluteKeywordLocation": "#/properties",
"relativeSchemaLocation": "",
"relativeInstanceLocation": "",
Expand All @@ -46,6 +49,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": [
{
"category": "assertion",
Expand All @@ -55,6 +59,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "string",
"value": "foo"
},
"schemaResource": "",
"absoluteKeywordLocation": "#/properties",
"relativeSchemaLocation": "",
"relativeInstanceLocation": "",
Expand All @@ -63,6 +68,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": []
}
],
Expand All @@ -75,6 +81,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "type",
"value": "string"
},
"schemaResource": "",
"absoluteKeywordLocation": "#/properties/foo/type",
"relativeSchemaLocation": "/foo/type",
"relativeInstanceLocation": "/foo",
Expand All @@ -83,6 +90,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": []
},
{
Expand All @@ -93,6 +101,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "json",
"value": "foo"
},
"schemaResource": "",
"absoluteKeywordLocation": "#/properties",
"relativeSchemaLocation": "",
"relativeInstanceLocation": "",
Expand All @@ -101,6 +110,7 @@ cat << 'EOF' > "$TMP/expected.json"
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": []
}
]
Expand Down
41 changes: 41 additions & 0 deletions test/validate/fail_2019_09.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

cat << 'EOF' > "$TMP/instance.json"
{ "foo": 1 }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/instance.json
error: Schema validation failure
The target document is expected to be of the given type
at instance location "/foo"
at evaluate path "/properties/foo/type"
The target is expected to match all of the given assertions
at instance location ""
at evaluate path "/properties"
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
25 changes: 25 additions & 0 deletions test/validate/pass_2019_09.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

cat << 'EOF' > "$TMP/instance.json"
{ "foo": "bar" }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json"
7 changes: 7 additions & 0 deletions vendor/jsontoolkit/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions vendor/jsontoolkit/Config.uk

This file was deleted.

71 changes: 0 additions & 71 deletions vendor/jsontoolkit/Makefile.uk

This file was deleted.

5 changes: 5 additions & 0 deletions vendor/jsontoolkit/cmake/FindGoogleBenchmark.cmake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8da8967

Please sign in to comment.