Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model OpenAPI 2.0 file download, type string:binary vs. type file

I'm a little confused how to model a file download with Swagger/OpenAPI v2. Take this small example:

/files/{name}.zip:
  get:
    summary: Returns the requested ZIP file as "file download" i.e. with content-disposition = attachment
    produces:
      - application/zip
    parameters:
      - name: name
        in: path
        required: true
        type: string
    responses:
      200:
        description: OK
        schema:
          type: file      # <- what is it?
        headers:
          Content-Disposition:
            type: string
            description: the value is `attachment; filename="name.zip"`

What do I use as response type? Is it type: string & format: binary or simply type: file?

I was looking at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types and https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#response-object (response data type file) but it isn't clear to me how the two are different. Which should be used when?

Also, does the use of the Content-Disposition header make a difference for choosing one or the other?

Note to self, also looked at

  • https://github.com/OAI/OpenAPI-Specification/issues/430
  • https://github.com/OAI/OpenAPI-Specification/issues/50
  • https://github.com/swagger-api/swagger-codegen/issues/319#issuecomment-113880278
like image 232
Marcel Stör Avatar asked Jun 13 '26 02:06

Marcel Stör


1 Answers

In a private conversation with the OpenAPI folks on gitter.im I was told the following.

In OAS v3, file has been replaced by type: string, format: binary instead so if you're planning to upgrade your spec to OAS v3 eventually, i would suggest you use binary from now on

like image 116
Marcel Stör Avatar answered Jun 18 '26 00:06

Marcel Stör



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!