File uploads problem with RESTEasy

947 views
Skip to first unread message

john....@singlewire.com

unread,
Mar 20, 2014, 12:16:09 PM3/20/14
to swagger-sw...@googlegroups.com
Hello,

I'm currently developing a java REST api using RESTEasy and incorporating Swagger. I've run into a problem with implementing a file upload resource and having it appear correctly on the Swagger UI. The file chooser (browse button) will not be presented on my parameter. I've tried defining the data type on the parameter multiple ways, but the file chooser will not appear for the parameter. Here are a few data types that I've tried:
@MultipartForm FileUploadForm file
MultipartFormDataInput file
List<Attachment> attachments

I've also tried using this on the method:
 @ApiImplicitParams(@ApiImplicitParam(dataType = "file", name = "file", paramType = "body"))
which does display the file chooser, but does not associate it with the parameter, which means the Swagger UI ends up shows two input parameters.

How do I need to define my file upload parameter in order for Swagger to give me a file chooser for it?

Thanks.

john....@singlewire.com

unread,
Mar 24, 2014, 12:16:07 PM3/24/14
to swagger-sw...@googlegroups.com

More details:

Using the  @ApiImplicitParams on the method does in fact associate with the parameter, but there is still two input parameters on the Swagger UI. See attached screen shot.
I'm currently using the following to at least give a description on the parameter that tells the user to ignore:

    @POST
    @Path(CERTIFICATES_SERVICE)
    @Consumes("multipart/form-data")
    @Produces("application/json")
    @ApiOperation(
            value="Upload Certificate",
            notes="Upload a Certificate file.")
    @ApiImplicitParams(@ApiImplicitParam(
            dataType = "file",
            name = "uploadFile",
            value="Certificate file",
            paramType = "body"))
    public Response saveCertificate(
            @ApiParam(value = IGNORE_PARAM_DESC)
            MultipartFormDataInput form) throws Exception {
...
Is there any way I can tell Swagger to not show this parameter on the UI, but still retain the file chooser?

Thanks.


swaggerFileUpload.png

tony tam

unread,
Apr 7, 2014, 1:57:29 PM4/7/14
to swagger-sw...@googlegroups.com
Hi, you must be using the non jersey swagger scanner.  If you were, you woulnd't see the multi-part form data input.  Can you post how you've configured the server with swagger?  I'd expect this:


    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.wordnik.swagger.jaxrs.json;com.wordnik.swagger.sample.resource;com.wordnik.swagger.jersey.listing</param-value>
    </init-param>

john....@singlewire.com

unread,
Apr 7, 2014, 2:32:26 PM4/7/14
to swagger-sw...@googlegroups.com
We are using swagger in a RESTEasy environment, and not using Jersey.
Here is the tutorial that we used as an example to configure swagger with RESTEasy, and our configuration:


    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/RESTServices</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.providers</param-name>
        <param-value>
            com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider,
            com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,
            com.berbee.ipt.broadcastsystem.restservices.RESTExceptionHandler</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON</param-value>
    </context-param>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.berbee.ipt.broadcastsystem.restservices.RestApp</param-value>
        </init-param>
    </servlet>

    <servlet>
        <servlet-name>DefaultJaxrsConfig</servlet-name>
        <servlet-class>com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
        <init-param>
            <param-name>api.version</param-name>
            <param-value>1.0</param-value>
        </init-param>
        <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>/RESTServices</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/RESTServices/*</url-pattern>
        <url-pattern>/api-docs/*</url-pattern>
    </servlet-mapping>


Thanks for any input you can give.

tony tam

unread,
Apr 7, 2014, 2:55:36 PM4/7/14
to swagger-sw...@googlegroups.com
Hi, just change your dependency to include swagger-jersey-jaxrs instead of swagger-jaxrs, and update your Resteasy resources to this:

    <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.wordnik.swagger.jersey.listing.ApiListingResourceJSON</param-value>
    </context-param>
Reply all
Reply to author
Forward
0 new messages