Operation Example Mismatch Produces MimeType
- Query id: 2cf35b40-ded3-43d6-9633-c8dcc8bcc822
- Query name: Operation Example Mismatch Produces MimeType
- Platform: OpenAPI
- Severity: Info
- Category: Structure and Semantics
- URL: Github
Description¶
Example should match one of MimeTypes on 'produces'. It is important to know that, if a 'produces' is declared on operation it will override global 'produces'
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Postitive test num. 1 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "limit2",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
],
"operationId": "listVersionsv2",
"summary": "List API versions",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "OK",
"examples": {
"application/json": {
"id": 38,
"title": "Versions"
},
"text/csv": "id,title 38,Versions"
}
}
}
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
}
}
Postitive test num. 2 - yaml file
---
swagger: '2.0'
info:
title: Simple API Overview
version: 1.0.0
paths:
"/":
get:
parameters:
- name: limit2
in: body
description: max records to return
required: true
schema:
type: integer
operationId: listVersionsv2
summary: List API versions
produces:
- application/json
responses:
'200':
description: OK
examples:
application/json:
id: 38
title: Versions
text/csv: id,title 38,Versions
parameters:
limitParam:
name: limit
in: body
description: max records to return
required: true
schema:
type: integer
Code samples without security vulnerabilities¶
Negative test num. 1 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "limit2",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
],
"operationId": "listVersionsv2",
"summary": "List API versions",
"produces": [
"application/json",
"text/csv"
],
"responses": {
"200": {
"description": "OK",
"examples": {
"application/json": {
"id": 38,
"title": "Versions"
},
"text/csv": "id,title 38,Versions"
}
}
}
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
}
}
Negative test num. 2 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "limit2",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
],
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "OK",
"examples": {
"application/json": {
"id": 38,
"title": "Versions"
},
"text/csv": "id,title 38,Versions"
}
}
}
}
}
},
"produces": [
"application/json",
"text/csv"
],
"parameters": {
"limitParam": {
"name": "limit",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "integer"
}
}
}
}
Negative test num. 3 - yaml file
swagger: '2.0'
info:
title: Simple API Overview
version: 1.0.0
paths:
"/":
get:
parameters:
- name: limit2
in: body
description: max records to return
required: true
schema:
type: integer
operationId: listVersionsv2
summary: List API versions
produces:
- application/json
- text/csv
responses:
'200':
description: OK
examples:
application/json:
id: 38
title: Versions
text/csv: id,title 38,Versions
parameters:
limitParam:
name: limit
in: body
description: max records to return
required: true
schema:
type: integer
Negative test num. 4 - yaml file
---
swagger: '2.0'
info:
title: Simple API Overview
version: 1.0.0
paths:
"/":
get:
parameters:
- name: limit2
in: body
description: max records to return
required: true
schema:
type: integer
operationId: listVersionsv2
summary: List API versions
responses:
'200':
description: OK
examples:
application/json:
id: 38
title: Versions
text/csv: id,title 38,Versions
produces:
- application/json
- text/csv
parameters:
limitParam:
name: limit
in: body
description: max records to return
required: true
schema:
type: integer