Last active
March 9, 2018 15:10
-
-
Save kkotaro0111/11886a6206f43e03ea52128f3a0d2028 to your computer and use it in GitHub Desktop.
あるitemsな要素fugaの値には、boolean型の値を持つhogeというプロパティを持つobjectがあって、そのhogeは、そのitemsの中で1つだけtrueがある状態をバリデーションしたい。 こういうルールはSchemaにどう記述すればいいのん?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// schema: **************************************************************************** | |
{ | |
"type": "object", | |
"properties": { | |
"fuga": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "number" | |
}, | |
"hoge": { | |
"type": "boolean" | |
} | |
} | |
} | |
} | |
} | |
} | |
// valid: **************************************************************************** | |
{ | |
"fuga": [ | |
{ | |
"id": 1, | |
"hoge": true | |
}, | |
{ | |
"id": 2, | |
"hoge": false | |
}, | |
{ | |
"id": 3, | |
"hoge": false | |
}, | |
] | |
} | |
// invalid 1: **************************************************************************** | |
{ | |
"fuga": [ | |
{ | |
"id": 1, | |
"hoge": false | |
}, | |
{ | |
"id": 2, | |
"hoge": false | |
}, | |
{ | |
"id": 3, | |
"hoge": false | |
}, | |
] | |
} | |
// invalid 2: **************************************************************************** | |
{ | |
"fuga": [ | |
{ | |
"id": 1, | |
"hoge": true | |
}, | |
{ | |
"id": 2, | |
"hoge": false | |
}, | |
{ | |
"id": 3, | |
"hoge": true | |
}, | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment