1[ 2 { 3 "description": 4 "patternProperties validates properties matching a regex", 5 "schema": { 6 "patternProperties": { 7 "f.*o": {"type": "integer"} 8 } 9 }, 10 "tests": [ 11 { 12 "description": "a single valid match is valid", 13 "data": {"foo": 1}, 14 "valid": true 15 }, 16 { 17 "description": "multiple valid matches is valid", 18 "data": {"foo": 1, "foooooo" : 2}, 19 "valid": true 20 }, 21 { 22 "description": "a single invalid match is invalid", 23 "data": {"foo": "bar", "fooooo": 2}, 24 "valid": false 25 }, 26 { 27 "description": "multiple invalid matches is invalid", 28 "data": {"foo": "bar", "foooooo" : "baz"}, 29 "valid": false 30 }, 31 { 32 "description": "ignores arrays", 33 "data": ["foo"], 34 "valid": true 35 }, 36 { 37 "description": "ignores strings", 38 "data": "foo", 39 "valid": true 40 }, 41 { 42 "description": "ignores other non-objects", 43 "data": 12, 44 "valid": true 45 } 46 ] 47 }, 48 { 49 "description": "multiple simultaneous patternProperties are validated", 50 "schema": { 51 "patternProperties": { 52 "a*": {"type": "integer"}, 53 "aaa*": {"maximum": 20} 54 } 55 }, 56 "tests": [ 57 { 58 "description": "a single valid match is valid", 59 "data": {"a": 21}, 60 "valid": true 61 }, 62 { 63 "description": "a simultaneous match is valid", 64 "data": {"aaaa": 18}, 65 "valid": true 66 }, 67 { 68 "description": "multiple matches is valid", 69 "data": {"a": 21, "aaaa": 18}, 70 "valid": true 71 }, 72 { 73 "description": "an invalid due to one is invalid", 74 "data": {"a": "bar"}, 75 "valid": false 76 }, 77 { 78 "description": "an invalid due to the other is invalid", 79 "data": {"aaaa": 31}, 80 "valid": false 81 }, 82 { 83 "description": "an invalid due to both is invalid", 84 "data": {"aaa": "foo", "aaaa": 31}, 85 "valid": false 86 } 87 ] 88 }, 89 { 90 "description": "regexes are not anchored by default and are case sensitive", 91 "schema": { 92 "patternProperties": { 93 "[0-9]{2,}": { "type": "boolean" }, 94 "X_": { "type": "string" } 95 } 96 }, 97 "tests": [ 98 { 99 "description": "non recognized members are ignored", 100 "data": { "answer 1": "42" }, 101 "valid": true 102 }, 103 { 104 "description": "recognized members are accounted for", 105 "data": { "a31b": null }, 106 "valid": false 107 }, 108 { 109 "description": "regexes are case sensitive", 110 "data": { "a_x_3": 3 }, 111 "valid": true 112 }, 113 { 114 "description": "regexes are case sensitive, 2", 115 "data": { "a_X_3": 3 }, 116 "valid": false 117 } 118 ] 119 }, 120 { 121 "description": "patternProperties with boolean schemas", 122 "schema": { 123 "patternProperties": { 124 "f.*": true, 125 "b.*": false 126 } 127 }, 128 "tests": [ 129 { 130 "description": "object with property matching schema true is valid", 131 "data": {"foo": 1}, 132 "valid": true 133 }, 134 { 135 "description": "object with property matching schema false is invalid", 136 "data": {"bar": 2}, 137 "valid": false 138 }, 139 { 140 "description": "object with both properties is invalid", 141 "data": {"foo": 1, "bar": 2}, 142 "valid": false 143 }, 144 { 145 "description": "object with a property matching both true and false is invalid", 146 "data": {"foobar":1}, 147 "valid": false 148 }, 149 { 150 "description": "empty object is valid", 151 "data": {}, 152 "valid": true 153 } 154 ] 155 }, 156 { 157 "description": "patternProperties with null valued instance properties", 158 "schema": { 159 "patternProperties": { 160 "^.*bar$": {"type": "null"} 161 } 162 }, 163 "tests": [ 164 { 165 "description": "allows null values", 166 "data": {"foobar": null}, 167 "valid": true 168 } 169 ] 170 } 171] 172