mlapeyre mlapeyre - 1 month ago 12
Java Question

How to generate file chooser in Swagger-ui for body inpustream

Hello i have the following jaxrs entry


@PUT()
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@ApiOperation(value = "Bla bla.")
@Path("secure/flappy")
public Response testput(
@ApiParam(value = "pwet",type = "file",format = "binary", required = true) InputStream certificate) throws Throwable {
try (InputStream stream = certificate) {
//Consume stream
return Response.ok().build();
}
}


And the generated swagger-ui page for this entryenter image description here

I would like to know how to document my paremeter for getting only one parameter presented as a file chooser in swagger-ui.

Answer Source

@sdc: You're right i had to use multi part form data for getting a working file chooser in Swagger-ui. I also had to use @ApiImplicitParam for getting it working.

@PUT()
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Bla bla.")
@Path("secure/flappy")
@ApiImplicitParams({
    @ApiImplicitParam(name = "file", value = "bla bla.", required = true, dataType = "java.io.File", paramType = "form")
})
public Response testput(@ApiParam(hidden = true) @FormDataParam("file") final  InputStream certificate
) throws Throwable {
    //TODO do something
    return Response.ok().build();
}