Response on operations that should have a body has undefined schema (v3)

  • Query id: a92be1d5-d762-484a-86d6-8cd0907ba100
  • Query name: Response on operations that should have a body has undefined schema (v3)
  • Platform: OpenAPI
  • Severity: Medium
  • Category: Networking and Firewall
  • URL: Github

Description

If a response is not head or its code is not 204 or 304, it should have a schema defined
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiVersion": {
        "type": "object",
        "discriminator": {
          "propertyName": "ApiVersion"
        },
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  }
}
Positive test num. 2 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
Positive test num. 3 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {}
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiVersion": {
        "type": "object",
        "discriminator": {
          "propertyName": "ApiVersion"
        },
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  }
}

Positive test num. 4 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/pdf": {},
              "application/json": {}
            }
          }
        }
      },
      "post": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiVersion"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiVersion": {
        "type": "object",
        "discriminator": {
          "propertyName": "ApiVersion"
        },
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  }
}
Positive test num. 5 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {}
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiVersion": {
        "type": "object",
        "discriminator": {
          "propertyName": "ApiVersion"
        },
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  }
}
Positive test num. 6 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
components:
  schemas:
    ApiVersion:
      type: object
      discriminator:
        propertyName: ApiVersion
      properties:
        code:
          type: integer
          format: int32
        version:
          type: string
Positive test num. 7 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          content:
            application/json: {}
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
components:
  schemas:
    ApiVersion:
      type: object
      discriminator:
        propertyName: ApiVersion
      properties:
        code:
          type: integer
          format: int32
        version:
          type: string
Positive test num. 8 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          content:
            application/pdf: {}
            application/json: {}
    post:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/ApiVersion"
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
components:
  schemas:
    ApiVersion:
      type: object
      discriminator:
        propertyName: ApiVersion
      properties:
        code:
          type: integer
          format: int32
        version:
          type: string
Positive test num. 9 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          content: {}
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
components:
  schemas:
    ApiVersion:
      type: object
      discriminator:
        propertyName: ApiVersion
      properties:
        code:
          type: integer
          format: int32
        version:
          type: string
Positive test num. 10 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  }
}

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiVersion"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiVersion": {
        "type": "object",
        "discriminator": {
          "propertyName": "ApiVersion"
        },
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  }
}
Negative test num. 2 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/ApiVersion"
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content
components:
  schemas:
    ApiVersion:
      type: object
      discriminator:
        propertyName: ApiVersion
      properties:
        code:
          type: integer
          format: int32
        version:
          type: string
Negative test num. 3 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "object",
              "discriminator": "ApiVersion",
              "properties": {
                "code": {
                  "type": "integer",
                  "format": "int32"
                },
                "version": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteVersion",
        "summary": "Deletes API versions",
        "responses": {
          "204": {
            "description": "no content"
          }
        }
      }
    }
  }
}

Negative test num. 4 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          schema:
            type: object
            discriminator: ApiVersion
            properties:
              code:
                type: integer
                format: int32
              version:
                type: string
    delete:
      operationId: deleteVersion
      summary: Deletes API versions
      responses:
        "204":
          description: no content