drafter icon indicating copy to clipboard operation
drafter copied to clipboard

Incorrect JSON and JSON Schema if there is a circular reference.

Open w-vi opened this issue 9 years ago • 3 comments

See any of the circular reference test in drafter repo for the details.

w-vi avatar Feb 12 '16 06:02 w-vi

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

kylef avatar Sep 04 '18 15:09 kylef

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)

kylef avatar Sep 04 '18 15:09 kylef

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

kylef avatar Apr 22 '20 13:04 kylef