swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

TypeError: e.split is not a function in v4.12.0

Open IgorMamushin opened this issue 2 years ago • 3 comments

  • OS: Windows 10 Version 22H2
  • Browser: Chrome
  • Version: 110.0.5481.178
  • Method of installation: Nuget
  • Swagger-UI version: 4.12.0
  • OpenAPI version: OpenAPI 3.0.1

I cannot download .xlsx file via swagger UI. But before update it has worked filne. I updated lib for .net wich uptdated Swagger UI from 3.47.1 to 4.12.0. And now i am getting the error "TypeError: e.split is not a function". I have tried add header "Content-Disposition: attachment" and it doesn't work.

I changed media type from "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" to "application/octet-stream" and it works, but i get unknown type of file as well.

image image

Any idea what i can do?

IgorMamushin avatar Feb 28 '23 09:02 IgorMamushin

Hi @IgorMamushin,

Can yo provide a minimal OpenAPI definition + Steps of Reproduction where we can see this manifesting?

Thanks

char0n avatar Mar 01 '23 10:03 char0n

Hi.

It doesn't work in huge project, I cannot share OpenAPI definition here.

I've tried to create pet project. But it works fine there! I'll try to figure out how to reproduce it. I will let know, when i finde the problem

IgorMamushin avatar Mar 03 '23 05:03 IgorMamushin

I'm seeing this too., and it seems to have been around for a while, see #4955. That exlains why it happens, but it would be very useful to get some kind of a sane message from Swagger rather than the current behaviour (which also seems to prevent the "Curl" and "Request URL" windows from rendering).

Anyway, this is the stack trace I get (click on the little "Object" icon in the console.


    at ResponseBody (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1182729)
    at td
    at tr
    at tbody
    at table
    at div
    at LiveResponse (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1156811)
    at div
    at div
    at div
    at responses_Responses (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1175298)
    at ErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1133412)
    at WithErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1132626)
    at div
    at div
    at NoMargin (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1206868)
    at Collapse (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1206931)
    at div
    at operation_Operation (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1163735)
    at span
    at OperationWrapper (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:688812)
    at OperationContainer (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1168277)
    at ErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1133412)
    at WithErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1132626)
    at WithSystem (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1098804)
    at ConnectFunction (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1095767)
    at div
    at div
    at NoMargin (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1206868)
    at Collapse (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1206931)
    at div
    at OperationTag (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1162115)
    at span
    at OperationTagWrapper (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:689144)
    at div
    at Operations (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1160606)
    at WithSystem (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1098804)
    at ConnectFunction (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1095767)
    at section
    at Col (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1204883)
    at div
    at Row (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1205368)
    at div
    at version_pragma_filter (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1358772)
    at div
    at BaseLayout (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1324536)
    at ErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1133412)
    at WithErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1132626)
    at WithSystem (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1098804)
    at ConnectFunction (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1095767)
    at App (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1134242)
    at ErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1133412)
    at WithErrorBoundary (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1132626)
    at WithSystem (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1098804)
    at ConnectFunction (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1095767)
    at Provider (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1098066)
    at WithRoot (http://192.168.1.108:8000/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js:2:1099031)

I'm not JS-enabled, but it looks as though the failure is in the lines below https://github.com/swagger-api/swagger-ui/blob/8e6824cb452ae4b268f45f5203575194217c6653/src/core/components/response-body.jsx#L62 . The headers in my case (as reported by curl) look like this:

< HTTP/1.1 200 OK
< Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
< Content-Length: 104524
< Content-Disposition: inline;filename="Finance Journal.xlsx"
< Vary: Accept, Accept-Language, Cookie
< Allow: GET, HEAD, OPTIONS
< Content-Security-Policy: img-src * data:; frame-ancestors 'self'; font-src 'self' data: https://fonts.gstatic.com; default-src 'self' 'unsafe-inline' 'unsafe-eval' http://unpkg.com https://fonts.googleapis.com http://netdna.bootstrapcdn.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com
< X-Frame-Options: DENY
< Content-Language: en-gb
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Cross-Origin-Opener-Policy: same-origin
< Set-Cookie: sessionid=i2h9y3808qd9ple9wh43pw6chpxwpbg9; expires=Sat, 27 Jul 2024 00:06:42 GMT; HttpOnly; Max-Age=3600; Path=/
< Server: daphne

My guess is that it the these tests fail on my Content-Disposition "inline":

        (headers["Content-Disposition"] && /attachment/i.test(headers["Content-Disposition"])) ||
        (headers["content-disposition"] && /attachment/i.test(headers["content-disposition"])) ||
        (headers["Content-Description"] && /File Transfer/i.test(headers["Content-Description"])) ||
        (headers["content-description"] && /File Transfer/i.test(headers["content-description"]))) &&

and so the code ends up walking down the "else" where the presence of the magic letters "xml" in "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" causes an attempt to parse the XLSX file as unzipped XML here:

body = formatXml(content, {
        textNodesOnSameLine: true,
        indentor: "  "
      })

and thus ends up blowing up.

ShaheedHaque avatar Jul 26 '24 22:07 ShaheedHaque