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
        }
      }
    }
  }

}

Please help. :) have troubles with conditioning according to property value. I need to validate JSON according to simple condition:

  • if attributes.is_generic === false > account and venue properties should be present in relationship property
  • if attributes.is_generic === true > only venue should be present

Thank in advance.

got basic schema ready:

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,

thank you for help

1 Answers1

0

its not an elegant way but it did work for me

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,
}