1[ 2 { 3 "description": "ignore if without then or else", 4 "schema": { 5 "$schema": "https://json-schema.org/draft/2020-12/schema", 6 "if": { 7 "const": 0 8 } 9 }, 10 "tests": [ 11 { 12 "description": "valid when valid against lone if", 13 "data": 0, 14 "valid": true 15 }, 16 { 17 "description": "valid when invalid against lone if", 18 "data": "hello", 19 "valid": true 20 } 21 ] 22 }, 23 { 24 "description": "ignore then without if", 25 "schema": { 26 "$schema": "https://json-schema.org/draft/2020-12/schema", 27 "then": { 28 "const": 0 29 } 30 }, 31 "tests": [ 32 { 33 "description": "valid when valid against lone then", 34 "data": 0, 35 "valid": true 36 }, 37 { 38 "description": "valid when invalid against lone then", 39 "data": "hello", 40 "valid": true 41 } 42 ] 43 }, 44 { 45 "description": "ignore else without if", 46 "schema": { 47 "$schema": "https://json-schema.org/draft/2020-12/schema", 48 "else": { 49 "const": 0 50 } 51 }, 52 "tests": [ 53 { 54 "description": "valid when valid against lone else", 55 "data": 0, 56 "valid": true 57 }, 58 { 59 "description": "valid when invalid against lone else", 60 "data": "hello", 61 "valid": true 62 } 63 ] 64 }, 65 { 66 "description": "if and then without else", 67 "schema": { 68 "$schema": "https://json-schema.org/draft/2020-12/schema", 69 "if": { 70 "exclusiveMaximum": 0 71 }, 72 "then": { 73 "minimum": -10 74 } 75 }, 76 "tests": [ 77 { 78 "description": "valid through then", 79 "data": -1, 80 "valid": true 81 }, 82 { 83 "description": "invalid through then", 84 "data": -100, 85 "valid": false 86 }, 87 { 88 "description": "valid when if test fails", 89 "data": 3, 90 "valid": true 91 } 92 ] 93 }, 94 { 95 "description": "if and else without then", 96 "schema": { 97 "$schema": "https://json-schema.org/draft/2020-12/schema", 98 "if": { 99 "exclusiveMaximum": 0 100 }, 101 "else": { 102 "multipleOf": 2 103 } 104 }, 105 "tests": [ 106 { 107 "description": "valid when if test passes", 108 "data": -1, 109 "valid": true 110 }, 111 { 112 "description": "valid through else", 113 "data": 4, 114 "valid": true 115 }, 116 { 117 "description": "invalid through else", 118 "data": 3, 119 "valid": false 120 } 121 ] 122 }, 123 { 124 "description": "validate against correct branch, then vs else", 125 "schema": { 126 "$schema": "https://json-schema.org/draft/2020-12/schema", 127 "if": { 128 "exclusiveMaximum": 0 129 }, 130 "then": { 131 "minimum": -10 132 }, 133 "else": { 134 "multipleOf": 2 135 } 136 }, 137 "tests": [ 138 { 139 "description": "valid through then", 140 "data": -1, 141 "valid": true 142 }, 143 { 144 "description": "invalid through then", 145 "data": -100, 146 "valid": false 147 }, 148 { 149 "description": "valid through else", 150 "data": 4, 151 "valid": true 152 }, 153 { 154 "description": "invalid through else", 155 "data": 3, 156 "valid": false 157 } 158 ] 159 }, 160 { 161 "description": "non-interference across combined schemas", 162 "schema": { 163 "$schema": "https://json-schema.org/draft/2020-12/schema", 164 "allOf": [ 165 { 166 "if": { 167 "exclusiveMaximum": 0 168 } 169 }, 170 { 171 "then": { 172 "minimum": -10 173 } 174 }, 175 { 176 "else": { 177 "multipleOf": 2 178 } 179 } 180 ] 181 }, 182 "tests": [ 183 { 184 "description": "valid, but would have been invalid through then", 185 "data": -100, 186 "valid": true 187 }, 188 { 189 "description": "valid, but would have been invalid through else", 190 "data": 3, 191 "valid": true 192 } 193 ] 194 }, 195 { 196 "description": "if with boolean schema true", 197 "schema": { 198 "$schema": "https://json-schema.org/draft/2020-12/schema", 199 "if": true, 200 "then": { "const": "then" }, 201 "else": { "const": "else" } 202 }, 203 "tests": [ 204 { 205 "description": "boolean schema true in if always chooses the then path (valid)", 206 "data": "then", 207 "valid": true 208 }, 209 { 210 "description": "boolean schema true in if always chooses the then path (invalid)", 211 "data": "else", 212 "valid": false 213 } 214 ] 215 }, 216 { 217 "description": "if with boolean schema false", 218 "schema": { 219 "$schema": "https://json-schema.org/draft/2020-12/schema", 220 "if": false, 221 "then": { "const": "then" }, 222 "else": { "const": "else" } 223 }, 224 "tests": [ 225 { 226 "description": "boolean schema false in if always chooses the else path (invalid)", 227 "data": "then", 228 "valid": false 229 }, 230 { 231 "description": "boolean schema false in if always chooses the else path (valid)", 232 "data": "else", 233 "valid": true 234 } 235 ] 236 }, 237 { 238 "description": "if appears at the end when serialized (keyword processing sequence)", 239 "schema": { 240 "$schema": "https://json-schema.org/draft/2020-12/schema", 241 "then": { "const": "yes" }, 242 "else": { "const": "other" }, 243 "if": { "maxLength": 4 } 244 }, 245 "tests": [ 246 { 247 "description": "yes redirects to then and passes", 248 "data": "yes", 249 "valid": true 250 }, 251 { 252 "description": "other redirects to else and passes", 253 "data": "other", 254 "valid": true 255 }, 256 { 257 "description": "no redirects to then and fails", 258 "data": "no", 259 "valid": false 260 }, 261 { 262 "description": "invalid redirects to else and fails", 263 "data": "invalid", 264 "valid": false 265 } 266 ] 267 } 268] 269