question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger UI is sending wrong Accept header [Produces, text/plain, application/json]

See original GitHub issue

I 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.

image

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

image

And in devtools Console tab I get the following message:

image

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:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
webroncommented, Jun 22, 2017

I tested with the current UI and the snippet you provided. Both the GET and POST produce the right headers.

0reactions
crorafcommented, Jun 23, 2017

The issue was related to my use of the library. https://github.com/carlansley/swagger2-koa/issues/13

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found