Skip to content

Commit 15fbf7f

Browse files
committed
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 <[email protected]> Change-Id: I65d24ae8c147d36499b4e02b418bedcc6d1a376b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200932 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 2f82fb4 commit 15fbf7f

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

Diff for: cmd/cue/cmd/help.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,15 @@ The following tags are only valid in combination with other tags,
613613
and influence the functioning of the codec. The tag they are
614614
valid with is mentioned in parentheses at the end.
615615
616-
strictFeatures report errors for lossy mappings (jsonschema)
616+
strictFeatures report errors for lossy mappings. Enabled by default (jsonschema)
617617
strictKeywords report errors for unknown keywords (jsonschema)
618618
strict report errors for either of the above (jsonschema)
619619
620620
The above flags also accept a boolean flag value (e.g. true, 1, false, 0)
621-
to set them explicitly. For example:
621+
to set them explicitly. For example, to ignore unimplemented JSON Schema
622+
features rather than giving an error:
622623
623-
jsonschema+strictKeywords=0+strictFeatures=1
624+
jsonschema+strictFeatures=0
624625
625626
Many commands also support the --out and --outfile/-o flags.
626627
The --out flag specifies the output type using a qualifier

Diff for: cmd/cue/cmd/testdata/script/def_jsonschema.txtar

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ cmp stdout expect-stdout
55
exec cue def schema.json -p schema -l '#Person:'
66
cmp stdout expect-stdout
77

8-
exec cue def jsonschema: bad.json
8+
! exec cue def jsonschema: bad.json
9+
cmp stderr expect-stderr-strict-features
10+
11+
exec cue def jsonschema+strictFeatures=0: bad.json
912

1013
! exec cue def jsonschema: bad.json --strict
1114
cmp stderr expect-stderr

Diff for: internal/filetypes/filetypes_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestFromFile(t *testing.T) {
181181
Form: build.Schema,
182182
BoolTags: map[string]bool{
183183
"strict": false,
184-
"strictFeatures": false,
184+
"strictFeatures": true,
185185
"strictKeywords": false,
186186
},
187187
},
@@ -419,7 +419,7 @@ func TestParseArgs(t *testing.T) {
419419
Interpretation: "jsonschema",
420420
BoolTags: map[string]bool{
421421
"strict": false,
422-
"strictFeatures": false,
422+
"strictFeatures": true,
423423
"strictKeywords": false,
424424
},
425425
},
@@ -439,6 +439,21 @@ func TestParseArgs(t *testing.T) {
439439
},
440440
},
441441
},
442+
}, {
443+
in: "jsonschema+strictFeatures=0: bar.schema",
444+
out: []*build.File{
445+
{
446+
Filename: "bar.schema",
447+
Encoding: "json",
448+
Interpretation: "jsonschema",
449+
Form: build.Schema,
450+
BoolTags: map[string]bool{
451+
"strict": false,
452+
"strictFeatures": false,
453+
"strictKeywords": false,
454+
},
455+
},
456+
},
442457
}, {
443458
in: `json: c:\foo.json c:\path\to\file.dat`,
444459
out: []*build.File{

Diff for: internal/filetypes/types.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ interpretations: jsonschema: {
297297
boolTags: {
298298
strict: *false | bool
299299
strictKeywords: *strict | bool
300-
strictFeatures: *strict | bool
300+
strictFeatures: *true | bool
301301
}
302302
}
303303

0 commit comments

Comments
 (0)