this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <rogpeppe@gmail.com>
Change-Id: I59f46f5f2002ed21e822731d0bce294399f2d892
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199397
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+128 -20
-20
encoding/jsonschema/testdata/err.txtar
··· 1 - -- type.json -- 2 - { 3 - "type": "object", 4 - 5 - "properties": { 6 - "multi": { 7 - "type": [ "integer" ], 8 - "minimum": 2, 9 - "maximum": 3, 10 - "maxLength": 5 11 - } 12 - }, 13 - "additionalProperties": false 14 - } 15 - 16 - -- out/decode/err -- 17 - constraint not allowed because type string is excluded: 18 - type.json:9:9 19 - -- out/decode/cue -- 20 - multi?: int & >=2 & <=3
+128
encoding/jsonschema/testdata/typeexcluded.txtar
··· 1 + -- type.json -- 2 + { 3 + "type": "object", 4 + "properties": { 5 + "e0": { 6 + "type": [ 7 + "integer" 8 + ], 9 + "minimum": 2, 10 + "maximum": 3, 11 + "maxLength": 5 12 + }, 13 + "e1": { 14 + "enum": [ 15 + "cover", 16 + "contain" 17 + ], 18 + "type": [ 19 + "array", 20 + "boolean", 21 + "number", 22 + "object", 23 + "string", 24 + "null" 25 + ] 26 + }, 27 + "e2": { 28 + "title": "none", 29 + "type": "string", 30 + "enum": [ 31 + "none" 32 + ], 33 + "required": [ 34 + "none" 35 + ] 36 + }, 37 + "e3": { 38 + "type": "array", 39 + "uniqueItems": true, 40 + "minItems": 1, 41 + "items": { 42 + "type": "string", 43 + "minLength": 1 44 + }, 45 + "minLength": 1 46 + }, 47 + "e4": { 48 + "type": "array", 49 + "description": "Main authors of the plugin", 50 + "items": { 51 + "type": "string", 52 + "uniqueItems": true 53 + } 54 + }, 55 + "e5": { 56 + "type": "integer", 57 + "minimum": 0 58 + }, 59 + "e6": { 60 + "items": { 61 + "type": "string", 62 + "pattern": "^[A-Za-z0-9 _.-]+$" 63 + }, 64 + "type": "array", 65 + "pattern": "^[A-Za-z0-9 _.-]+$" 66 + }, 67 + "e7": { 68 + "type": [ 69 + "boolean", 70 + "object" 71 + ], 72 + "anyOf": [ 73 + { 74 + "type": "boolean", 75 + "enum": [ 76 + true, 77 + {} 78 + ] 79 + }, 80 + { 81 + "type": "object", 82 + "allOf": [ 83 + { 84 + "properties": { 85 + "disableFix": { 86 + "type": "boolean" 87 + } 88 + } 89 + } 90 + ], 91 + "properties": { 92 + "ignoreMediaFeatureNames": { 93 + "type": "array", 94 + "minItems": 1, 95 + "uniqueItems": true, 96 + "items": { 97 + "type": "string" 98 + } 99 + } 100 + } 101 + } 102 + ] 103 + } 104 + } 105 + } 106 + -- out/decode/err -- 107 + constraint not allowed because type string is excluded: 108 + type.json:10:7 109 + constraint not allowed because type array is excluded: 110 + type.json:18:9 111 + constraint not allowed because type bool is excluded: 112 + type.json:19:9 113 + constraint not allowed because type number is excluded: 114 + type.json:20:9 115 + constraint not allowed because type object is excluded: 116 + type.json:21:9 117 + constraint not allowed because type null is excluded: 118 + type.json:23:9 119 + constraint not allowed because type object is excluded: 120 + type.json:32:7 121 + constraint not allowed because type string is excluded: 122 + type.json:44:7 123 + constraint not allowed because type array is excluded: 124 + type.json:51:9 125 + constraint not allowed because type string is excluded: 126 + type.json:64:7 127 + constraint not allowed because type bool is excluded: 128 + type.json:68:9