swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.29k stars 8.91k forks source link

Swagger UI freezes when processing a 1.5MB response #7687

Open ppazos opened 2 years ago

ppazos commented 2 years ago

Q&A (please complete the following information)

Content & configuration

openapi2.json.txt

The path GET /definition/template/adl1.4/{template_id} retrieves an XML that is 1.5 MB long.

Swagger-UI configuration options:

window.onload = function() {
        // Begin Swagger UI call region
        const ui = SwaggerUIBundle({
          url: "/assets/openapi2.json",
          dom_id: '#swagger-ui',
          deepLinking: true,
          presets: [
            SwaggerUIBundle.presets.apis//,
            //SwaggerUIStandalonePreset // commented to remove the topbar plugin
          ],
          plugins: [
            SwaggerUIBundle.plugins.DownloadUrl
          ]//,
          //layout: "StandaloneLayout" // commented to remove the topbar plugin
        });
        // End Swagger UI call region

        window.ui = ui;
      };

Describe the bug you're encountering

Call to the endpoint freezes the whole page and stays in "LOADING" forever.

Screenshot_2021-11-29_14-03-18

In the JS console I see this trace from highlight.js:

Script terminated by timeout at:
O@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:182485
C@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:182558
R<@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:185916
oi@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:790540
qi@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:800058
Hu@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:843753
Os@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:829987
ks@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:829915
Ss@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:829776
vs@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:826763
Jo/<@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:776435
t.unstable_runWithPriority@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:853474
Wo@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:776212
Jo@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:776382
$o@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:776315
gs@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:827084
notify@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:252413
O</t.notifyNestedSubs@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:253048
O</t.handleChangeWrapper@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:253116
p@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:946287
Ce/</</<@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:61301
$/<@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:946718
ze/</<@http://localhost:8095/assets/swagger-ui-bundle.js?compile=false:2:89982

Maybe this is not a swagger-ui issue per se, it seems the highlight lib doesn't have the power to handle the big XML.

Can highlight be disabled to test?

To reproduce...

The API is not public so it can't be reproduced publicly. Internally what I do is:

  1. Invoke the authentication endpoint
  2. Copy the token to the AUTHORIZATION button
  3. Invoke the list templates endpoint
  4. Copy the template id from the response
  5. Invoke the get template endpoint with the template id
  6. Everything freezes

Expected behavior

Avoid freezing.

Screenshots

See above.

Additional context or thoughts

Allow to disable the response highlight to test.

ppazos commented 2 years ago

Also see what highlight recommends about workers to avoid freezing the whole window https://github.com/highlightjs/highlight.js#using-web-workers

xiakunhou commented 1 year ago

Any plan to fix this issue? Meet the same problem here.

MarkDonovan51 commented 1 year ago

Also experiencing the same issue. Not a major problem, but a fix would be nice.

engFelipeMonteiro commented 1 year ago

still a problem in version 5.4.2, very impacting on usability