Skip to content

Commit

Permalink
internal/filetypes: default strictFeatures to true
Browse files Browse the repository at this point in the history
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
Dispatch-Trailer: {"type":"trybot","CL":1200932,"patchset":1,"ref":"refs/changes/32/1200932/1","targetBranch":"master"}
  • Loading branch information
rogpeppe authored and cueckoo committed Sep 10, 2024
1 parent 382e6c5 commit fcb1f30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/cue/cmd/testdata/script/def_jsonschema.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions internal/filetypes/filetypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestFromFile(t *testing.T) {
Form: build.Schema,
BoolTags: map[string]bool{
"strict": false,
"strictFeatures": false,
"strictFeatures": true,
"strictKeywords": false,
},
},
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestParseArgs(t *testing.T) {
Interpretation: "jsonschema",
BoolTags: map[string]bool{
"strict": false,
"strictFeatures": false,
"strictFeatures": true,
"strictKeywords": false,
},
},
Expand All @@ -438,6 +438,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{
Expand Down
2 changes: 1 addition & 1 deletion internal/filetypes/types.cue
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ interpretations: jsonschema: {
boolTags: {
strict: *false | bool
strictKeywords: *strict | bool
strictFeatures: *strict | bool
strictFeatures: *true | bool
}
}

Expand Down

0 comments on commit fcb1f30

Please sign in to comment.