Parameter Object With Incorrect Ref (v3)

  • Query id: d40f27e6-15fb-4b56-90f8-fc0ff0291c51
  • Query name: Parameter Object With Incorrect Ref (v3)
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Parameter Object reference must always point to '#/components/parameters'
Documentation

Code samples

Code samples with security vulnerabilities

Postitive test num. 1 - json file
{
  "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 the version",
        "required": true,
        "schema": {
          "type": "int"
        }
      }
    }
  },
  "paths": {
    "/": {
      "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"
          }
        ]
      }
    }
  }
}
Postitive test num. 2 - yaml file
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: int
    nameParam:
      in: path
      description: Name of the API version
      required: true
      schema:
        type: string
paths:
  "/":
    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"

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "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 the version",
        "required": true,
        "schema": {
          "type": "int"
        }
      }
    }
  },
  "paths": {
    "/": {
      "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"
        }
      ]
    }
  }
}
Negative test num. 2 - yaml file
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: int
    nameParam:
      in: path
      description: Name of the API version
      required: true
      schema:
        type: string
paths:
  "/":
    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"