xiaodongw / swagger-finatra

Finatra Swagger Support
Apache License 2.0
46 stars 45 forks source link

File formParam #20

Open dayyan opened 7 years ago

dayyan commented 7 years ago

Unless I'm doing this incorrectly, seems like file upload isn't supported yet.

Example in pet store: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/PetApi.scala#L128-L133

Example in ui: http://petstore.swagger.io/#!/pet/uploadFile

I've tried both a case class with a dataType file, and specifying File as the TypeTag.

xiaodongw commented 7 years ago

Can you provide the sample code of doing file upload with Finatra?

dayyan commented 7 years ago

Here's what I tried:

postWithDoc("/file") { o =>
   o.summary("Submit a new file.")
    .formParam[File]("file")
    .bodyParam[Metadata](name = "Metadata", description = "Metadata on the binary.")
 } { request: Request => response.ok.toFuture }

I also tried:

case class ApplicationBinary(
   @ApiModelProperty(dataType = "java.io.File")
   fileToUpload: java.io.File
)

And using that as the dataType.

xiaodongw commented 7 years ago

I cannot find any example about how to do file upload with Finatra. Your example having a File field in case class, will this work? Can you provide a full example about handling the file upload, not just the swagger part?

forthy commented 7 years ago

@xiaodongw Finatra uses RequestUtils to handle file upload.

dayyan commented 7 years ago

Sorry for the delay. This is how I process in a nutshell:

  postWithDoc("/file") { o =>
    o.summary("submit a new file")
     .produces("application/json")
     // examples don't work.
     .formParam[File](name = "file", description = "binary to upload", true)
     .consumes("multipart/form-data")
     .responseWith(...
  } { request: Request =>
    val params = RequestUtils.multiParams(request)
    ourService.submitBinary(formRequest.file, formRequest.filename)
    ...