swagger-api / swagger-api/swagger-ui

Accept header with multi content-type

Open
#5,649 12 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: try-it-out
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: ubuntu 18.04
  • Browser: chrome
  • Version: 77.0.3865.90
  • Swagger-UI version: 3.23.5
  • Swagger/OpenAPI version: Swagger 2.0.9, OpenAPI 3.0 (imported from org.springdoc:springdoc-openapi-ui:1.1.44)
Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'Test'
paths:
  /test:
    post:
      requestBody:
        content:
          multipart/form-data: # Media type
            schema:            # Request payload
              type: object
              properties:      # Request parts
                file:         #fichier
                  type: string
                  format: binary
                 schema:
                  type: string
      responses:
        '200':
          description: File generated
          content:
            application/xml:
              schema:
                type: string
                format: binary
        '406':
          description: Bad file
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Error:
      type: object
      properties:
        message:
          type: array
          items:
            type: string
          description: liste des messages d'erreur
        status:
          type: string
          description: status

Swagger-UI configuration options: i use default index.html file

Describe the bug you're encountering

With Swagger UI, when i made a request (with Try it out), only the content-type from the 200 Response (xml) is used to Accept Header, so when my request produce a 406 Response (json), I have a 500 Response because my backend can't match the content type json with the Accept headers (which has only content type "xml")

I think that the request has to have in the Accept Header all the content type from all the responses (or give a possibility to choose the Accept header)

Thank you ;)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Try it out request with the provided OpenAPI definition and inspect how Swagger UI builds the Accept header from the response content types. Done means the request can negotiate both the XML and JSON responses, or provides a documented way to choose the Accept value; the payload names no source files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.