我正在尝试为以下对象模型创建一个json架构。但是,当我尝试根据架构验证数据时,出现以下错误。
should be valid to one and only one of schema, but more than one are valid: {"$ref":"#/$defs/drug-treatment"}{"$ref":"#/$defs/surgery-treatment"}
下面是我的架构
{
"$id": "someid",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "JSON Schema for treatments",
"oneOf" : [
{ "$ref" : "#/$defs/drug-treatment" },
{ "$ref" : "#/$defs/surgery-treatment" }
],
"$defs": {
"base": {
"type": "object",
"properties": {
"type-tag": {
"enum": [ "SURGERY", "DRUGTREATMENT", "RADIOLOGY", "PHYSIOTHERAPY" ]
},
"id": {
"type": "string",
"format": "uuid"
},
"patient-id": {
"type": "string",
"format": "uuid"
},
"patient-name": {
"type": "string"
},
"provider-id": {
"type": "string",
"format": "uuid"
},
"provider-name": {
"type": "string"
},
"diagnosis": {
"type": "string"
},
"followup-treatments": {
"type" : "array",
"items" : { "$ref" : "#" }
}
},
"required": [
"id",
"type-tag",
"patient-id",
"patient-name",
"provider-id",
"provider-name",
"diagnosis",
"followup-treatments"
]
},
"drug-treatment": {
"allOf": [
{ "$ref" : "#/$defs/base" }
],
"properties": {
"drug": {
"type": "string"
},
"dosage": {
"type": "number"
},
"start-date": {
"type": "string",
"format": "date"
},
"end-date": {
"type": "string",
"format": "date"
},
"frequency": "integer"
},
"required": [
"drug",
"dosage",
"start-date",
"end-date",
"frequency"
],
"unevaluatedProperties" : false
},
"surgery-treatment": {
"allOf": [
{ "$ref" : "#/$defs/base" }
],
"properties": {
"surgery-date": {
"type": "string",
"format": "date"
},
"discharge-instructions": {
"type": "string"
},
"required": [
"surgery-date",
"discharge-instructions"
],
"unevaluatedProperties" : false
}
},
}
}
下面是正在验证模式的示例数据。
"treatments": [
{
"type-tag": "DRUGTREATMENT",
"drug": "fdsds",
"dosage": 2.0,
"start-date": "2222-02-12",
"end-date": "2222-02-12",
"frequency": 2,
"id": "aa7da984-0252-45b1-b0cd-f1dbe98662e2",
"patient-id": "ab62420e-0bd8-4e39-8e0b-36e464b7abb2",
"patient-name": "Tom",
"provider-id": "154523b2-7598-4ed4-aab1-b2ef1692109c",
"provider-name": "gdsfdsd",
"diagnosis": "sfdsfds",
"followup-treatments": []
},
{
"type-tag": "SURGERY",
"surgery-date": "2222-02-12",
"discharge-instructions": "dsfdsfdsfds",
"id": "12d2e565-8966-4029-840b-1959277b37f6",
"patient-id": "ab62420e-0bd8-4e39-8e0b-36e464b7abb2",
"patient-name": "Tom",
"provider-id": "154523b2-7598-4ed4-aab1-b2ef1692109c",
"provider-name": "gdsfdsd",
"diagnosis": "fdsfds",
"followup-treatments": [],
}
]
但当我验证类型“药物治疗”时,它给我错误
should be valid to one and only one of schema, but more than one are valid: {"$ref":"#/$defs/drug-treatment"}{"$ref":"#/$defs/surgery-treatment"}
你知道我错过了什么吗?
1条答案
按热度按时间lx0bsm1f1#
我对你的模式做了一些修改,但这应该适用于你问题中的样本数据。你的模式有一些语法错误和关键字放置错误:
编辑:显示带有任意附加属性的错误消息。