Request Body JSON Reference Does Not Exists
- Query id: ca02f4e8-d3ae-4832-b7db-bb037516d9e7
- Query name: Request Body JSON Reference Does Not Exists
- Platform: OpenAPI
- Severity: Info
- Category: Structure and Semantics
- URL: Github
Description¶
Request Body reference should exists on components field
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"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"$ref": "#/components/schemas/MyObject"
}
},
"requestBody": {
"$ref": "#/components/requestBodies/MyWrongObjectBody"
}
}
}
},
"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"
}
}
}
}
}
}
}
Postitive 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/MyWrongObjectBody"
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"