bw_dev
bw_dev

Reputation: 805

OpenAPI 3.0 - how to define file download operation correctly

I use online Swagger Editor with OpenAPI 3.0 and I have to create a definition file download. I develop server-side and a customer should be able to create a client using YAML description without my "addition explanation". The relevant part of YAML is:

/files/download/{fileName}:
get:
  summary: download file
  operationId: downloadFile
  description: this API is for file download
  parameters:
    - in: path
      name: fileName
      schema:
        type: string
      required: true
      description: The name of file to download
  responses:
    200:
      description: Operation performed successfully.
      content:
        application/octet-stream:
          schema:
            type: string
            format: binary
   ...

The questions are:

Upvotes: 37

Views: 15659

Answers (1)

Spacewink
Spacewink

Reputation: 155

I believe content is what you're looking for. You can also use contentReference to reference a reusable object in components. For example:

paths:
  /files/{fileName}:
    get:
      summary: download file
      operationId: downloadFile
      description: this API is for file download
      parameters:
        - in: path
          name: fileName
          schema:
            type: string
          required: true
          description: The name of file to download
      responses:
        200:
          description: Operation performed successfully.
          content:
            application/pdf:
              schema:
                type: string
                format: binary

components:
  contentTypes:
    application/pdf:
      schema:
        type: string
        format: binary

Upvotes: 1

Related Questions