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"
        }
      }
    }
  }
}

貢獻者指南