Swagger-ui: Generate a link to download a file rather than automatically downloading it

Created on 3 Jul 2020  路  4Comments  路  Source: swagger-api/swagger-ui

Q&A (please complete the following information)

  • OS: Fedora
  • Browser: Firefox
  • Version: Latest
  • Method of installation: standalone dist
  • Swagger-UI version: latest (3.28.0)
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

N/A

Screenshots

N/A

How can we help?

Considering an API that returns a stream of data (XML or JSON) as a file Content-disposition: attachment;filename=xxx.json.

We would like Swagger to generate:

  • the cURL command :heavy_check_mark:
  • the request URL :heavy_check_mark:
  • and a "download" button but we would like Swagger to NOT actually do the call automatically because the file is big (potentially hundreds of MB) and it makes the Swagger UI freeze :negative_squared_cross_mark: , OR just keep the execute but download the file through the browser native mechanism (asking for "save vs open..")

Is it something possible?

Thank you for any response :)

support

Most helpful comment

For anyone interested, we ended up using the userFetch attribute that you can set on a Swagger request (using a requestInterceptor). See https://github.com/swagger-api/swagger-js/blob/master/docs/usage/http-client.md#custom-fetch.

With this custom fetch method, we used StreamSaver.js library.

Quite elegant and working fine although we would have loved some kind of native support.

All 4 comments

Kinda related to #6206

To complete my original question: what we would want is actually to handle the download file through the browser native download popup.

Maybe something we can achieve with a plugin?
I've read the doc about plugins but it feels quite hard to know in which direction to look without knowing the internals of Swagger UI.

Giving it a second thought, I think this is not possible anyway because if you need to send headers, a basic "download link" won't work.

And I don't know if there is a way to trigger the "Save as" dialog from Javascript?
Maybe with the Download API

For anyone interested, we ended up using the userFetch attribute that you can set on a Swagger request (using a requestInterceptor). See https://github.com/swagger-api/swagger-js/blob/master/docs/usage/http-client.md#custom-fetch.

With this custom fetch method, we used StreamSaver.js library.

Quite elegant and working fine although we would have loved some kind of native support.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

easyest picture easyest  路  3Comments

DavidBiesack picture DavidBiesack  路  4Comments

liuya05 picture liuya05  路  3Comments

Deraen picture Deraen  路  4Comments

fehguy picture fehguy  路  3Comments