From bef55cb1eddb0d1d9fc2a065a5144d1b20e83198 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Thu, 12 Sep 2024 15:23:10 +0100 Subject: [PATCH] encoding/jsonschema: use StrictFeatures in external tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: If4d66285b6a9f77bb6ae4915a4818967290578f2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201117 Reviewed-by: Daniel Martí Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- encoding/jsonschema/constraints_meta.go | 4 +- encoding/jsonschema/external_test.go | 2 +- encoding/jsonschema/external_teststats.txt | 12 +-- .../optional/refOfUnknownKeyword.json | 8 +- .../draft2019-09/optional/unknownKeyword.json | 4 +- .../optional/refOfUnknownKeyword.json | 8 +- .../draft2020-12/optional/unknownKeyword.json | 4 +- .../external/tests/draft4/optional/id.json | 4 +- .../testdata/external/tests/draft4/ref.json | 4 +- .../tests/draft6/optional/unknownKeyword.json | 4 +- .../testdata/external/tests/draft6/ref.json | 84 +++---------------- .../tests/draft7/optional/unknownKeyword.json | 4 +- 12 files changed, 41 insertions(+), 101 deletions(-) diff --git a/encoding/jsonschema/constraints_meta.go b/encoding/jsonschema/constraints_meta.go index e99444d5e44..6f371a7688a 100644 --- a/encoding/jsonschema/constraints_meta.go +++ b/encoding/jsonschema/constraints_meta.go @@ -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 diff --git a/encoding/jsonschema/external_test.go b/encoding/jsonschema/external_test.go index 6ea3c34021c..12f2c8ed726 100644 --- a/encoding/jsonschema/external_test.go +++ b/encoding/jsonschema/external_test.go @@ -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 diff --git a/encoding/jsonschema/external_teststats.txt b/encoding/jsonschema/external_teststats.txt index 175ca323e1e..b9934375293 100644 --- a/encoding/jsonschema/external_teststats.txt +++ b/encoding/jsonschema/external_teststats.txt @@ -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% diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json index 70c06635444..c4c3807e818 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json @@ -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": [ { @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json index 5862a066e27..c5555f4be54 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json index a9371eacab7..ec1aba50cec 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json @@ -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": [ { @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json index 5e3a4d2570c..005a0f3918d 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json index 9e295a3c9e0..596a269f827 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft4/ref.json b/encoding/jsonschema/testdata/external/tests/draft4/ref.json index 6128b344fee..4f27fe02eb5 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/ref.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/ref.json @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json index f60e74e6ff5..c30a4ec0584 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json @@ -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": [ { diff --git a/encoding/jsonschema/testdata/external/tests/draft6/ref.json b/encoding/jsonschema/testdata/external/tests/draft6/ref.json index 7e11cf10b9c..5adfd9d198d 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/ref.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/ref.json @@ -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": [ { @@ -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 } ] }, @@ -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 } ] }, @@ -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 } ] }, @@ -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 } ] }, @@ -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 } ] }, diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json index f60e74e6ff5..c30a4ec0584 100644 --- a/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json @@ -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": [ {