1[ 2 { 3 "description": "issue386", 4 "schema": { 5 "$schema": "http://json-schema.org/draft-07/schema#", 6 "$id": "https://example.com/issue386.json", 7 "type": "object", 8 "properties": { 9 "street_address": { 10 "type": "string" 11 }, 12 "country": { 13 "default": "United States of America", 14 "enum": [ 15 "United States of America", 16 "Canada", 17 "Netherlands" 18 ] 19 } 20 }, 21 "allOf": [ 22 { 23 "if": { 24 "properties": { 25 "country": { 26 "const": "United States of America" 27 } 28 } 29 }, 30 "then": { 31 "properties": { 32 "postal_code": { 33 "pattern": "[0-9]{5}(-[0-9]{4})?" 34 } 35 } 36 } 37 }, 38 { 39 "if": { 40 "properties": { 41 "country": { 42 "const": "Canada" 43 } 44 }, 45 "required": [ 46 "country" 47 ] 48 }, 49 "then": { 50 "properties": { 51 "postal_code": { 52 "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" 53 } 54 } 55 } 56 }, 57 { 58 "if": { 59 "properties": { 60 "country": { 61 "const": "Netherlands" 62 } 63 }, 64 "required": [ 65 "country" 66 ] 67 }, 68 "then": { 69 "properties": { 70 "postal_code": { 71 "pattern": "[0-9]{4} [A-Z]{2}" 72 } 73 } 74 } 75 } 76 ] 77 }, 78 "tests": [ 79 { 80 "data": { 81 "street_address": "1600 Pennsylvania Avenue NW", 82 "country": "United States of America", 83 "postal_code": "20500" 84 }, 85 "valid": true 86 }, 87 { 88 "data": { 89 "street_address": "1600 Pennsylvania Avenue NW", 90 "postal_code": "20500" 91 }, 92 "valid": true 93 }, 94 { 95 "data": { 96 "street_address": "24 Sussex Drive", 97 "country": "Canada", 98 "postal_code": "K1M 1M4" 99 }, 100 "valid": true 101 }, 102 { 103 "data": { 104 "street_address": "Adriaan Goekooplaan", 105 "country": "Netherlands", 106 "postal_code": "2517 JX" 107 }, 108 "valid": true 109 }, 110 { 111 "data": { 112 "street_address": "24 Sussex Drive", 113 "country": "Canada", 114 "postal_code": "10000" 115 }, 116 "valid": false, 117 "expectedErrors": [ 118 "$.postal_code: does not match the regex pattern [A-Z][0-9][A-Z] [0-9][A-Z][0-9]" 119 ] 120 }, 121 { 122 "description": "invalid through first then", 123 "data": { 124 "street_address": "1600 Pennsylvania Avenue NW", 125 "postal_code": "K1M 1M4" 126 }, 127 "valid": false, 128 "expectedErrors": [ 129 "$.postal_code: does not match the regex pattern [0-9]{5}(-[0-9]{4})?" 130 ] 131 } 132 ] 133 } 134]