您好我有以下jaxrs条目
@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();
}
}
我想知道如何记录我的参数,只能在swagger-ui中将一个参数作为文件选择器显示。
答案 0 :(得分:0)
我对Swagger UI不太熟悉,但这个帖子可能会有所帮助
https://github.com/swagger-api/swagger-ui/issues/72
我看到使用@ApiParam
注释
这篇文章谈到了一个文件上传
def uploadFile
注释
https://github.com/swagger-api/swagger-ui/issues/169
@PUT
@Path("/secure/flappy")
@Consumes(Array(MediaType.MULTIPART_FORM_DATA))
@ApiOperation(value = "test a put file upload")
def uploadFile(
@ApiParam(value = "file to upload", required=false) @FormDataParam("file") inputStream: InputStream,
@ApiParam(value = "file detail") @FormDataParam("file") fileDetail: FormDataContentDisposition) = {
val uploadedFileLocation = "./" + fileDetail.getFileName
IOUtils.copy(inputStream, new FileOutputStream(uploadedFileLocation))
val msg = "File uploaded to " + uploadedFileLocation + ", " + (new java.io.File(uploadedFileLocation)).length + " bytes"
val output = new com.wordnik.swagger.sample.model.ApiResponse(200, msg)
Response.status(200).entity(output).build()
}
答案 1 :(得分:0)
@sdc:你说得对,我必须使用多部分表单数据来获取Swagger-ui中的工作文件选择器。我还必须使用@ApiImplicitParam来使其正常工作。
@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();
}