首页 文章

Swagger注释处理org.apache.cxf.jaxrs.ext.multipart.Attachment

提问于
浏览
1

我是一个开发REST API的过程,它接受文件并执行一些特定于业务的操作,因为我们使用的是apache cxf 3.1.0对于JAXRS植入, endpoints 自动采用Attachment而不是Inputstream

public Response sampleAPI(
            @ApiParam(value = "File to be uploaded.", required = true) 
            @Multipart(value = "file", required = true) Attachment file){
       // Some Logic 
     }

现在,由于我们需要使用swagger输出发布此API,因此它显示的是复杂类型附件 .

enter image description here

因此,任何需要发送文件的消费者都会得到一个印象,他需要使用CXF API将他的文件发送到 endpoints ,这对我们来说是一个问题 .

在swagger注释中是否有任何方法,或者我们可以将附件作为API中的参数更改为标准输入流,以便API的使用者不会感到困惑 .

1 回答

  • 1

    您可以在此处使用 @ApiImplicitParam 注释 .
    因此,对于您的问题中提到的代码段,以下内容应该有效

    @ApiImplicitParams({
          @ApiImplicitParam(name = "file", value = "File to be uploaded.", required = true, dataType = "file", paramType = "form")
      })
      public Response sampleAPI(
          @ApiParam(hidden = true) @Multipart(value = "file", required = true) Attachment file){
        // Some Logic 
      }
    

    请注意,我已将 Attachment 方法参数标记为 hidden ,因此swagger不会显示它,因为它正在显示给您 .

相关问题