Skip to content

Commit 036d0e4

Browse files
authored
Improve linter with regards to cross-dialect embedded resources (#542)
See: sourcemeta/studio#67 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 7f3ba4d commit 036d0e4

File tree

13 files changed

+103
-29
lines changed

13 files changed

+103
-29
lines changed

DEPENDENCIES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
2-
core https://github.com/sourcemeta/core f94f8b4bc7c1406ee37f86fe3c1886e8bedf70ee
2+
core https://github.com/sourcemeta/core eff08dbc8da88db93c52643ff2eb84db1741b662
33
jsonbinpack https://github.com/sourcemeta/jsonbinpack abd40e41050d14d74af1fddb5c397de5cca3b13c
44
blaze https://github.com/sourcemeta/blaze e6da51b14d4a187b03c175af2c87395f9c150d15
55
hydra https://github.com/sourcemeta/hydra af9f2c54709d620872ead0c3f8f683c15a0fa702

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ add_jsonschema_test_unix(compile/pass_resolve_remap_relative)
277277
# Lint
278278
add_jsonschema_test_unix(lint/pass_lint_fix)
279279
add_jsonschema_test_unix(lint/pass_lint_no_fix)
280+
add_jsonschema_test_unix(lint/pass_lint_embedded_resource)
280281
add_jsonschema_test_unix(lint/fail_lint)
281-
add_jsonschema_test_unix(lint/fail_lint_embedded_resource)
282+
add_jsonschema_test_unix(lint/fail_lint_invalid_embedded_resource)
282283
add_jsonschema_test_unix(lint/fail_lint_with_id)
283284
add_jsonschema_test_unix(lint/fail_lint_fix_broken_reference)
284285
add_jsonschema_test_unix(lint/fail_lint_default_dialect)

test/lint/fail_lint_embedded_resource.sh renamed to test/lint/fail_lint_invalid_embedded_resource.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cat << 'EOF' > "$TMP/schema.json"
1616
"embedded": {
1717
"$schema": "http://json-schema.org/draft-07/schema#",
1818
"$id": "embedded",
19-
"allOf": [ { "$ref": "#/definitions/foo" } ],
19+
"$ref": "#/definitions/foo",
2020
"definitions": {
2121
"foo": { "type": "number" }
2222
}
@@ -29,13 +29,15 @@ cd "$TMP"
2929
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
3030
test "$CODE" = "1" || exit 1
3131

32+
cat "$TMP/stderr.txt"
33+
3234
cat << 'EOF' > "$TMP/expected.txt"
3335
schema.json:10:7:
3436
`definitions` was superseded by `$defs` in 2019-09 and later versions (definitions_to_defs)
3537
at location "/$defs/embedded/definitions"
36-
schema.json:9:20:
37-
Wrapping `$ref` in `allOf` was only necessary in JSON Schema Draft 7 and older (unnecessary_allof_ref_wrapper_modern)
38-
at location "/$defs/embedded/allOf/0/$ref"
38+
schema.json:7:7:
39+
A `$schema` declaration without a sibling identifier (or with a sibling `$ref` in Draft 7 and older dialects), is ignored (ignored_metaschema)
40+
at location "/$defs/embedded/$schema"
3941
EOF
4042

4143
diff "$TMP/stderr.txt" "$TMP/expected.txt"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.json"
11+
{
12+
"$schema": "https://json-schema.org/draft/2020-12/schema",
13+
"$id": "https://example.com/main",
14+
"$ref": "embedded",
15+
"$defs": {
16+
"embedded": {
17+
"$schema": "http://json-schema.org/draft-07/schema#",
18+
"$id": "embedded",
19+
"allOf": [ { "$ref": "#/definitions/foo" } ],
20+
"definitions": {
21+
"foo": { "type": "number" }
22+
}
23+
}
24+
}
25+
}
26+
EOF
27+
28+
cd "$TMP"
29+
"$1" lint "$TMP/schema.json"

test/lint/pass_lint_list_exclude.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ exclusive_minimum_number_and_minimum
8888
if_without_then_else
8989
The `if` keyword is meaningless without the presence of the `then` or `else` keywords
9090
91+
ignored_metaschema
92+
A `$schema` declaration without a sibling identifier (or with a sibling `$ref` in Draft 7 and older dialects), is ignored
93+
9194
items_array_default
9295
Setting the `items` keyword to the empty array does not add any further constraint
9396
@@ -163,7 +166,7 @@ unsatisfiable_max_contains
163166
unsatisfiable_min_properties
164167
Setting `minProperties` to a number less than `required` does not add any further constraint
165168
166-
Number of rules: 51
169+
Number of rules: 52
167170
EOF
168171

169172
diff "$TMP/output.txt" "$TMP/expected.txt"

test/lint/pass_lint_list_long.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ exclusive_minimum_number_and_minimum
9494
if_without_then_else
9595
The `if` keyword is meaningless without the presence of the `then` or `else` keywords
9696
97+
ignored_metaschema
98+
A `$schema` declaration without a sibling identifier (or with a sibling `$ref` in Draft 7 and older dialects), is ignored
99+
97100
items_array_default
98101
Setting the `items` keyword to the empty array does not add any further constraint
99102
@@ -169,7 +172,7 @@ unsatisfiable_max_contains
169172
unsatisfiable_min_properties
170173
Setting `minProperties` to a number less than `required` does not add any further constraint
171174
172-
Number of rules: 53
175+
Number of rules: 54
173176
EOF
174177

175178
diff "$TMP/output.txt" "$TMP/expected.txt"

test/lint/pass_lint_list_short.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ exclusive_minimum_number_and_minimum
9494
if_without_then_else
9595
The `if` keyword is meaningless without the presence of the `then` or `else` keywords
9696
97+
ignored_metaschema
98+
A `$schema` declaration without a sibling identifier (or with a sibling `$ref` in Draft 7 and older dialects), is ignored
99+
97100
items_array_default
98101
Setting the `items` keyword to the empty array does not add any further constraint
99102
@@ -169,7 +172,7 @@ unsatisfiable_max_contains
169172
unsatisfiable_min_properties
170173
Setting `minProperties` to a number less than `required` does not add any further constraint
171174
172-
Number of rules: 53
175+
Number of rules: 54
173176
EOF
174177

175178
diff "$TMP/output.txt" "$TMP/expected.txt"

test/lint/pass_lint_list_strict.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ exclusive_minimum_number_and_minimum
9494
if_without_then_else
9595
The `if` keyword is meaningless without the presence of the `then` or `else` keywords
9696
97+
ignored_metaschema
98+
A `$schema` declaration without a sibling identifier (or with a sibling `$ref` in Draft 7 and older dialects), is ignored
99+
97100
items_array_default
98101
Setting the `items` keyword to the empty array does not add any further constraint
99102
@@ -172,7 +175,7 @@ unsatisfiable_max_contains
172175
unsatisfiable_min_properties
173176
Setting `minProperties` to a number less than `required` does not add any further constraint
174177
175-
Number of rules: 54
178+
Number of rules: 55
176179
EOF
177180

178181
diff "$TMP/output.txt" "$TMP/expected.txt"

vendor/core/src/core/jsonschema/frame.cc

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/core/src/core/jsonschema/transformer.cc

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)