diff --git a/cmd/cue/cmd/help.go b/cmd/cue/cmd/help.go index bf77410d19d..54f7c5a3ef3 100644 --- a/cmd/cue/cmd/help.go +++ b/cmd/cue/cmd/help.go @@ -615,16 +615,10 @@ The following tags are only valid in combination with other tags, and influence the functioning of the codec. The tag they are valid with is mentioned in parentheses at the end. - strictFeatures report errors for lossy mappings. Enabled by default (jsonschema) + strictFeatures report errors for lossy mappings. (jsonschema) strictKeywords report errors for unknown keywords (jsonschema) strict report errors for either of the above (jsonschema) -The above flags also accept a boolean flag value (e.g. true, 1, false, 0) -to set them explicitly. For example, to ignore unimplemented JSON Schema -features rather than giving an error: - - jsonschema+strictFeatures=0 - Many commands also support the --out and --outfile/-o flags. The --out flag specifies the output type using a qualifier (without the ':'). The -o flag specifies an output file diff --git a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar index bb8f322410b..075e9a65d4f 100644 --- a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar +++ b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar @@ -5,21 +5,20 @@ cmp stdout expect-stdout exec cue def schema.json -p schema -l '#Person:' cmp stdout expect-stdout -! exec cue def jsonschema: bad.json -cmp stderr expect-stderr-strict-features +exec cue def jsonschema: bad.json # The default strictness modes should apply even when # we haven't explicitly specifed the jsonschema file type. -! exec cue def bad.json +! exec cue def jsonschema+strictFeatures: bad.json cmp stderr expect-stderr-strict-features -exec cue def jsonschema+strictFeatures=0: bad.json +exec cue def jsonschema: bad.json ! exec cue def jsonschema: bad.json --strict -cmp stderr expect-stderr +cmp stderr expect-stderr-strict ! exec cue def jsonschema+strict: bad.json -cmp stderr expect-stderr +cmp stderr expect-stderr-strict # With only strict features, it should error only for the # unimplemented feature and not for the unknown keyword. @@ -83,7 +82,7 @@ import "strings" "$dynamicAnchor": "bar", "foo": true } --- expect-stderr -- +-- expect-stderr-strict -- keyword "$dynamicAnchor" not yet implemented: ./bad.json:4:3 unknown keyword "foo": diff --git a/cmd/cue/cmd/testdata/script/def_openapi_strict.txtar b/cmd/cue/cmd/testdata/script/def_openapi_strict.txtar index 95f3ccbd14e..56f03619e2c 100644 --- a/cmd/cue/cmd/testdata/script/def_openapi_strict.txtar +++ b/cmd/cue/cmd/testdata/script/def_openapi_strict.txtar @@ -1,16 +1,14 @@ -! exec cue def openapi: openapi.json -cmp stderr expect-stderr-1 +exec cue def openapi: openapi.json -! exec cue def openapi.json -cmp stderr expect-stderr-1 +# Default is to best-effort mode. +exec cue def openapi.json +cmp stdout expect-out.cue +# We can enable strictFeatures to give an error when +# unimplemented features are used. ! exec cue def openapi+strictFeatures: openapi.json cmp stderr expect-stderr-1 -# We can disable strictFeatures to enable best effort mode. -exec cue def openapi+strictFeatures=0: openapi.json -cmp stdout expect-out.cue - # Bad keywords are still always bad with OpenAPI 3.0. ! exec cue def openapi-badkeyword.json cmp stderr expect-stderr-2 diff --git a/internal/filetypes/filetypes_test.go b/internal/filetypes/filetypes_test.go index 8012292751e..67b821921e5 100644 --- a/internal/filetypes/filetypes_test.go +++ b/internal/filetypes/filetypes_test.go @@ -132,7 +132,7 @@ func TestFromFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -187,7 +187,7 @@ func TestFromFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -218,7 +218,7 @@ func TestFromFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -249,7 +249,7 @@ func TestFromFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -349,7 +349,7 @@ func TestParseFile(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -440,7 +440,7 @@ func TestParseArgs(t *testing.T) { Interpretation: "jsonschema", BoolTags: map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, }, }, @@ -461,7 +461,7 @@ func TestParseArgs(t *testing.T) { }, }, }, { - in: "jsonschema+strictFeatures=0: bar.schema", + in: "jsonschema+strictFeatures=1: bar.schema", out: []*build.File{ { Filename: "bar.schema", @@ -470,7 +470,7 @@ func TestParseArgs(t *testing.T) { Form: build.Schema, BoolTags: map[string]bool{ "strict": false, - "strictFeatures": false, + "strictFeatures": true, "strictKeywords": false, }, }, @@ -503,7 +503,7 @@ func TestDefaultTagsForInterpretation(t *testing.T) { tags := DefaultTagsForInterpretation(build.JSONSchema, Input) qt.Assert(t, qt.DeepEquals(tags, map[string]bool{ "strict": false, - "strictFeatures": true, + "strictFeatures": false, "strictKeywords": false, })) } diff --git a/internal/filetypes/types.cue b/internal/filetypes/types.cue index 8ab5ff71ab9..3597c1a420e 100644 --- a/internal/filetypes/types.cue +++ b/internal/filetypes/types.cue @@ -297,7 +297,8 @@ interpretations: jsonschema: { boolTags: { strict: *false | bool strictKeywords: *strict | bool - strictFeatures: *true | bool + // TODO(v0.12): enable strictFeatures by default + strictFeatures: *strict | bool } } @@ -307,7 +308,7 @@ interpretations: openapi: { boolTags: { strict: *false | bool strictKeywords: *strict | bool - strictFeatures: *true | bool + strictFeatures: *strict | bool } }