Enhance presentation for MULTIPART_FORM_DATA ?

109 views
Skip to first unread message

Bastien Tresse

unread,
Oct 2, 2015, 9:10:51 AM10/2/15
to Swagger
Hello,

Everybody knows that it gets a bit tedious when it comes to play with WebServices and file upload.

More often than not, we got to send more data then just a file to the webservice. It is our case, with have a JSON object to send as well.

Please have a look at the webservice declaration : 

@POST
@Path("/{numDemande}/taches/traiter")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Traite une tâche.")
RetourTraiterTache traiterTache(@ApiParam("Numéro de demande") @PathParam("numDemande") String numDemande, 
@ApiParam("Pièce jointe") @FormDataParam("file") InputStream file, 
@FormDataParam("file") FormDataContentDisposition fileDetail, 
@ApiParam(hidden = true) @FormDataParam("file") FormDataBodyPart fileBody,
@ApiParam(value = "Représentation string du JSON de l'objet TraitementTache", required = true) @FormDataParam("traitementTacheJson") String traitementTacheJson, 
@ApiParam("Identifiant utilisateur") @QueryParam("login") String login) throws PortailDistributeurException;

In swagger, it generates something like this :


As you can see, the only way to pass an object to the Multipart-form-data webservice is to give its string representation. But in swagger, for those who use it, it's not easy to type the "traitementTacheJson".


Is there a way to display this kind of data with dataType = "body" ?

We tried to hide "traitementTacheJson" and add an implicitParam with the same name and dataType = "body", but the resquests weren't working anymore.


We would like to have the same presentation as below (with parameter content type=multipart-form-data, of course)




Ron Ratovsky

unread,
Oct 2, 2015, 2:57:46 PM10/2/15
to Swagger
Hi Bastien!

I'm afraid there's no good news here, and I'll explain why.

What you're trying to do is actually support two file uploads - one is a binary, and the other is a text file.
While the binary has probably any mime type, the text file has the application/json mime type.
In Swagger, right now, it is not possible to restrict the mime type to a given file upload (see https://github.com/swagger-api/swagger-spec/issues/222).

The most you can do right now is either define it as a string, which has no type and can be pretty much anything (as you do now) or define it as a file which would indeed require you to pick a file.
There's no for us to know that this is in fact a json structure and that we should provide a form to fill it.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Bastien Tresse

unread,
Oct 2, 2015, 7:39:42 PM10/2/15
to Swagger
Thank you Ron for the clarification !

Too bad, maybe in a future version of Swagger then :)

Have a nice day.
Reply all
Reply to author
Forward
0 new messages