-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
encoding/jsonschema: add Config.AllowNonExistentRoot
`AllowNonExistentRoot` prevents an error when there is no value at the above Root path. Such an error can be useful to signal that the data may not be a JSON Schema, but is not always a good idea. When extracting CUE from OpenAPI documents, they are not required to contain a .components.schemas member but in the usual case of using the command line, it's probably an error if there is no such member (because it might mean that we're not using the right kind of file at all, and we're probably expecting some schemas to be present otherwise we wouldn't be invoking the cue command to extract schemas). However, in some cases, we don't want to consider it an error, so add an option to cause us to ignore a missing root. Another possibility might be to change jsonschema.Extract to return a custom error type/value, but this means that it would be harder to change the cue command to import openapi files even as CUE even when there are no definitions. Also in passing fix an error message that was not including the error that it was about. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ib9d6ef9be834a869000762bff9bc9cd4bc9bd115 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207007 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
- Loading branch information
Showing
5 changed files
with
29 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Test what happens when there's an OpenAPI schema that has no | ||
/components/schemas entry but AllowNonExistentRoot is true | ||
|
||
#allowNonExistentRoot | ||
#version: openapi | ||
|
||
-- schema.yaml -- | ||
-- out/decode/extract -- | ||
|
9 changes: 9 additions & 0 deletions
9
encoding/jsonschema/testdata/txtar/openapi_nonexistent_error.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,9 @@ | ||
Test what happens when there's an OpenAPI schema that has no | ||
/components/schemas entry and AllowNonExistentRoot is false | ||
|
||
#version: openapi | ||
|
||
-- schema.yaml -- | ||
-- out/decode/extract -- | ||
ERROR: | ||
value at path #/components/schemas/ must be struct containing definitions but is actually _|_ // field not found: components |