RicoSuter/NJsonSchema

Recursive refs on JSON Schema from JSON example

Open

#1,252 创建于 2020年9月22日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)C# (550 fork)github user discovery
help wantedtype: bugtype: enhancement

仓库指标

Star
 (1,578 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Hi! The JSON

{
    "Publications": [{
            "Author": {
                "Name": "Joaquin Phoenix",
                "FullInfo": {
                    "Name": "Joaquin Phoenix"
                }
            },
            "Collaborator": {
                "Name": "Robert DeNiro",
                "FullInfo": {
                    "Name": "Robert DeNiro"
                }
            }
        }
    ]
}

when run by the code var schema = JsonSchema.FromSampleJson(data); var json = schema.ToJson();

generates schema with self-referencial refs:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "Publications": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Publication"
      }
    }
  },
  "definitions": {
    "Author": {
      "type": "object",
      "properties": {
        "Name": {
          "type": "string"
        },
        "FullInfo": {
          "$ref": "#/definitions/Author"
        }
      }
    },
    "Publication": {
      "type": "object",
      "properties": {
        "Author": {
          "$ref": "#/definitions/Author"
        },
        "Collaborator": {
          "$ref": "#/definitions/Author"
        }
      }
    }
  }
}

贡献者指南