Hi everyone!
Swagger is an awesome tool for easily creating an API documentation. But I've got an issue with image uploads from the Swagger UI.
The Swagger UI demo for the image upload is here:
http://petstore.swagger.wordnik.com/#!/pet/uploadFile_post_8The resource file for that demo is either the plain Scala or the Play 2 one:
https://github.com/wordnik/swagger-core/blob/master/samples/scala-jaxrs-fileupload/src/main/scala/com/wordnik/swagger/sample/resource/PetResource.scalahttps://github.com/wordnik/swagger-core/blob/master/samples/scala-play2/app/controllers/PetApiController.scalaOne is using the
@ApiImplicitParams annotation, the other isn't.
I'm developing in Java, so I looked for a corresponding example for Jersey or JaxRS:
https://github.com/wordnik/swagger-core/blob/master/samples/java-jaxrs/src/main/java/com/wordnik/swagger/sample/resource/PetResource.javahttps://github.com/wordnik/swagger-core/blob/master/samples/java-jersey2/src/main/java/com/wordnik/swagger/sample/resource/PetResource.javaNeither of the two has a method for image upload. I tried to adapt the code from the Scala examples, but didn't get it to work.
My Code is like this:
@POST
@Path( "images" )
@Produces( MediaType.APPLICATION_JSON )
@Consumes( MediaType.MULTIPART_FORM_DATA )
@ApiOperation(value = "Create a new image (Multipart)", notes = "<short explanation>")
public Response createNewImage(
@ApiParam( value = "Application name", required = true ) @PathParam( "appName" ) String appName,
@FormDataParam( "apiKey" ) String apiKey,
@FormDataParam( "file name" ) String fileName,
@FormDataParam( "file" ) InputStream uploadedInputStream )
{...}
This code works fine with curl like this:
curl -v -F "file=@googlelogo.png" -F "apiKey=123"
http://localhost:8080/path/MyApp/data/imagesBut it doesn't work with the Swagger UI "Try now!". When using that, I get this error:
java.lang.NullPointerException
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.unquoteMediaTypeParameters(MultiPartReaderClientSide.java:227)
Also, when trying to document the other FormDataParams with @ApiParam it results in 500 Internal Server Errors (don't have the stack trace at hand now - this is just of minor importance).
I'm using swagger-jersey-jaxrs_2.10 version 1.3.1.
Regarding the topic I read:
https://groups.google.com/forum/#!topic/swagger-swaggersocket/xJiG1etE3nshttps://github.com/wordnik/swagger-core/issues/184#issuecomment-17689042But trying out what was done there didn't help.
-> If someone could help me with my code snippet or maybe even create an image upload example for the pet store in java for the greater good, that would be awesome!