-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
encoding/jsonschema: allow impossible subschemas
Some real-world schemas contain self-contradictory elements, despite being useful in practice. We change `encoding/jsonschema` so that it's not necessarily an error to have a self-contradictory schema as long as the top level schema itself is not self-contradictory. This allows us to generate CUE for more real-world schemas, such as this one: https://github.com/SchemaStore/schemastore/blob/c084075dbfa7eb7da2c4c81456d04543b7be5744/src/schemas/json/stylelintrc.json#L173 We might add functionality to enable stricter vetting of such schemas in the future, but for now, schema linting is not what we're aiming for. Fixes #3455 Signed-off-by: Roger Peppe <[email protected]> Change-Id: I60f5b56b7afd59d9e42ca93906f6f335b4500a39 Dispatch-Trailer: {"type":"trybot","CL":1201396,"patchset":4,"ref":"refs/changes/96/1201396/4","targetBranch":"master"}
- Loading branch information
Showing
9 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
encoding/jsonschema/testdata/txtar/anyof_with_one_possible.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- schema.json -- | ||
{ | ||
"anyOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
1, | ||
2 | ||
] | ||
}, | ||
{ | ||
"type": "boolean" | ||
} | ||
] | ||
} | ||
-- out/decode/extract -- | ||
bool |
20 changes: 20 additions & 0 deletions
20
encoding/jsonschema/testdata/txtar/anyofof_with_impossible_elements.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- schema.json -- | ||
{ | ||
"anyOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
1, | ||
2 | ||
] | ||
}, | ||
{ | ||
"type": "boolean" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
] | ||
} | ||
-- out/decode/extract -- | ||
matchN(>=1, [bool, number]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
encoding/jsonschema/testdata/txtar/oneof_with_one_possible.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- schema.json -- | ||
{ | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
1, | ||
2 | ||
] | ||
}, | ||
{ | ||
"type": "boolean" | ||
} | ||
] | ||
} | ||
-- out/decode/extract -- | ||
bool |