2017-08-16 90 views
0
"data": { 
    "type": "systems", 
    "attributes": { 
     "display_name": "Meals", 
     "is_generic": false, 
     "interaction_object": "BlahBlah" 
    }, 
    "relationships": { 
     "account": { 
     "data": { 
      "type": "accounts", 
      "id": 204 
     } 
     }, 
     "venue": { 
     "data": { 
      "type": "venues", 
      "id": 187 
     } 
     } 
    } 
    } 

}基於屬性值爲true或false Ajv條件架構

請幫助。 :)根據物業價值有調理麻煩。 我需要驗證JSON根據簡單的條件:

  • 如果attributes.is_generic === false>帳戶和地點性能應出現在關係屬性
  • 如果attributes.is_generic === true>唯一場所應該是事先本

謝謝。

了基本架構準備:

type: 'object', 
 
    properties: { 
 
    data: { 
 
     properties: { 
 
     type: { type: 'string' }, 
 
     attributes: { 
 
      properties: { 
 
      display_name: { type: 'string' }, 
 
      is_generic: { type: 'boolean' }, 
 
      interaction_object: { type: 'string' }, 
 
      }, 
 
      required: ['display_name', 'is_generic', 'interaction_object'] 
 
     }, 
 
     relationships: { 
 
      properties: { 
 
      account: { 
 
       properties: { 
 
       data: { 
 
        properties: { 
 
        type: { type: 'string' }, 
 
        id: { type: 'number' }, 
 
        }, 
 
        required: [ 'type', 'id'], 
 
       } 
 
       }, 
 
       required: ['data'], 
 
      }, 
 
      venue: { 
 
       properties: { 
 
       data: { 
 
        properties: { 
 
        type: { type: 'string' }, 
 
        id: { type: 'number' }, 
 
        }, 
 
        required: [ 'type', 'id'], 
 
       } 
 
       }, 
 
       required: ['data'], 
 
      }, 
 
      }, 
 
      required: ['venue', 'account'] 
 
     } 
 
     }, 
 
     required: ['attributes', 'relationships'] 
 
    } 
 
    }, 
 
    required: ['data'], 
 
    additionalProperties: false,

謝謝大家幫忙

回答

0

它不是一種優雅的方式,但它確實爲我工作

const availableSystemSchema2 = { 
 
    type: 'object', 
 
    properties: { 
 
    data: { 
 
     oneOf: [ 
 
      { 
 
      properties: { 
 
       attributes: { 
 
       properties: { 
 
        display_name: { type: 'string' }, 
 
        is_generic: { enum: [false]}, 
 
        interaction_object: { type: 'string' }, 
 
       }, 
 
       required: ['display_name'] 
 
       }, 
 
       relationships: { 
 
       properties: { 
 
        account: { 
 
        properties: { 
 
         data: { 
 
         properties: { 
 
          type: { type: 'string' }, 
 
          id: { type: 'number' }, 
 
         }, 
 
         required: [ 'type', 'id'], 
 
         } 
 
        }, 
 
        required: ['data'], 
 
        }, 
 
        venue: { 
 
        properties: { 
 
         data: { 
 
         properties: { 
 
          type: { type: 'string' }, 
 
          id: { type: 'number' }, 
 
         }, 
 
         required: [ 'type', 'id'], 
 
         } 
 
        }, 
 
        required: ['data'], 
 
        }, 
 
       }, 
 
       required: ['venue', 'account'] 
 
       } 
 
      }, 
 
      required: ['attributes', 'relationships'] 
 
      }, 
 
      { 
 
      properties: { 
 
       attributes: { 
 
       properties: { 
 
        display_name: { type: 'string' }, 
 
        is_generic: { enum: [true]}, 
 
        interaction_object: { type: 'string' }, 
 
       }, 
 
       required: ['display_name'] 
 
       }, 
 
       relationships: { 
 
       properties: { 
 
        venue: { 
 
        properties: { 
 
         data: { 
 
         properties: { 
 
          type: { type: 'string' }, 
 
          id: { type: 'number' }, 
 
         }, 
 
         required: [ 'type', 'id'], 
 
         } 
 
        }, 
 
        required: ['data'], 
 
        }, 
 
       }, 
 
       required: ['venue'] 
 
       } 
 
      }, 
 
      required: ['attributes', 'relationships'] 
 
      } 
 
     ] 
 
     } 
 
    }, 
 
    required: ['data'], 
 
    additionalProperties: false, 
 
}

相關問題