Example JSON Reference Does Not Exist
- Query id: 6a2c219f-da5e-4745-941e-5ea8cde23356
- Query name: Example JSON Reference Does Not Exist
- Platform: OpenAPI
- Severity: Info
- Category: Structure and Semantics
- CWE: 20
- URL: Github
Description¶
Example reference should exist on components field
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": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
},
"examples": {
"objectExample": {
"$ref": "#/components/examples/wrongExample"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"examples": {
"objectExample": {
"value": {
"id": "1",
"name": "new object"
},
"summary": "A sample object"
}
}
}
}
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':
description: Success
content:
application/json:
schema:
"$ref": "#/components/schemas/MyObject"
examples:
objectExample:
"$ref": "#/components/examples/wrongExample"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
examples:
objectExample:
value:
id: '1'
name: new object
summary: A sample object
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": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
},
"examples": {
"objectExample": {
"$ref": "#/components/examples/objectExample"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"examples": {
"objectExample": {
"value": {
"id": "1",
"name": "new object"
},
"summary": "A sample object"
}
}
}
}
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':
description: Success
content:
application/json:
schema:
"$ref": "#/components/schemas/MyObject"
examples:
objectExample:
"$ref": "#/components/examples/objectExample"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
examples:
objectExample:
value:
id: '1'
name: new object
summary: A sample object