Incorrect parameter object reference (OpenAPI 3.0)

A parameter reference points to the wrong kind of definition

Description

Each $ref in parameters must identify a parameter with a name and location.

Potential impact

A broken path or a reference to a schema can prevent validation or leave a required input out of generated clients.

Remediation

Point to a parameter under #/components/parameters/... or in an external file. For a path parameter, match its name to the placeholder in the URL.

Examples

On /{id}, idParam defines the required integer path parameter id. If you also serve /user/{id}, which the second excerpt omits, fix its reference too.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "integer"
        }
      }
    }
  },
  "paths": {
    "/{id}": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "$ref": "#path/parameters/idParam"
        },
        {
          "$ref": "#components/schemas/idParam"
        }
      ]
    },
    "/user/{id}": {
      "get": {
        "parameters": [
          {
            "$ref": "#path/parameters/idParam"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "integer"
        }
      }
    }
  },
  "paths": {
    "/{id}": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/idParam"
        }
      ]
    }
  }
}

References