swaggerswagger-uiswashbuckleswashbuckle.aspnetcore

Toggle document expansion in Swagger/Swashbuckle


To configure whether the Swagger sections are initially collapsed or not, I can use SwaggerUIOptions.DocExpansion. But is it possible to add a link or button to the page that expands or collapses all sections?

Previously, it was possible to add a query parameter docExpansion={expansion mode} to the URL (see this answer). But this does not seem to work anymore.


Solution

  • Previously, it was possible to add a query parameter docExpansion={expansion mode} to the URL (see this answer). But this does not seem to work anymore.

    Swagger UI v. 4.1.3+ ignores its query parameters by default for security reasons. To enable query parameter processing, you need to configure Swagger UI with the queryConfigEnabled: true option.

    In Swashbuckle.AspNetCore, you can configure this option as suggested here:

    app.UseSwaggerUI(c =>
    {
        ...
        c.ConfigObject.AdditionalItems["queryConfigEnabled"] = true
    }