swagger-api / swagger-api/swagger-ui

Live response rendering can fail after large request body returns 413

Open
#10,900 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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: macOS / Linux
  • Browser: Chrome / Chromium
  • Method of installation: springdoc-openapi webjar
  • Swagger-UI version: 5.28.0
  • Swagger/OpenAPI version: OpenAPI 3.1
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
paths:
  /render:
    post:
      requestBody:
        required: true
        content:
          application/xml:
            schema:
              type: string
      responses:
        "200":
          description: PDF rendered successfully
          content:
            application/pdf:
              schema:
                type: string
                format: binary
        "413":
          description: Request body too large
          content:
            application/problem+json:
              schema:
                type: object
                properties:
                  type:
                    type: string
                  title:
                    type: string
                  status:
                    type: integer
                  detail:
                    type: string
                  instance:
                    type: string

Swagger-UI configuration options:

SwaggerUI({
  showMutatedRequest: true
})
Describe the bug you're encountering

When using "Try it out" with a large XML request body, the backend correctly returns HTTP 413 with application/problem+json.

Instead of rendering the live response reliably, Swagger UI can show:

😱 Could not render responses_Responses, see the console.

The response itself is valid. The failure appears to happen in Swagger UI's live response rendering path, where the sent request body is rendered again in the cURL/request display area.

To reproduce...
  1. Define an endpoint that accepts application/xml request bodies.
  2. Return HTTP 413 with application/problem+json when the request exceeds a server-side limit.
  3. Open the endpoint in Swagger UI.
  4. Click "Try it out".
  5. Paste/send a very large XML request body, e.g. several MB.
  6. Observe that the backend returns a valid 413 response.
  7. Swagger UI may render Could not render responses_Responses instead of the response details.
Expected behavior

Swagger UI should render the 413 response body and headers normally.

If the request body is too large to safely render in the live response/cURL block, Swagger UI should truncate or virtualize only the displayed copy of the request body. The actual request sent to the server should remain unchanged.

Additional context or thoughts

We worked around this locally by truncating only the display copy of the request body used in the live response/cURL rendering path. The original request is still sent unchanged.

A possible upstream improvement would be a built-in display limit for request bodies in live response/cURL rendering, for example a configurable maxDisplayedRequestBodyChars, plus defensive handling when the mutated request is not available.

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 tracing Swagger UI's live response and cURL/request display rendering path, especially the handling of showMutatedRequest, using the large XML request and 413 response described here. Confirm that the display copy can be limited or handled defensively while the original request remains unchanged, and verify that the 413 body and headers render normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.