Skip to content

Commit

Permalink
Fully support JSON Schema 2020-12
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 14, 2024
1 parent 446a4d0 commit a11591e
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 377 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 e7a8f35b0b85cd87b5fa587b2ae767ed939a0b4d
jsontoolkit https://github.com/sourcemeta/jsontoolkit 00251a4161434463c24bc18418e3ffd37f998f29
hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ We aim to fully support _every_ version of JSON Schema and combinations between

| Dialect | Support |
|---------------------|------------------------------------------------------------------|
| JSON Schema 2020-12 | Partial (except `validate`, `test`, `metaschema`, and `compile`) |
| JSON Schema 2020-12 | **Full** |
| JSON Schema 2019-09 | **Full** |
| JSON Schema Draft 7 | **Full** |
| JSON Schema Draft 6 | **Full** |
Expand Down
4 changes: 1 addition & 3 deletions docs/compile.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ Compile
=======

> [!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.
> JSON Schema Draft 3 and older are not supported at this point in time.
```sh
jsonschema compile <schema.json>
Expand Down
4 changes: 1 addition & 3 deletions docs/metaschema.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ 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.
> JSON Schema Draft 3 and older are not supported at this point in time.
```sh
jsonschema metaschema [schemas-or-directories...]
Expand Down
4 changes: 1 addition & 3 deletions docs/test.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ Testing
=======

> [!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.
> JSON Schema Draft 3 and older are not supported at this point in time.
```sh
jsonschema test [schemas-or-directories...]
Expand Down
4 changes: 1 addition & 3 deletions docs/validate.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ Validating
==========

> [!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.
> JSON Schema Draft 3 and older are not supported at this point in time.
```sh
jsonschema validate <schema.json> <instance.json|.jsonl...> [--http/-h]
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_jsonschema_test_unix(metaschema_fail_single)
add_jsonschema_test_unix(metaschema_fail_non_schema)
add_jsonschema_test_unix(metaschema_pass_cwd)
add_jsonschema_test_unix(metaschema_pass_single)
add_jsonschema_test_unix(metaschema_pass_2020_12)

# Validate
add_jsonschema_test_unix(validate/fail_instance_directory)
Expand All @@ -58,10 +59,12 @@ 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/pass_2020_12)
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/fail_2020_12)
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
17 changes: 17 additions & 0 deletions test/metaschema_pass_2020_12.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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/2020-12/schema",
"type": "string"
}
EOF

"$1" metaschema "$TMP/schema.json"
41 changes: 41 additions & 0 deletions test/validate/fail_2020_12.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/2020-12/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"
4 changes: 3 additions & 1 deletion test/validate/fail_relative_external_ref_missing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://example.com",
"$ref": "nested"
"allOf": [
{ "$ref": "nested" }
]
}
EOF

Expand Down
25 changes: 25 additions & 0 deletions test/validate/pass_2020_12.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/2020-12/schema",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

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

"$1" validate "$TMP/schema.json" "$TMP/instance.json"
4 changes: 2 additions & 2 deletions vendor/jsontoolkit/src/jsonschema/CMakeLists.txt

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

7 changes: 4 additions & 3 deletions vendor/jsontoolkit/src/jsonschema/compile.cc

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

48 changes: 12 additions & 36 deletions vendor/jsontoolkit/src/jsonschema/compile_evaluate.cc

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

16 changes: 14 additions & 2 deletions vendor/jsontoolkit/src/jsonschema/default_compiler_2020_12.h

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

Loading

0 comments on commit a11591e

Please sign in to comment.