2

So I have one json schema and within this schema I am referencing another two schemas within the same json file, this works fine.

{
  "id": "http://ourdns.co.za/public/assets/json/formSchema.json",
  "type": "object",
  "properties": {
    "person": {
      "type": "object",
      "id": "#person",
      "properties": {
        "first_name": {
          "title": "What is your first name",
          "type": "string"
        },
        "last_name": {
          "title": "What is your last name",
          "type": "string"
        }
      }
    },
    "person_api": {
      "type": "object",
      "id": "#person"
    }
  }
}

What i would like to have is a root json schema that references two other json schemas that are external to the root. This differs from my current schema where I have all the schemas in one file(not ideal). There is a slight problem in that I cannot use $ref as a reference keyword because the plugin we are using does not support this. However we have found that id can be used as a reference keyword.(JsonForm is the plugin). How would we then get these using the id keyword because it does not seem to work?

{
  "id": "http://ourdns.co.za/public/assets/json/formSchema.json",
  "type": "object",
  "properties": {
    "person_api": {
      "type": "object",
      "id": "public/assets/person.json"
    }
  }
}

1) How do we call the same data externally, like.. "id": "public/assets/person.json" instead of combining it all in one file? 2) How would we retrieve particular properties for example if we only need person.firstname from person.json schema?

{
  "id": "http://dsn.co.za/public/assets/json/person.json",
  "type": "object",
  "properties": {
    "first_name": {
      "title": "What is your first name",
      "type": "string"
    }
  }
}
4

1 回答 1

6

您不能单独执行引用id。对于参考,您必须使用$ref.

id关键字允许您提供架构的 URL 作为引用的目标

{
    "id": "http://example.com/schemas/example",
    "type": "object",
    "properties": {
        "arr1": {
            "id": "#item-schema",
            ...
        },
        "arr2": {"$ref": "#item-schema"}
    }
}

这样您就可以使用漂亮的 URL(例如http://example.com/schemas/example#item-schema)而不是使用 JSON 指针片段语法来引用模式。它还允许您在definitions不更改 URL 的情况下重新组织您的架构(例如,将项目架构移动到 中)。

但是,对于引用本身,您仍然需要使用$ref. 如果您需要此功能,则需要在您使用的任何工具中支持它。

于 2013-10-24T11:15:00.303 回答