1[ 2 { 3 "description": "oneOf", 4 "schema": { 5 "oneOf": [ 6 { 7 "type": "integer" 8 }, 9 { 10 "minimum": 2 11 } 12 ] 13 }, 14 "tests": [ 15 { 16 "description": "first oneOf valid", 17 "data": 1, 18 "valid": true 19 }, 20 { 21 "description": "second oneOf valid", 22 "data": 2.5, 23 "valid": true 24 }, 25 { 26 "description": "both oneOf valid", 27 "data": 3, 28 "valid": false 29 }, 30 { 31 "description": "neither oneOf valid", 32 "data": 1.5, 33 "valid": false 34 } 35 ] 36 }, 37 { 38 "description": "oneOf with base schema", 39 "schema": { 40 "type": "string", 41 "oneOf" : [ 42 { 43 "minLength": 2 44 }, 45 { 46 "maxLength": 4 47 } 48 ] 49 }, 50 "tests": [ 51 { 52 "description": "mismatch base schema", 53 "data": 3, 54 "valid": false 55 }, 56 { 57 "description": "one oneOf valid", 58 "data": "foobar", 59 "valid": true 60 }, 61 { 62 "description": "both oneOf valid", 63 "data": "foo", 64 "valid": false 65 } 66 ] 67 }, 68 { 69 "description": "oneOf complex types", 70 "schema": { 71 "oneOf": [ 72 { 73 "properties": { 74 "bar": {"type": "integer"} 75 }, 76 "required": ["bar"] 77 }, 78 { 79 "properties": { 80 "foo": {"type": "string"} 81 }, 82 "required": ["foo"] 83 } 84 ] 85 }, 86 "tests": [ 87 { 88 "description": "first oneOf valid (complex)", 89 "data": {"bar": 2}, 90 "valid": true 91 }, 92 { 93 "description": "second oneOf valid (complex)", 94 "data": {"foo": "baz"}, 95 "valid": true 96 }, 97 { 98 "description": "both oneOf valid (complex)", 99 "data": {"foo": "baz", "bar": 2}, 100 "valid": false 101 }, 102 { 103 "description": "neither oneOf valid (complex)", 104 "data": {"foo": 2, "bar": "quux"}, 105 "valid": false 106 } 107 ] 108 }, 109 { 110 "description": "oneOf with empty schema", 111 "schema": { 112 "oneOf": [ 113 { "type": "number" }, 114 {} 115 ] 116 }, 117 "tests": [ 118 { 119 "description": "one valid - valid", 120 "data": "foo", 121 "valid": true 122 }, 123 { 124 "description": "both valid - invalid", 125 "data": 123, 126 "valid": false 127 } 128 ] 129 }, 130 { 131 "description": "oneOf with required", 132 "schema": { 133 "type": "object", 134 "oneOf": [ 135 { "required": ["foo", "bar"] }, 136 { "required": ["foo", "baz"] } 137 ] 138 }, 139 "tests": [ 140 { 141 "description": "both invalid - invalid", 142 "data": {"bar": 2}, 143 "valid": false 144 }, 145 { 146 "description": "first valid - valid", 147 "data": {"foo": 1, "bar": 2}, 148 "valid": true 149 }, 150 { 151 "description": "second valid - valid", 152 "data": {"foo": 1, "baz": 3}, 153 "valid": true 154 }, 155 { 156 "description": "both valid - invalid", 157 "data": {"foo": 1, "bar": 2, "baz" : 3}, 158 "valid": false 159 } 160 ] 161 }, 162 { 163 "description": "oneOf with missing optional property", 164 "schema": { 165 "oneOf": [ 166 { 167 "properties": { 168 "bar": {}, 169 "baz": {} 170 }, 171 "required": ["bar"] 172 }, 173 { 174 "properties": { 175 "foo": {} 176 }, 177 "required": ["foo"] 178 } 179 ] 180 }, 181 "tests": [ 182 { 183 "description": "first oneOf valid", 184 "data": {"bar": 8}, 185 "valid": true 186 }, 187 { 188 "description": "second oneOf valid", 189 "data": {"foo": "foo"}, 190 "valid": true 191 }, 192 { 193 "description": "both oneOf valid", 194 "data": {"foo": "foo", "bar": 8}, 195 "valid": false 196 }, 197 { 198 "description": "neither oneOf valid", 199 "data": {"baz": "quux"}, 200 "valid": false 201 } 202 ] 203 }, 204 { 205 "description": "nested oneOf, to check validation semantics", 206 "schema": { 207 "oneOf": [ 208 { 209 "oneOf": [ 210 { 211 "type": "null" 212 } 213 ] 214 } 215 ] 216 }, 217 "tests": [ 218 { 219 "description": "null is valid", 220 "data": null, 221 "valid": true 222 }, 223 { 224 "description": "anything non-null is invalid", 225 "data": 123, 226 "valid": false 227 } 228 ] 229 } 230] 231