Skip to content

Swagger-UI - Uncaught TypeError when response includes an attachment #2439

@nurandhawa

Description

@nurandhawa

Hi Guys.

I found an issue where the swagger ui would keep loading when the response of a GET request contains an attachment. The response headers include Content-Disposition →attachment; filename=example.txt and Content-Type →text/plain; charset=UTF-8 along some others.
The error that I was getting was this: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
To fix this, I had to make some changes in the swagger-ui.js.
@@ -23447,7 +23447,11 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({

     var type = contentType || 'text/html';
     var a = document.createElement('a');
     var href = window.URL.createObjectURL(content);
     var binaryData = [];
     binaryData.push(content);
     var href = window.URL.createObjectURL(new Blob(binaryData, {type: type}));
     var fileName = response.url.substr(response.url.lastIndexOf('/') + 1);
     var download = [type, fileName, href].join(':');

I am using swagger-ui-2.2.5. Can anyone confirm this error and if so, make the above mentioned changes and merge it?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions