Components Example Definition Is Unused
- Query id: b05bb927-2df5-43cc-8d7b-6825c0e71625
- Query name: Components Example Definition Is Unused
- Platform: OpenAPI
- Severity: Info
- Category: Best Practices
- URL: Github
Description¶
Components examples 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": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
},
"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"
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