swagger-ui hangs on big responses
Asked Answered
G

3

24

One of my endpoints returns a JSON (not huge, around 2MB). Trying to run GET on this endpoint in swagger-ui results in the browser hanging for a few minutes. After this time, it finally displays the JSON.

Is there a way to define that the response shouldn't be rendered but provided as a file to download instead?

I'm using OpenAPI 3, and I tried the following:

content:
    application/json:
        schema:
            type: string
            format: binary

taken from the documentation. Still, swagger-ui renders the response.

Has anyone had the same problem?

Genni answered 27/8, 2020 at 11:41 Comment(4)
Known issue: github.com/swagger-api/swagger-ui/issues/3832, github.com/swagger-api/swagger-ui/issues/6206, github.com/swagger-api/swagger-ui/issues/6202Jefferey
saw these ones, so it seems there is no solution for nowGenni
Check github.com/swagger-api/swagger-ui/issues/… - by setting the Content-Disposition header, it is possible to control the download behaviour. Works for us.Embalm
Problem is known for more than 5 years know. Still not fixed :(Muddle
D
22

Lex45x proposes in this github issue to disable syntax highlighting. In ASP.Net Core you can do this with

app.UseSwaggerUI(config =>
{
    config.ConfigObject.AdditionalItems["syntaxHighlight"] = new Dictionary<string, object>
    {
        ["activated"] = false
    };
});

This significantly improves render performance.

Deliciadelicious answered 10/2, 2022 at 15:40 Comment(2)
How do I add the syntaxHighlight false for the OpenAPI Quarkus service? I am facing a problem so I tried a couple of things but still not working. Can you please have a look at this post? https://mcmap.net/q/583382/-how-to-configure-swagger-ui-to-display-results-as-and-when-received-asynchronously-instead-of-waiting-for-the-complete-results/7584240Sliver
I love you, Peter. You helped me soo much.Ilowell
I
2

The equivalent to PeterB's answer on newer versions of NSwag (using UseSwaggerUI3) looks like this:

app.UseSwaggerUi3(settings =>
{
   settings.AdditionalSettings.Add("syntaxHighlight", false);
});
Inadvertent answered 8/9, 2022 at 13:40 Comment(1)
How do I add the syntaxHighlight false for the OpenAPI Quarkus service? I am facing a problem so I tried a couple of things but still not working. Can you please have a look at this post? https://mcmap.net/q/583382/-how-to-configure-swagger-ui-to-display-results-as-and-when-received-asynchronously-instead-of-waiting-for-the-complete-results/7584240Sliver
D
2

The equivalent in spring-boot, if using SpringDoc-openapi, is to add this to your application.yml

springdoc:
  swagger-ui:
    syntaxHighlight:
      activated: false

Here's the link to the official docs: https://springdoc.org/#swagger-ui-properties

Drais answered 6/4, 2023 at 14:16 Comment(1)
This solution works perfectly fine. Thank you!Bioecology

© 2022 - 2024 — McMap. All rights reserved.