RicoSuter/NJsonSchema

Recursive refs on JSON Schema from JSON example

オープン

#1,252 opened on 2020/09/22

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (549 件のフォーク)github user discovery
help wantedtype: bugtype: enhancement

Repository metrics

Stars
 (1,581 個のスター)
PR merge metrics
 (平均マージ 39d 6h) (30d で 1 merged 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"
        }
      }
    }
  }
}

コントリビューターガイド