Request Body With Incorrect Ref

  • Query id: 0f6cd0ab-c366-4595-84fc-fbd8b9901e4d
  • Query name: Request Body With Incorrect Ref
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Request Body reference must always point to '#/components/RequestBodies'
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": {
    "requestBodies": {
      "List": {
        "description": "id of api version",
        "content": {
          "text/plain": {
            "schema": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "requestBody": {
          "$ref": "#/components/schemas/List"
        },
        "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Postitive test num. 2 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
components:
  requestBodies:
    List:
      description: id of api version
      required: true
      content:
        text/plain:
          schema:
            type: array
            items:
              type: integer
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      requestBody:
        $ref: "#/components/schemas/List"
      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

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": {
    "requestBodies": {
      "List": {
        "description": "id of api version",
        "content": {
          "text/plain": {
            "schema": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "requestBody": {
          "$ref": "#/components/requestBodies/List"
        },
        "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Negative test num. 2 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
components:
  requestBodies:
    List:
      description: id of api version
      required: true
      content:
        text/plain:
          schema:
            type: array
            items:
              type: integer
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      requestBody:
        $ref: "#/components/requestBodies/List"
      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