From f2b1b2198f28cb328424d2498e0102e49e91d1a6 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 10 Sep 2024 11:26:06 +0100 Subject: [PATCH] internal/filetypes: default strictFeatures to true In general in JSON Schema we want to ignore keywords which aren't defined, but it seems better to default to giving an error when there's a keyword that we know is not implemented, meaning that the schema cannot be interpreted correctly. To revert to previous behavior, `jsonschema+strictFeatures=0:` can be used. Signed-off-by: Roger Peppe Change-Id: I65d24ae8c147d36499b4e02b418bedcc6d1a376b Dispatch-Trailer: {"type":"trybot","CL":1200932,"patchset":3,"ref":"refs/changes/32/1200932/3","targetBranch":"master"} --- .../cmd/testdata/script/def_jsonschema.txtar | 5 ++++- internal/filetypes/filetypes_test.go | 19 +++++++++++++++++-- internal/filetypes/types.cue | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar index 474f09973..f68cc3b97 100644 --- a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar +++ b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar @@ -5,7 +5,10 @@ cmp stdout expect-stdout exec cue def schema.json -p schema -l '#Person:' cmp stdout expect-stdout -exec cue def jsonschema: bad.json +! exec cue def jsonschema: bad.json +cmp stderr expect-stderr-strict-features + +exec cue def jsonschema+strictFeatures=0: bad.json ! exec cue def jsonschema: bad.json --strict cmp stderr expect-stderr diff --git a/internal/filetypes/filetypes_test.go b/internal/filetypes/filetypes_test.go index a675fe322..6e4805a98 100644 --- a/internal/filetypes/filetypes_test.go +++ b/internal/filetypes/filetypes_test.go @@ -181,7 +181,7 @@ func TestFromFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": false, + "strictFeatures": true, "strictKeywords": false, }, }, @@ -419,7 +419,7 @@ func TestParseArgs(t *testing.T) { Interpretation: "jsonschema", BoolTags: map[string]bool{ "strict": false, - "strictFeatures": false, + "strictFeatures": true, "strictKeywords": false, }, }, @@ -439,6 +439,21 @@ func TestParseArgs(t *testing.T) { }, }, }, + }, { + in: "jsonschema+strictFeatures=0: bar.schema", + out: []*build.File{ + { + Filename: "bar.schema", + Encoding: "json", + Interpretation: "jsonschema", + Form: build.Schema, + BoolTags: map[string]bool{ + "strict": false, + "strictFeatures": false, + "strictKeywords": false, + }, + }, + }, }, { in: `json: c:\foo.json c:\path\to\file.dat`, out: []*build.File{ diff --git a/internal/filetypes/types.cue b/internal/filetypes/types.cue index 19c95c6cd..7f42bb4fb 100644 --- a/internal/filetypes/types.cue +++ b/internal/filetypes/types.cue @@ -297,7 +297,7 @@ interpretations: jsonschema: { boolTags: { strict: *false | bool strictKeywords: *strict | bool - strictFeatures: *strict | bool + strictFeatures: *true | bool } }