widdershins icon indicating copy to clipboard operation
widdershins copied to clipboard

Links to nested schemas

Open timothymcmackin opened this issue 5 years ago • 0 comments

This might be related to #107, #175, or #181. I've got several OAS 3 documents, and I've extracted the schemas to a separate file so I can refer to them from each document. Based on discussion in #175, instead of referring directly to the external file, I refer from the endpoint to the schemas in that same file, and those schemas refer to the schemas in the external file. For testing, I've pulled the "components" section from petstore3.json into petstore3_schemas.json and updated petstore3.json/components/requestBodies/Pet to refer to it. Here's a gist: https://gist.github.com/timothymcmackin/72e5b6e9b4ff661117d0c0e90c782055

[petstore3_withrefs.json]

"paths": {
    "/pet": {
        "post": {
            "summary": "Add a new pet to the store",
            "operationId": "addPet",
            "requestBody": {
                "$ref": "#/components/requestBodies/Pet"
            }
        }
...
"components": {
    "Pet": {
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "petstore3_schemas.json#/components/schemas/Pet"
                }
            },
            "application/xml": {
                "schema": {
                    "$ref": "petstore3_schemas.json#/components/schemas/Pet"
                }
            }
        },
        "description": "Pet object that needs to be added to the store",
        "required": true
    }

[petstore3_schemas.json]

"components": {
  "requestBodies": {
    "Pet": {
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/Pet"
                }
            },
            "application/xml": {
                "schema": {
                    "$ref": "#/components/schemas/Pet"
                }
            }
        },
        "description": "Pet object that needs to be added to the store",
        "required": true
    }
...
  "schemas" {
    "Category": {
      "type": "object",
      "properties": {
          "id": {
              "type": "integer",
              "format": "int64"
          },
          "name": {
              "type": "string"
          }
      },
      "xml": {
          "name": "Category"
      }
    },
    "Tag": {
      "type": "object",
      "properties": {
          "id": {
              "type": "integer",
              "format": "int64"
          },
          "name": {
              "type": "string"
          }
      },
      "xml": {
          "name": "Tag"
      }
    },
    "Pet": {
      "type": "object",
      "required": [
          "name",
          "photoUrls"
      ],
      "properties": {
          "id": {
              "type": "integer",
              "format": "int64"
          },
          "category": {
              "$ref": "#/components/schemas/Category"
          },
          "name": {
              "type": "string",
              "example": "doggie"
          },
          "photoUrls": {
              "type": "array",
              "xml": {
                  "name": "photoUrl",
                  "wrapped": true
              },
              "items": {
                  "type": "string"
              }
          },
          "tags": {
              "type": "array",
              "xml": {
                  "name": "tag",
                  "wrapped": true
              },
              "items": {
                  "$ref": "#/components/schemas/Tag"
              }
          },
          "status": {
              "type": "string",
              "description": "pet status in the store",
              "enum": [
                  "available",
                  "pending",
                  "sold"
              ]
          }
      },
      "xml": {
          "name": "Pet"
      }
  }
}

[env.json]

{
  "resolve": true,
  "language_tabs": [{ "javascript": "JavaScript" }],
  "expandBody": true,
  "summary": true
}

The result I get from Widdershins shows [object] as the type of Category and Tag. I was expecting to get links to the Category and Tag schemas.

<h3 id="addpet-parameters">Parameters</h3>

|Parameter|In|Type|Required|Description|
|---|---|---|---|---|
|body|body|[Pet](#schemapet)|true|Pet object that needs to be added to the store|
|» id|body|integer(int64)|false|none|
|» category|body|object|false|none|
|»» id|body|integer(int64)|false|none|
|»» name|body|string|false|none|
|» name|body|string|true|none|
|» photoUrls|body|[string]|true|none|
|» tags|body|[object]|false|none|
|»» id|body|integer(int64)|false|none|
|»» name|body|string|false|none|
|» status|body|string|false|pet status in the store|

Here's what I get if I convert the original petstore3.json with that env file. Note that there are links to the nested Tag and Category schemas.

<h3 id="addpet-parameters">Parameters</h3>

|Parameter|In|Type|Required|Description|
|---|---|---|---|---|
|body|body|[Pet](#schemapet)|true|Pet object that needs to be added to the store|
|» id|body|integer(int64)|false|none|
|» category|body|[Category](#schemacategory)|false|none|
|»» id|body|integer(int64)|false|none|
|»» name|body|string|false|none|
|» name|body|string|true|none|
|» photoUrls|body|[string]|true|none|
|» tags|body|[[Tag](#schematag)]|false|none|
|»» id|body|integer(int64)|false|none|
|»» name|body|string|false|none|
|» status|body|string|false|pet status in the store|

Is this a limitation of resolving the $refs, or is there something I can do to preserve the links?

timothymcmackin avatar Oct 10 '18 18:10 timothymcmackin