swagger-ui and multipart form file uploads

4,409 views
Skip to first unread message

Horaci Macias

unread,
Nov 23, 2016, 7:30:33 AM11/23/16
to Swagger
Hi everybody,

I'm trying to use swagger-ui and annotations to document my REST java backed.
For some reason the generated swagger.json has a duplicate parameter for the file.

If I use the following java code/annotations:

@POST
@Path("/fileupload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
value = "Imports CSV file",
notes = "Bulk imports all users from CSV file into database."
)
@ApiResponses({
@ApiResponse(code = 200, message = "Import successful"),
@ApiResponse(code = 500, message= "Error importing file")
})
@ApiImplicitParams(@ApiImplicitParam(dataType = "file", name = "upload", paramType = "formData", required = true))
public Response uploadFile(@ApiParam(hidden = true, name = "upload") @FormParam("upload") File upload) {

this is the json generated:

    "/users/fileupload" : {
      "post" : {
        "tags" : [ "Users" ],
        "summary" : "Imports CSV file",
        "description" : "Bulk imports all users from CSV file into database.",
        "operationId" : "uploadFile",
        "consumes" : [ "multipart/form-data" ],
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "upload",
          "in" : "formData",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "upload",
          "in" : "formData",
          "required" : true,
          "type" : "file"
        } ],
        "responses" : {
          "200" : {
            "description" : "Import successful"
          },
          "500" : {
            "description" : "Error importing file"
          }
        }
      }
    },

which swagger-ui shows as a duplicate parameter, one being required (the file upload which is the only one I want to see) and another non-required of data type "String":

Does anybody have a working example of this same scenario? how can I make sure swagger-ui just shows a single "upload" parameter of type "file" ?


thanks,


H


Ron Ratovsky

unread,
Nov 23, 2016, 1:45:23 PM11/23/16
to swagger-sw...@googlegroups.com

Which version of swagger-core are you using?

--
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.

Horaci Macias

unread,
Nov 23, 2016, 3:41:08 PM11/23/16
to swagger-sw...@googlegroups.com
Hi Ron,

I'm using swagger-jaxrs 1.5.10, swagger-ui 2.2.6 (from org.webjars which I then embed on my war file) and I'm generating the swagger.json file from maven, using swagger-maven-plugin (com.github.kongchen) 3.1.0.

thanks,

H

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Nov 23, 2016, 3:45:30 PM11/23/16
to swagger-sw...@googlegroups.com

You’d probably have to file a ticket on the maven plugin then, as it does the annotation introspection and probably ignores the ‘hidden’ property.

--

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.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.

To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

 

--

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.

Horaci Macias

unread,
Nov 23, 2016, 4:56:51 PM11/23/16
to swagger-sw...@googlegroups.com
thank you Ron, I'll follow that approach.

H

--

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.

To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
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-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Horaci Macias

unread,
Nov 23, 2016, 5:03:05 PM11/23/16
to swagger-sw...@googlegroups.com
in case this helps anybody, I noticed there was a newer version of swagger-maven-plugin (3.1.4) and that seems to work as expected.

thanks Ron for the help.

H

--

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.

To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
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-swaggersocket+unsubscri...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/_ZvVuNweJwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages