我有以下json架构:
{
"$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",
}
]
}
我希望它能够验证
{"firstName":"John", "lastName":"Doe", "sport": "football", "age": 15}
以及
{"type": "car", "price": 100, "age": 3}
我收到以下错误JSON is valid against more than one schema from 'oneOf'. Valid schema indexes: 0, 1.
。
为什么它对多于一个有效? (firstName
仅在person
中定义,type
仅在vehicle
中定义。)
答案 0 :(得分:1)