Skip to content

Commit

Permalink
encoding/jsonschema: use StrictFeatures in external tests
Browse files Browse the repository at this point in the history
The spec specifically says that unknown keywords should be ignored, so
use `StrictFeatures` in the external tests so they correspond better to
the spec.

Also, use `StrictFeatures` rather than `Strict` in one of the
constraints, as we should never be using `Strict` as a condition.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: If4d66285b6a9f77bb6ae4915a4818967290578f2
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201117
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Sep 12, 2024
1 parent af57269 commit bef55cb
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 101 deletions.
4 changes: 2 additions & 2 deletions encoding/jsonschema/constraints_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func constraintID(key string, n cue.Value, s *state) {
}

if u.Fragment != "" {
// TODO do not use Strict for this. The specification is clear:
// TODO do not use StrictFeatures for this. The specification is clear:
// before 2019-09, IDs could contain plain-name fragments;
// (see https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.5)
// afterwards, $anchor was reserved for that purpose.
if s.cfg.Strict {
if s.cfg.StrictFeatures {
s.errf(n, "$id URI may not contain a fragment")
}
return
Expand Down
2 changes: 1 addition & 1 deletion encoding/jsonschema/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *ex
t.Skipf("skipping test for unknown schema version %v", versStr)
}
schemaAST, extractErr := jsonschema.Extract(jsonValue, &jsonschema.Config{
Strict: true,
StrictFeatures: true,
DefaultVersion: vers,
})
var schemaValue cue.Value
Expand Down
12 changes: 6 additions & 6 deletions encoding/jsonschema/external_teststats.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by teststats. DO NOT EDIT
v2:
schema extract (pass / total): 1072 / 1637 = 65.5%
tests (pass / total): 3457 / 7175 = 48.2%
tests on extracted schemas (pass / total): 3457 / 3874 = 89.2%
schema extract (pass / total): 1077 / 1637 = 65.8%
tests (pass / total): 3467 / 7175 = 48.3%
tests on extracted schemas (pass / total): 3467 / 3884 = 89.3%

v3:
schema extract (pass / total): 1060 / 1637 = 64.8%
tests (pass / total): 3408 / 7175 = 47.5%
tests on extracted schemas (pass / total): 3408 / 3830 = 89.0%
schema extract (pass / total): 1065 / 1637 = 65.1%
tests (pass / total): 3418 / 7175 = 47.6%
tests on extracted schemas (pass / total): 3418 / 3840 = 89.0%
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
},
"skip": {
"v2": "extract error: unknown keyword \"unknown-keyword\"",
"v3": "extract error: unknown keyword \"unknown-keyword\""
"v2": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n",
"v3": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n"
},
"tests": [
{
Expand Down Expand Up @@ -57,8 +57,8 @@
}
},
"skip": {
"v2": "extract error: unknown keyword \"unknown-keyword\"",
"v3": "extract error: unknown keyword \"unknown-keyword\""
"v2": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n",
"v3": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n"
},
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
]
},
"skip": {
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
},
"skip": {
"v2": "extract error: unknown keyword \"unknown-keyword\"",
"v3": "extract error: unknown keyword \"unknown-keyword\""
"v2": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n",
"v3": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n"
},
"tests": [
{
Expand Down Expand Up @@ -57,8 +57,8 @@
}
},
"skip": {
"v2": "extract error: unknown keyword \"unknown-keyword\"",
"v3": "extract error: unknown keyword \"unknown-keyword\""
"v2": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n",
"v3": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n"
},
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
]
},
"skip": {
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
]
},
"skip": {
"v2": "extract error: keyword \"const\" is not supported in JSON schema version http://json-schema.org/draft-04/schema#",
"v3": "extract error: keyword \"const\" is not supported in JSON schema version http://json-schema.org/draft-04/schema#"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down
4 changes: 2 additions & 2 deletions encoding/jsonschema/testdata/external/tests/draft4/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@
]
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-04/schema# (and 1 more errors)",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-04/schema# (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
]
},
"skip": {
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down
84 changes: 12 additions & 72 deletions encoding/jsonschema/testdata/external/tests/draft6/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@
]
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema# (and 1 more errors)",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema# (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down Expand Up @@ -993,32 +993,20 @@
}
}
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
},
"tests": [
{
"description": "valid under the URN IDed schema",
"data": {
"foo": 37
},
"valid": true,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": true
},
{
"description": "invalid under the URN IDed schema",
"data": {
"foo": 12
},
"valid": false,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": false
}
]
},
Expand All @@ -1038,32 +1026,20 @@
}
}
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
},
"tests": [
{
"description": "a string is valid",
"data": {
"foo": "bar"
},
"valid": true,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": true
},
{
"description": "a non-string is invalid",
"data": {
"foo": 12
},
"valid": false,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": false
}
]
},
Expand All @@ -1083,32 +1059,20 @@
}
}
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
},
"tests": [
{
"description": "a string is valid",
"data": {
"foo": "bar"
},
"valid": true,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": true
},
{
"description": "a non-string is invalid",
"data": {
"foo": 12
},
"valid": false,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": false
}
]
},
Expand All @@ -1128,32 +1092,20 @@
}
}
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
},
"tests": [
{
"description": "a string is valid",
"data": {
"foo": "bar"
},
"valid": true,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": true
},
{
"description": "a non-string is invalid",
"data": {
"foo": 12
},
"valid": false,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": false
}
]
},
Expand All @@ -1173,32 +1125,20 @@
}
}
},
"skip": {
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
},
"tests": [
{
"description": "a string is valid",
"data": {
"foo": "bar"
},
"valid": true,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": true
},
{
"description": "a non-string is invalid",
"data": {
"foo": 12
},
"valid": false,
"skip": {
"v2": "could not compile schema",
"v3": "could not compile schema"
}
"valid": false
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
]
},
"skip": {
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
},
"tests": [
{
Expand Down

0 comments on commit bef55cb

Please sign in to comment.