1[ 2 { 3 "description": "const validation", 4 "schema": {"const": 2}, 5 "tests": [ 6 { 7 "description": "same value is valid", 8 "data": 2, 9 "valid": true 10 }, 11 { 12 "description": "another value is invalid", 13 "data": 5, 14 "valid": false 15 }, 16 { 17 "description": "another type is invalid", 18 "data": "a", 19 "valid": false 20 } 21 ] 22 }, 23 { 24 "description": "const with object", 25 "schema": {"const": {"foo": "bar", "baz": "bax"}}, 26 "tests": [ 27 { 28 "description": "same object is valid", 29 "data": {"foo": "bar", "baz": "bax"}, 30 "valid": true 31 }, 32 { 33 "description": "same object with different property order is valid", 34 "data": {"baz": "bax", "foo": "bar"}, 35 "valid": true 36 }, 37 { 38 "description": "another object is invalid", 39 "data": {"foo": "bar"}, 40 "valid": false 41 }, 42 { 43 "description": "another type is invalid", 44 "data": [1, 2], 45 "valid": false 46 } 47 ] 48 }, 49 { 50 "description": "const with array", 51 "schema": {"const": [{ "foo": "bar" }]}, 52 "tests": [ 53 { 54 "description": "same array is valid", 55 "data": [{"foo": "bar"}], 56 "valid": true 57 }, 58 { 59 "description": "another array item is invalid", 60 "data": [2], 61 "valid": false 62 }, 63 { 64 "description": "array with additional items is invalid", 65 "data": [1, 2, 3], 66 "valid": false 67 } 68 ] 69 }, 70 { 71 "description": "const with null", 72 "schema": {"const": null}, 73 "tests": [ 74 { 75 "description": "null is valid", 76 "data": null, 77 "valid": true 78 }, 79 { 80 "description": "not null is invalid", 81 "data": 0, 82 "valid": false 83 } 84 ] 85 }, 86 { 87 "description": "const with false does not match 0", 88 "schema": {"const": false}, 89 "tests": [ 90 { 91 "description": "false is valid", 92 "data": false, 93 "valid": true 94 }, 95 { 96 "description": "integer zero is invalid", 97 "data": 0, 98 "valid": false 99 }, 100 { 101 "description": "float zero is invalid", 102 "data": 0.0, 103 "valid": false 104 } 105 ] 106 }, 107 { 108 "description": "const with true does not match 1", 109 "schema": {"const": true}, 110 "tests": [ 111 { 112 "description": "true is valid", 113 "data": true, 114 "valid": true 115 }, 116 { 117 "description": "integer one is invalid", 118 "data": 1, 119 "valid": false 120 }, 121 { 122 "description": "float one is invalid", 123 "data": 1.0, 124 "valid": false 125 } 126 ] 127 }, 128 { 129 "description": "const with [false] does not match [0]", 130 "schema": {"const": [false]}, 131 "tests": [ 132 { 133 "description": "[false] is valid", 134 "data": [false], 135 "valid": true 136 }, 137 { 138 "description": "[0] is invalid", 139 "data": [0], 140 "valid": false 141 }, 142 { 143 "description": "[0.0] is invalid", 144 "data": [0.0], 145 "valid": false 146 } 147 ] 148 }, 149 { 150 "description": "const with [true] does not match [1]", 151 "schema": {"const": [true]}, 152 "tests": [ 153 { 154 "description": "[true] is valid", 155 "data": [true], 156 "valid": true 157 }, 158 { 159 "description": "[1] is invalid", 160 "data": [1], 161 "valid": false 162 }, 163 { 164 "description": "[1.0] is invalid", 165 "data": [1.0], 166 "valid": false 167 } 168 ] 169 }, 170 { 171 "description": "const with {\"a\": false} does not match {\"a\": 0}", 172 "schema": {"const": {"a": false}}, 173 "tests": [ 174 { 175 "description": "{\"a\": false} is valid", 176 "data": {"a": false}, 177 "valid": true 178 }, 179 { 180 "description": "{\"a\": 0} is invalid", 181 "data": {"a": 0}, 182 "valid": false 183 }, 184 { 185 "description": "{\"a\": 0.0} is invalid", 186 "data": {"a": 0.0}, 187 "valid": false 188 } 189 ] 190 }, 191 { 192 "description": "const with {\"a\": true} does not match {\"a\": 1}", 193 "schema": {"const": {"a": true}}, 194 "tests": [ 195 { 196 "description": "{\"a\": true} is valid", 197 "data": {"a": true}, 198 "valid": true 199 }, 200 { 201 "description": "{\"a\": 1} is invalid", 202 "data": {"a": 1}, 203 "valid": false 204 }, 205 { 206 "description": "{\"a\": 1.0} is invalid", 207 "data": {"a": 1.0}, 208 "valid": false 209 } 210 ] 211 }, 212 { 213 "description": "const with 0 does not match other zero-like types", 214 "schema": {"const": 0}, 215 "tests": [ 216 { 217 "description": "false is invalid", 218 "data": false, 219 "valid": false 220 }, 221 { 222 "description": "integer zero is valid", 223 "data": 0, 224 "valid": true 225 }, 226 { 227 "description": "float zero is valid", 228 "data": 0.0, 229 "valid": true 230 }, 231 { 232 "description": "empty object is invalid", 233 "data": {}, 234 "valid": false 235 }, 236 { 237 "description": "empty array is invalid", 238 "data": [], 239 "valid": false 240 }, 241 { 242 "description": "empty string is invalid", 243 "data": "", 244 "valid": false 245 } 246 ] 247 }, 248 { 249 "description": "const with 1 does not match true", 250 "schema": {"const": 1}, 251 "tests": [ 252 { 253 "description": "true is invalid", 254 "data": true, 255 "valid": false 256 }, 257 { 258 "description": "integer one is valid", 259 "data": 1, 260 "valid": true 261 }, 262 { 263 "description": "float one is valid", 264 "data": 1.0, 265 "valid": true 266 } 267 ] 268 }, 269 { 270 "description": "const with -2.0 matches integer and float types", 271 "schema": {"const": -2.0}, 272 "tests": [ 273 { 274 "description": "integer -2 is valid", 275 "data": -2, 276 "valid": true 277 }, 278 { 279 "description": "integer 2 is invalid", 280 "data": 2, 281 "valid": false 282 }, 283 { 284 "description": "float -2.0 is valid", 285 "data": -2.0, 286 "valid": true 287 }, 288 { 289 "description": "float 2.0 is invalid", 290 "data": 2.0, 291 "valid": false 292 }, 293 { 294 "description": "float -2.00001 is invalid", 295 "data": -2.00001, 296 "valid": false 297 } 298 ] 299 }, 300 { 301 "description": "float and integers are equal up to 64-bit representation limits", 302 "schema": {"const": 9007199254740992}, 303 "tests": [ 304 { 305 "description": "integer is valid", 306 "data": 9007199254740992, 307 "valid": true 308 }, 309 { 310 "description": "integer minus one is invalid", 311 "data": 9007199254740991, 312 "valid": false 313 }, 314 { 315 "description": "float is valid", 316 "data": 9007199254740992.0, 317 "valid": true 318 }, 319 { 320 "description": "float minus one is invalid", 321 "data": 9007199254740991.0, 322 "valid": false 323 } 324 ] 325 }, 326 { 327 "description": "nul characters in strings", 328 "schema": { "const": "hello\u0000there" }, 329 "tests": [ 330 { 331 "description": "match string with nul", 332 "data": "hello\u0000there", 333 "valid": true 334 }, 335 { 336 "description": "do not match string lacking nul", 337 "data": "hellothere", 338 "valid": false 339 } 340 ] 341 } 342] 343