Swagger UI不支持为RestEasy正确上传文件 [英] Swagger UI doesn't support uploading a file properly for RestEasy

查看:162
本文介绍了Swagger UI不支持为RestEasy正确上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将JAX-RS(RestEasy)与Swagger一起使用.我的一个端点可以上传文件.上载文件的定义方式(在RestEasy中)是提供org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput作为参数.

I use a JAX-RS (RestEasy) along with a Swagger. One of my endpoint can upload a file. Defined way to upload the file (in RestEasy) is to provide a org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput as a parameter.

这是我的终点:

@PUT
@Path("/apis/{id}/file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Registers a file.", code = 201, nickname = "registerFile")
@ApiResponses(
    value = {
        @ApiResponse(code = 201, message = "File created.",
                     response = FileCreated.class),
        @ApiResponse(code = 400, message = "Invalid parameters."),
        @ApiResponse(code = 404, message = "API is not found.")})
Response registerFile(
    @ApiParam(value = "API ID.", required = true) @PathParam("id") String apiId,
    @ApiParam(value = "File to register.", required = true, type = "file", name = "apiFile")
        MultipartFormDataInput apiFile) throws AppException;

出什么问题了?

不幸的是,swagger-ui会基于MultipartFormDataInput的内部属性而不是用于上传文件的按钮来生成模式. 我尝试使用@FormParam批注(指示应该将提供的参数解释为文件)与MultipartFormDataInput参数一起使用,但是应用程序不想编译.

What is the problem?

Unfortunately, swagger-ui generates a schema based on the inner properties of the MultipartFormDataInput instead of a button to upload the file. I tried use a @FormParam annotation (to indicate that the providing parameter should be interpreted as file) along with the MultipartFormDataInput parameter, but then the app doesn't want to compile.

问题:是否有任何解决方案/解决方法可提供在swagger-ui中上传文件的按钮?

Question: Is there any solution/workaround to provide the button to upload the file in the swagger-ui?

推荐答案

该解决方案是从apiFile参数中删除@ApiParam,并在该文件上方添加@ApiImplicitParam(该值未绑定到Jax-RS,允许手动定义参数).方法:

The solution is removing @ApiParam from your apiFile argument and adding @ApiImplicitParam (which is not bound to Jax-RS and allows defining parameters manually) above the method :

@ApiImplicitParams({@ApiImplicitParam (value = "File to register.", required = true, dataType = "file", name = "apiFile", paramType="formData")})

这篇关于Swagger UI不支持为RestEasy正确上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆