Skip to content

Instantly share code, notes, and snippets.

@kkotaro0111
Last active March 9, 2018 15:10
Show Gist options
  • Save kkotaro0111/11886a6206f43e03ea52128f3a0d2028 to your computer and use it in GitHub Desktop.
Save kkotaro0111/11886a6206f43e03ea52128f3a0d2028 to your computer and use it in GitHub Desktop.
あるitemsな要素fugaの値には、boolean型の値を持つhogeというプロパティを持つobjectがあって、そのhogeは、そのitemsの中で1つだけtrueがある状態をバリデーションしたい。 こういうルールはSchemaにどう記述すればいいのん?
// 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