Skip to content

Commit

Permalink
[WIP] 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 ff9841e
Show file tree
Hide file tree
Showing 51 changed files with 1,299 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 402fa43c7790778f99240961fcfa4b30bc2775cc
hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc
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.

19 changes: 14 additions & 5 deletions vendor/jsontoolkit/src/json/json_value.cc

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

Loading

0 comments on commit ff9841e

Please sign in to comment.