JSON模式引用其他属性

问题描述

我正在尝试使用JSON作为某些软件的输入文件,并使用JSON模式对其进行验证。

这是我要验证的事情。

{
"Car names":["Skoda","VW","Tesla"],"Car property names":["Body","Engine"],"Car properties types":{
    "Body":["Saloon","Hatchback","Estate"],"Engine":["Diesel","Petrol","Electric"],},"Cars"{
    "Skoda":{
        "Car properties"{
            "Body":"Hatchback","Engine":"Diesel"
        }
    }
}
}

因此,用户可以根据需要添加新的汽车属性,并可以自由选择汽车属性类型中数组的内容,但是用户必须从“汽车属性”对象中的数组中选择一项。 “鲤鱼属性类型”属性名称还必须包含所有汽车属性名称

这是我必须去的一个模式。我找不到一种方法来强制将汽车属性设为汽车属性类型数组中的项之一。

{
  "type": "object","title": "The Root Schema","required": [
    "Car names","Car property names","Car property types","Cars"
  ],"additionalProperties": false,"properties": {
    "Car names": {
      "type": "array","items": {
        "type": "string"
      },"uniqueItems": true
    },"Car property names": {
      "type": "array","Car property types": {
      "type": "object","propertyNames":{"enum":{"$data":"/Car property names"}},"additionalProperties":{
        "type":"array","uniqueItems": true
      }
    },"Cars": {
      "type": "object","propertyNames":{"enum":{"$data":"/Car names"}},"additionalProperties":{
        "type":"object","properties":{
          "Car properties":{
            "type": "object","propertyNames":{"enum":{"$data":"/Car property names"}
            },"additionalProperties":{
              "type":"string","enum":{"$data":"/Car property types/Body"}
            }
          }
        },"required":["Car properties"],"additionalProperties":false
      }
    }
  }
}

因此,在模式底部附近,我需要一些方法来根据属性名称将对Body的引用更改为变量。主体将是用户可编辑的,并且取决于输入,因此我需要某种引用它的方式,我不确定是否可行。 我们正在在线使用jsoneditor,我认为它可以访问$ data方法,但我无法在其上找到任何文档。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)