| 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": [], |
| 34 | "valid": true |
| 35 | }, |
| 36 | { |
| 37 | "description": "ignores strings", |
| 38 | "data": "", |
| 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 | ] |