-
Notifications
You must be signed in to change notification settings - Fork 294
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 test cases for excluded types
The jsonschema logic currently produces "constraint not allowed because type is excluded" errors. Although such errors do often represent a mistake on the part of the author of the schema, they are not technically errors. A classic example might be the following: { "enum": ["a", "b"], "type": ["string", "null"] } Even though we know that the only values possible are `"a"` and `"b"` so the `null` type constraints is redundant, it's OK to include it, and it's common to see this kind of thing in schemas in the wild. The test cases were all taken from real-life schemas. For #393. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I59f46f5f2002ed21e822731d0bce294399f2d892 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199397 Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information
Showing
2 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,128 @@ | ||
-- type.json -- | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"e0": { | ||
"type": [ | ||
"integer" | ||
], | ||
"minimum": 2, | ||
"maximum": 3, | ||
"maxLength": 5 | ||
}, | ||
"e1": { | ||
"enum": [ | ||
"cover", | ||
"contain" | ||
], | ||
"type": [ | ||
"array", | ||
"boolean", | ||
"number", | ||
"object", | ||
"string", | ||
"null" | ||
] | ||
}, | ||
"e2": { | ||
"title": "none", | ||
"type": "string", | ||
"enum": [ | ||
"none" | ||
], | ||
"required": [ | ||
"none" | ||
] | ||
}, | ||
"e3": { | ||
"type": "array", | ||
"uniqueItems": true, | ||
"minItems": 1, | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"minLength": 1 | ||
}, | ||
"e4": { | ||
"type": "array", | ||
"description": "Main authors of the plugin", | ||
"items": { | ||
"type": "string", | ||
"uniqueItems": true | ||
} | ||
}, | ||
"e5": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"e6": { | ||
"items": { | ||
"type": "string", | ||
"pattern": "^[A-Za-z0-9 _.-]+$" | ||
}, | ||
"type": "array", | ||
"pattern": "^[A-Za-z0-9 _.-]+$" | ||
}, | ||
"e7": { | ||
"type": [ | ||
"boolean", | ||
"object" | ||
], | ||
"anyOf": [ | ||
{ | ||
"type": "boolean", | ||
"enum": [ | ||
true, | ||
{} | ||
] | ||
}, | ||
{ | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"properties": { | ||
"disableFix": { | ||
"type": "boolean" | ||
} | ||
} | ||
} | ||
], | ||
"properties": { | ||
"ignoreMediaFeatureNames": { | ||
"type": "array", | ||
"minItems": 1, | ||
"uniqueItems": true, | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
-- out/decode/err -- | ||
constraint not allowed because type string is excluded: | ||
type.json:10:7 | ||
constraint not allowed because type array is excluded: | ||
type.json:18:9 | ||
constraint not allowed because type bool is excluded: | ||
type.json:19:9 | ||
constraint not allowed because type number is excluded: | ||
type.json:20:9 | ||
constraint not allowed because type object is excluded: | ||
type.json:21:9 | ||
constraint not allowed because type null is excluded: | ||
type.json:23:9 | ||
constraint not allowed because type object is excluded: | ||
type.json:32:7 | ||
constraint not allowed because type string is excluded: | ||
type.json:44:7 | ||
constraint not allowed because type array is excluded: | ||
type.json:51:9 | ||
constraint not allowed because type string is excluded: | ||
type.json:64:7 | ||
constraint not allowed because type bool is excluded: | ||
type.json:68:9 |