drafter
drafter copied to clipboard
Incorrect JSON and JSON Schema if there is a circular reference.
See any of the circular reference test in drafter repo for the details.
Current Behaviour
# GET /
+ Response 200 (application/json)
+ Attributes (Node)
# Data Structures
## Node
+ children (array[Node], fixed-type)
{
"children": [
{}
]
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object"
}
]
}
}
}
}
{
"element": "dataStructure",
"content": {
"element": "object",
"meta": {
"id": {
"element": "string",
"content": "Node"
}
},
"content": [
{
"element": "member",
"attributes": {
"typeAttributes": {
"element": "array",
"content": [
{
"element": "string",
"content": "fixedType"
}
]
}
},
"content": {
"key": {
"element": "string",
"content": "children"
},
"value": {
"element": "array",
"content": [
{
"element": "Node"
}
]
}
}
}
]
}
}
This following API Blueprint doesn't produce an error/warning and I think it should:
# GET /
+ Response 200 (application/json)
+ Attributes (Node)
# Data Structures
## Node
+ children (Node, required)
# GET /
+ Response 200 (application/json)
+ Attributes (Node)
# Data Structures
## Node
+ children (array[Node], fixed-type)
Current Result:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object"
}
]
}
}
}
}
Expectation?
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "#/$defs/Node"
}
],
"$defs": {
"Node": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/$defs/Node"
}
}
}
}
}
}