Skip to content

Commit cb332a3

Browse files
authored
IF-THEN-ELSE Conditional with properties attribute (#358)
#357 example from https://json-schema.org/understanding-json-schema/reference/conditionals.html
1 parent e1a5aa2 commit cb332a3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/test/resources/draft7/if-then-else.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,69 @@
184184
"valid": true
185185
}
186186
]
187+
},
188+
{
189+
"description": "conditions by properties",
190+
"schema": {
191+
"type": "object",
192+
"properties": {
193+
"street_address": {
194+
"type": "string"
195+
},
196+
"country": {
197+
"enum": ["United States of America", "Canada"]
198+
}
199+
},
200+
"if": {
201+
"properties": {
202+
"country": {
203+
"const": "United States of America"
204+
}
205+
}
206+
},
207+
"then": {
208+
"properties": {
209+
"postal_code": {
210+
"pattern": "[0-9]{5}(-[0-9]{4})?"
211+
}
212+
}
213+
},
214+
"else": {
215+
"properties": {
216+
"postal_code": {
217+
"pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"
218+
}
219+
}
220+
}
221+
},
222+
"tests": [
223+
{
224+
"description": "valid through then",
225+
"data": {
226+
"street_address": "1600 Pennsylvania Avenue NW",
227+
"country": "United States of America",
228+
"postal_code": "20500"
229+
},
230+
"valid": true
231+
},
232+
{
233+
"description": "valid through else",
234+
"data": {
235+
"street_address": "24 Sussex Drive",
236+
"country": "Canada",
237+
"postal_code": "K1M 1M4"
238+
},
239+
"valid": true
240+
},
241+
{
242+
"description": "invalid",
243+
"data": {
244+
"street_address": "24 Sussex Drive",
245+
"country": "Canada",
246+
"postal_code": "10000"
247+
},
248+
"valid": false
249+
}
250+
]
187251
}
188252
]

0 commit comments

Comments
 (0)