RicoSuter/NJsonSchema
View on GitHubRecursive refs on JSON Schema from JSON example
Open
#1,252 opened on Sep 22, 2020
help wantedtype: bugtype: enhancement
Repository metrics
- Stars
- (1,578 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
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"
}
}
}
}
}