Response Object With Incorrect Ref (v2)

  • Query id: bccfa089-89e4-47e0-a0e5-185fe6902220
  • Query name: Response Object With Incorrect Ref (v2)
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Response Object reference must always point to '#/responses'
Documentation

Code samples

Code samples with security vulnerabilities

Postitive test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "$ref": "#/definitions/User"
          }
        },
        "parameters": [
          {
            "$ref": "#/parameters/limitParam"
          }
        ]
      }
    }
  },
  "responses": {
    "Success": {
      "description": "An array with users",
      "schema": {
        "$ref": "#/definitions/User"
      }
    }
  },
  "parameters": {
    "limitParam": {
      "name": "limit",
      "in": "body",
      "description": "max records to return",
      "required": true,
      "schema": {
        "type": "integer"
      }
    }
  },
  "definitions": {
    "User": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      }
    }
  }
}
Postitive test num. 2 - yaml file
swagger: '2.0'
info:
  title: Simple API Overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        '200':
          "$ref": "#/definitions/User"
      parameters:
      - "$ref": "#/parameters/limitParam"
responses:
  Success:
    description: An array with users
    schema:
      "$ref": "#/definitions/User"
parameters:
  limitParam:
    name: limit
    in: body
    description: max records to return
    required: true
    schema:
      type: integer
definitions:
  User:
    type: object
    required:
    - id
    - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "$ref": "#/responses/Success"
          }
        },
        "parameters": [
          {
            "$ref": "#/parameters/limitParam"
          }
        ]
      }
    }
  },
  "responses": {
    "Success": {
      "description": "An array with users",
      "schema": {
        "$ref": "#/definitions/User"
      }
    }
  },
  "parameters": {
    "limitParam": {
      "name": "limit",
      "in": "body",
      "description": "max records to return",
      "required": true,
      "schema": {
        "type": "integer"
      }
    }
  },
  "definitions": {
    "User": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      }
    }
  }
}
Negative test num. 2 - yaml file
swagger: '2.0'
info:
  title: Simple API Overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        '200':
          "$ref": "#/responses/Success"
      parameters:
      - "$ref": "#/parameters/limitParam"
responses:
  Success:
    description: An array with users
    schema:
      "$ref": "#/definitions/User"
parameters:
  limitParam:
    name: limit
    in: body
    description: max records to return
    required: true
    schema:
      type: integer
definitions:
  User:
    type: object
    required:
    - id
    - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string