Skip to content

Commit bef55cb

Browse files
committed
encoding/jsonschema: use StrictFeatures in external tests
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]>
1 parent af57269 commit bef55cb

File tree

12 files changed

+41
-101
lines changed

12 files changed

+41
-101
lines changed

encoding/jsonschema/constraints_meta.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func constraintID(key string, n cue.Value, s *state) {
3434
}
3535

3636
if u.Fragment != "" {
37-
// TODO do not use Strict for this. The specification is clear:
37+
// TODO do not use StrictFeatures for this. The specification is clear:
3838
// before 2019-09, IDs could contain plain-name fragments;
3939
// (see https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.5)
4040
// afterwards, $anchor was reserved for that purpose.
41-
if s.cfg.Strict {
41+
if s.cfg.StrictFeatures {
4242
s.errf(n, "$id URI may not contain a fragment")
4343
}
4444
return

encoding/jsonschema/external_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *ex
9292
t.Skipf("skipping test for unknown schema version %v", versStr)
9393
}
9494
schemaAST, extractErr := jsonschema.Extract(jsonValue, &jsonschema.Config{
95-
Strict: true,
95+
StrictFeatures: true,
9696
DefaultVersion: vers,
9797
})
9898
var schemaValue cue.Value
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Generated by teststats. DO NOT EDIT
22
v2:
3-
schema extract (pass / total): 1072 / 1637 = 65.5%
4-
tests (pass / total): 3457 / 7175 = 48.2%
5-
tests on extracted schemas (pass / total): 3457 / 3874 = 89.2%
3+
schema extract (pass / total): 1077 / 1637 = 65.8%
4+
tests (pass / total): 3467 / 7175 = 48.3%
5+
tests on extracted schemas (pass / total): 3467 / 3884 = 89.3%
66

77
v3:
8-
schema extract (pass / total): 1060 / 1637 = 64.8%
9-
tests (pass / total): 3408 / 7175 = 47.5%
10-
tests on extracted schemas (pass / total): 3408 / 3830 = 89.0%
8+
schema extract (pass / total): 1065 / 1637 = 65.1%
9+
tests (pass / total): 3418 / 7175 = 47.6%
10+
tests on extracted schemas (pass / total): 3418 / 3840 = 89.0%

encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
}
1414
},
1515
"skip": {
16-
"v2": "extract error: unknown keyword \"unknown-keyword\"",
17-
"v3": "extract error: unknown keyword \"unknown-keyword\""
16+
"v2": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n",
17+
"v3": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n"
1818
},
1919
"tests": [
2020
{
@@ -57,8 +57,8 @@
5757
}
5858
},
5959
"skip": {
60-
"v2": "extract error: unknown keyword \"unknown-keyword\"",
61-
"v3": "extract error: unknown keyword \"unknown-keyword\""
60+
"v2": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n",
61+
"v3": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n"
6262
},
6363
"tests": [
6464
{

encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
]
4444
},
4545
"skip": {
46-
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
47-
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
46+
"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",
47+
"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"
4848
},
4949
"tests": [
5050
{

encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
}
1414
},
1515
"skip": {
16-
"v2": "extract error: unknown keyword \"unknown-keyword\"",
17-
"v3": "extract error: unknown keyword \"unknown-keyword\""
16+
"v2": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n",
17+
"v3": "extract error: cannot compile resulting schema: bar: reference \"_X0\" not found:\n generated.cue:3:8\n"
1818
},
1919
"tests": [
2020
{
@@ -57,8 +57,8 @@
5757
}
5858
},
5959
"skip": {
60-
"v2": "extract error: unknown keyword \"unknown-keyword\"",
61-
"v3": "extract error: unknown keyword \"unknown-keyword\""
60+
"v2": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n",
61+
"v3": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n"
6262
},
6363
"tests": [
6464
{

encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
]
4444
},
4545
"skip": {
46-
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
47-
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
46+
"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",
47+
"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"
4848
},
4949
"tests": [
5050
{

encoding/jsonschema/testdata/external/tests/draft4/optional/id.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
]
3434
},
3535
"skip": {
36-
"v2": "extract error: keyword \"const\" is not supported in JSON schema version http://json-schema.org/draft-04/schema#",
37-
"v3": "extract error: keyword \"const\" is not supported in JSON schema version http://json-schema.org/draft-04/schema#"
36+
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
37+
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
3838
},
3939
"tests": [
4040
{

encoding/jsonschema/testdata/external/tests/draft4/ref.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@
329329
]
330330
},
331331
"skip": {
332-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-04/schema# (and 1 more errors)",
333-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-04/schema# (and 1 more errors)"
332+
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n",
333+
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n"
334334
},
335335
"tests": [
336336
{

encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
]
4343
},
4444
"skip": {
45-
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
46-
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
45+
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
46+
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
4747
},
4848
"tests": [
4949
{

encoding/jsonschema/testdata/external/tests/draft6/ref.json

+12-72
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@
329329
]
330330
},
331331
"skip": {
332-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema# (and 1 more errors)",
333-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema# (and 1 more errors)"
332+
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n",
333+
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n"
334334
},
335335
"tests": [
336336
{
@@ -993,32 +993,20 @@
993993
}
994994
}
995995
},
996-
"skip": {
997-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
998-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
999-
},
1000996
"tests": [
1001997
{
1002998
"description": "valid under the URN IDed schema",
1003999
"data": {
10041000
"foo": 37
10051001
},
1006-
"valid": true,
1007-
"skip": {
1008-
"v2": "could not compile schema",
1009-
"v3": "could not compile schema"
1010-
}
1002+
"valid": true
10111003
},
10121004
{
10131005
"description": "invalid under the URN IDed schema",
10141006
"data": {
10151007
"foo": 12
10161008
},
1017-
"valid": false,
1018-
"skip": {
1019-
"v2": "could not compile schema",
1020-
"v3": "could not compile schema"
1021-
}
1009+
"valid": false
10221010
}
10231011
]
10241012
},
@@ -1038,32 +1026,20 @@
10381026
}
10391027
}
10401028
},
1041-
"skip": {
1042-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
1043-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
1044-
},
10451029
"tests": [
10461030
{
10471031
"description": "a string is valid",
10481032
"data": {
10491033
"foo": "bar"
10501034
},
1051-
"valid": true,
1052-
"skip": {
1053-
"v2": "could not compile schema",
1054-
"v3": "could not compile schema"
1055-
}
1035+
"valid": true
10561036
},
10571037
{
10581038
"description": "a non-string is invalid",
10591039
"data": {
10601040
"foo": 12
10611041
},
1062-
"valid": false,
1063-
"skip": {
1064-
"v2": "could not compile schema",
1065-
"v3": "could not compile schema"
1066-
}
1042+
"valid": false
10671043
}
10681044
]
10691045
},
@@ -1083,32 +1059,20 @@
10831059
}
10841060
}
10851061
},
1086-
"skip": {
1087-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
1088-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
1089-
},
10901062
"tests": [
10911063
{
10921064
"description": "a string is valid",
10931065
"data": {
10941066
"foo": "bar"
10951067
},
1096-
"valid": true,
1097-
"skip": {
1098-
"v2": "could not compile schema",
1099-
"v3": "could not compile schema"
1100-
}
1068+
"valid": true
11011069
},
11021070
{
11031071
"description": "a non-string is invalid",
11041072
"data": {
11051073
"foo": 12
11061074
},
1107-
"valid": false,
1108-
"skip": {
1109-
"v2": "could not compile schema",
1110-
"v3": "could not compile schema"
1111-
}
1075+
"valid": false
11121076
}
11131077
]
11141078
},
@@ -1128,32 +1092,20 @@
11281092
}
11291093
}
11301094
},
1131-
"skip": {
1132-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
1133-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
1134-
},
11351095
"tests": [
11361096
{
11371097
"description": "a string is valid",
11381098
"data": {
11391099
"foo": "bar"
11401100
},
1141-
"valid": true,
1142-
"skip": {
1143-
"v2": "could not compile schema",
1144-
"v3": "could not compile schema"
1145-
}
1101+
"valid": true
11461102
},
11471103
{
11481104
"description": "a non-string is invalid",
11491105
"data": {
11501106
"foo": 12
11511107
},
1152-
"valid": false,
1153-
"skip": {
1154-
"v2": "could not compile schema",
1155-
"v3": "could not compile schema"
1156-
}
1108+
"valid": false
11571109
}
11581110
]
11591111
},
@@ -1173,32 +1125,20 @@
11731125
}
11741126
}
11751127
},
1176-
"skip": {
1177-
"v2": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#",
1178-
"v3": "extract error: keyword \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#"
1179-
},
11801128
"tests": [
11811129
{
11821130
"description": "a string is valid",
11831131
"data": {
11841132
"foo": "bar"
11851133
},
1186-
"valid": true,
1187-
"skip": {
1188-
"v2": "could not compile schema",
1189-
"v3": "could not compile schema"
1190-
}
1134+
"valid": true
11911135
},
11921136
{
11931137
"description": "a non-string is invalid",
11941138
"data": {
11951139
"foo": 12
11961140
},
1197-
"valid": false,
1198-
"skip": {
1199-
"v2": "could not compile schema",
1200-
"v3": "could not compile schema"
1201-
}
1141+
"valid": false
12021142
}
12031143
]
12041144
},

encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
]
4343
},
4444
"skip": {
45-
"v2": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)",
46-
"v3": "extract error: unknown keyword \"array_of_schemas\" (and 1 more errors)"
45+
"v2": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n",
46+
"v3": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/unknownKeyword/my_identifier.json:my_identifier\":\n generated.cue:1:8\n"
4747
},
4848
"tests": [
4949
{

0 commit comments

Comments
 (0)