|
184 | 184 | "valid": true
|
185 | 185 | }
|
186 | 186 | ]
|
| 187 | + }, |
| 188 | + { |
| 189 | + "description": "conditions by properties", |
| 190 | + "schema": { |
| 191 | + "type": "object", |
| 192 | + "properties": { |
| 193 | + "street_address": { |
| 194 | + "type": "string" |
| 195 | + }, |
| 196 | + "country": { |
| 197 | + "enum": ["United States of America", "Canada"] |
| 198 | + } |
| 199 | + }, |
| 200 | + "if": { |
| 201 | + "properties": { |
| 202 | + "country": { |
| 203 | + "const": "United States of America" |
| 204 | + } |
| 205 | + } |
| 206 | + }, |
| 207 | + "then": { |
| 208 | + "properties": { |
| 209 | + "postal_code": { |
| 210 | + "pattern": "[0-9]{5}(-[0-9]{4})?" |
| 211 | + } |
| 212 | + } |
| 213 | + }, |
| 214 | + "else": { |
| 215 | + "properties": { |
| 216 | + "postal_code": { |
| 217 | + "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" |
| 218 | + } |
| 219 | + } |
| 220 | + } |
| 221 | + }, |
| 222 | + "tests": [ |
| 223 | + { |
| 224 | + "description": "valid through then", |
| 225 | + "data": { |
| 226 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 227 | + "country": "United States of America", |
| 228 | + "postal_code": "20500" |
| 229 | + }, |
| 230 | + "valid": true |
| 231 | + }, |
| 232 | + { |
| 233 | + "description": "valid through then, alternative match", |
| 234 | + "data": { |
| 235 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 236 | + "postal_code": "20500" |
| 237 | + }, |
| 238 | + "valid": true |
| 239 | + }, |
| 240 | + { |
| 241 | + "description": "valid through else", |
| 242 | + "data": { |
| 243 | + "street_address": "24 Sussex Drive", |
| 244 | + "country": "Canada", |
| 245 | + "postal_code": "K1M 1M4" |
| 246 | + }, |
| 247 | + "valid": true |
| 248 | + }, |
| 249 | + { |
| 250 | + "description": "invalid through else", |
| 251 | + "data": { |
| 252 | + "street_address": "24 Sussex Drive", |
| 253 | + "country": "Canada", |
| 254 | + "postal_code": "10000" |
| 255 | + }, |
| 256 | + "valid": false |
| 257 | + } |
| 258 | + , |
| 259 | + { |
| 260 | + "description": "invalid through then", |
| 261 | + "data": { |
| 262 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 263 | + "postal_code": "K1M 1M4" |
| 264 | + }, |
| 265 | + "valid": false |
| 266 | + } |
| 267 | + ] |
| 268 | + }, |
| 269 | + { |
| 270 | + "description": "conditions by allOf properties", |
| 271 | + "schema": { |
| 272 | + "type": "object", |
| 273 | + "properties": { |
| 274 | + "street_address": { |
| 275 | + "type": "string" |
| 276 | + }, |
| 277 | + "country": { |
| 278 | + "default": "United States of America", |
| 279 | + "enum": ["United States of America", "Canada", "Netherlands"] |
| 280 | + } |
| 281 | + }, |
| 282 | + "allOf": [ |
| 283 | + { |
| 284 | + "if": { |
| 285 | + "properties": { "country": { "const": "United States of America" } } |
| 286 | + }, |
| 287 | + "then": { |
| 288 | + "properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } } |
| 289 | + } |
| 290 | + }, |
| 291 | + { |
| 292 | + "if": { |
| 293 | + "properties": { "country": { "const": "Canada" } }, |
| 294 | + "required": ["country"] |
| 295 | + }, |
| 296 | + "then": { |
| 297 | + "properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } } |
| 298 | + } |
| 299 | + }, |
| 300 | + { |
| 301 | + "if": { |
| 302 | + "properties": { "country": { "const": "Netherlands" } }, |
| 303 | + "required": ["country"] |
| 304 | + }, |
| 305 | + "then": { |
| 306 | + "properties": { "postal_code": { "pattern": "[0-9]{4} [A-Z]{2}" } } |
| 307 | + } |
| 308 | + } |
| 309 | + ] |
| 310 | + }, |
| 311 | + "tests": [ |
| 312 | + { |
| 313 | + "description": "valid first if", |
| 314 | + "data": { |
| 315 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 316 | + "country": "United States of America", |
| 317 | + "postal_code": "20500" |
| 318 | + }, |
| 319 | + "valid": true |
| 320 | + }, |
| 321 | + { |
| 322 | + "description": "valid first if, alternative match", |
| 323 | + "data": { |
| 324 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 325 | + "postal_code": "20500" |
| 326 | + }, |
| 327 | + "valid": true |
| 328 | + }, |
| 329 | + { |
| 330 | + "description": "valid second if", |
| 331 | + "data": { |
| 332 | + "street_address": "24 Sussex Drive", |
| 333 | + "country": "Canada", |
| 334 | + "postal_code": "K1M 1M4" |
| 335 | + }, |
| 336 | + "valid": true |
| 337 | + }, |
| 338 | + { |
| 339 | + "description": "valid third if", |
| 340 | + "data": { |
| 341 | + "street_address": "Adriaan Goekooplaan", |
| 342 | + "country": "Netherlands", |
| 343 | + "postal_code": "2517 JX" |
| 344 | + }, |
| 345 | + "valid": true |
| 346 | + }, |
| 347 | + { |
| 348 | + "description": "invalid through second then", |
| 349 | + "data": { |
| 350 | + "street_address": "24 Sussex Drive", |
| 351 | + "country": "Canada", |
| 352 | + "postal_code": "10000" |
| 353 | + }, |
| 354 | + "valid": false |
| 355 | + }, |
| 356 | + { |
| 357 | + "description": "invalid through first then", |
| 358 | + "data": { |
| 359 | + "street_address": "1600 Pennsylvania Avenue NW", |
| 360 | + "postal_code": "K1M 1M4" |
| 361 | + }, |
| 362 | + "valid": false |
| 363 | + } |
| 364 | + ] |
187 | 365 | }
|
188 | 366 | ]
|
0 commit comments