openapi-backend icon indicating copy to clipboard operation
openapi-backend copied to clipboard

Decycle produce a wrong schema for schemas with `description`

Open juneidy opened this issue 4 months ago • 0 comments

The original schema:

{
  "title": "Request",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "requestBody": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "active": {
          "description": "Active style.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "foo": {
              "type": "string"
            }
          }
        },
        "default": {
          "description": "Default style.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "foo": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "required": [
    "requestBody"
  ]
}

The decycled schema:

{
  "title": "Request",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "requestBody": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "active": {
          "description": "Active style.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "foo": {
              "type": "string"
            }
          }
        },
        "default": {
          "description": "Default style.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "$ref": "#/properties/requestBody/properties/active/properties"
          }
        }
      }
    }
  },
  "required": [
    "requestBody"
  ]
}

I would imagine the correct result should be something like:

{
  "title": "Request",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "requestBody": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "active": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "foo": {
              "type": "string"
            }
          },
          "description": "Style definition."
        },
        "default": {
          "$ref": "#/properties/requestBody/properties/active"
        }
      }
    }
  },
  "required": [
    "requestBody"
  ]
}

juneidy avatar Apr 19 '24 06:04 juneidy