swagger-ui hangs on big responses

Viewed 5651

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?

2 Answers

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.

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

app.UseSwaggerUi3(settings =>
{
   settings.AdditionalSettings.Add("syntaxHighlight", false);
});
Related