Swagger UI is sending wrong Accept header [Produces, text/plain, application/json]
See original GitHub issueI set produces to application/json, and try to use swagger UI to send a get request. But Swagger UI is sending text/plain Accept header.

What is even more strange, in devtools Network tab it is shown that Accept: application/json was sent.

And in devtools Console tab I get the following message:

The same error message is shown when I try to access this resource from the browser URL bar (but there I cannot set the Accept header).
swagger-ui version: 2.2.10
I tried all possible combinations in the swagger file, here is the relevant excerpt. /login path works fine.
swagger: '2.0'
info:
version: 1.0.0
title: Whole
description: >
Swagger
consumes:
- application/json
- text/plain
produces: [application/json]
basePath: '/api'
paths:
/login:
post:
tags: [Login]
description: Receives login credentials and returns token if credentials are valid
parameters:
- name: credentials
in: body
description: Credentials object with username and password
required: true
schema:
$ref: '#/definitions/credentials'
responses:
'200':
description: Valid token
schema:
$ref: "#/definitions/token"
default:
description: unexpected error
schema:
type: object
/ingredients:
get:
tags: [Ingredients]
description: Retrieves a list
parameters: []
responses:
'200':
description: Array of ingredients
schema:
type: array
items:
type: string
Similar issue is this one, but was closed without discussion: #2450 NOTE: I’m using node.js swagger2-koa to bind swagger.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
NET Service reference sending wrong accept header (text/plain)
Let's assume you client send Accept-Header which support both text/xml and text/plain (which as i understand here, you expect a response as ...
Read more >Describing Responses - Swagger
JSON is the most common format for data exchange, but not the only one possible. To specify the response media types, use the...
Read more >MIME Types - Swagger
MIME Types. An API can accept and return data in different formats, the most common being JSON and XML. You can use the...
Read more >Media Types - Swagger
Media type is a format of a request or response body data. ... can accept and return data in different formats, the most...
Read more >Describing Request Body - Swagger
There can be only one body parameter, although the operation may have other parameters (path, query, header). Note: The payload of the application/x-www-form- ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I tested with the current UI and the snippet you provided. Both the GET and POST produce the right headers.
The issue was related to my use of the library. https://github.com/carlansley/swagger2-koa/issues/13