简体   繁体   English

等效于 XML 模式 keyref 的 JSON 模式

[英]JSON schema equivalent of XML schema keyref

I am trying to create a JSON schema for data that looks like this:我正在尝试为如下所示的数据创建 JSON 架构:

{
  "equipments": {
    "A": {},
    "B": {}
  },
  "work": [
    {
      "equipment": "A"
    }
  ]
}

The schema I currently have is this:我目前拥有的架构是这样的:

{
  "$id": "example",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "equipments":{
      "type": "object",
      "additionalProperties": true
    },
    "work": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "equipment": {
            "type": "string",
          }
        }
      }
    }
  }
}

In the equipments object different pieces of equipment are configured.在设备对象中配置了不同的设备。 These should then be referenced from items in the work array.然后应该从工作数组中的项目中引用这些。 In an XML schema I would do this with a keyref but I cannot find any equivalent for JSON schemas.在 XML 模式中,我会使用 keyref 来执行此操作,但我找不到 JSON 模式的任何等效项。 Is there an equivalent or is this just not possible with JSON schemas?是否有等效的或者这对 JSON 模式来说是不可能的?

It's not currently possible to validate relational data in JSON Schema.目前无法验证 JSON 架构中的关系数据。

There is a JSON Schema Vocabulary created to reference instance data , but I don't think that would do what you're looking for either.有一个 JSON Schema Vocabulary created to reference instance data ,但我认为这也不会满足您的需求。

There was an effort to define a Vocabulary for databases , but that has stalled.曾努力为数据库定义一个词汇表,但已经停滞不前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM