Components Request Body Definition Is Unused
- Query id: 6b76f589-9713-44ab-97f5-59a3dba1a285
- Query name: Components Request Body Definition Is Unused
- Platform: OpenAPI
- Severity: Info
- Category: Best Practices
- URL: Github
Description¶
Components request bodies definitions should be referenced or removed from Open API definition
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"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"requestBodies": {
"MyObjectBody": {
"description": "A JSON object containing my object information",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
Positive test num. 2 - yaml file
openapi: 3.0.0
info:
title: Simple API Overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
"$ref": "#/components/schemas/MyObject"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
requestBodies:
MyObjectBody:
description: A JSON object containing my object information
content:
application/json:
schema:
"$ref": "#/components/schemas/MyObject"
Code samples without security vulnerabilities¶
Negative test num. 1 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"$ref": "#/components/schemas/MyObject"
}
},
"requestBody": {
"$ref": "#/components/requestBodies/MyObjectBody"
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"requestBodies": {
"MyObjectBody": {
"description": "A JSON object containing my object information",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
Negative test num. 2 - yaml file
openapi: 3.0.0
info:
title: Simple API Overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
"$ref": "#/components/schemas/MyObject"
requestBody:
"$ref": "#/components/requestBodies/MyObjectBody"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
requestBodies:
MyObjectBody:
description: A JSON object containing my object information
content:
application/json:
schema:
"$ref": "#/components/schemas/MyObject"