4

We are working on Swagger Documentation for our Laravel REST API implementation. Several of the POST endpoints will use CSV as the parameter content type.

Is there a way in Swagger to have the "Try It Now" function work with a CSV POST file upload?

Below is our documentation in progress http://api.curvecompass.com/docs/#/

We have the Laravel POST function working correctly with the CSV endpoint, just not the Swagger docs.

mwex501
  • 492
  • 1
  • 8
  • 23
  • Does https://stackoverflow.com/questions/14455408/how-to-post-files-in-swagger point you in the right direction? – ceejayoz Feb 13 '18 at 15:25
  • You are using Swagger 2.0 or Swagger 3.0? – Tarun Lalwani Feb 13 '18 at 19:54
  • @TarunLalwani 3.0 – mwex501 Feb 14 '18 at 02:49
  • Just to clarify - do you mean that 1) an operation consumes `Content-Type: text/csv` and the response body is text formatted as CSV; 2) an operation is a file upload request ([`multipart/form-data`](https://stackoverflow.com/q/8659808/113116)) that expects a CSV file as part of the multipart payload? – Helen Feb 14 '18 at 20:21
  • @Helen Currently we use Laravel - we built an endpoint that accepts an HTML POST file that contains the CSV data. We want to add "Try It Now" functionality to our Swagger documentation that will accept a CSV file into the form data and pass it to the Laravel end point for ingestion. – mwex501 Feb 14 '18 at 23:46

2 Answers2

0

swagger ui for open api 3.0 does not support file upload yet. you can watch the update here https://github.com/swagger-api/swagger-ui/issues/3641

bhill77
  • 865
  • 11
  • 12
  • That stinks. At this point I'd be willing to accept a hack if anyone has one to offer. Otherwise I'll just hack it myself. Thanks for the info. – mwex501 Feb 17 '18 at 20:12
0

You can try this.

consumes:
    - multipart/form-data  # and/or application/x-www-form-urlencoded
  parameters:
    - name: file
      in: formData
      description: The uploaded file data
      required: true
      type: file
Pratik Mehta
  • 707
  • 8
  • 27