0

I have the following json schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "schema validating people and vehicles",
  "definitions": {
    "base": {
      "properties": {
        "age": {
          "type": "integer"
        }
      },
      "required": [
        "age"
      ]
    },
    "person": {
      "$ref": "#/definitions/base",
      "additionalProperties": false,
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "sport": {
          "type": "string"
        }
      },
      "required": [
        "firstName"
      ]
    },
    "vehicle": {
      "$ref": "#/definitions/base",
      "additionalProperties": false,
      "properties": {
        "vehicle": {
          "type": "string"
        },
        "price": {
          "type": "integer"
        }
      }
    }
  },
  "type": "object",
  "oneOf": [
    {
      "$ref": "#/definitions/person",
    },
    {
      "$ref": "#/definitions/vehicle",
    }
  ]
}

And i want it to validate against

{"firstName":"John", "lastName":"Doe", "sport": "football", "age": 15}

and the following

{"type": "car", "price": 100, "age": 3}

I get the following error JSON is valid against more than one schema from 'oneOf'. Valid schema indexes: 0, 1..

Why is it valid against more then one? (firstName is only defined in person and type is only defined in vehicle.)

Peter
  • 37,042
  • 39
  • 142
  • 198