【问题标题】:Swagger annotation to handle org.apache.cxf.jaxrs.ext.multipart.Attachment处理 org.apache.cxf.jaxrs.ext.multipart.Attachment 的 Swagger 注释
【发布时间】:2017-01-08 12:48:01
【问题描述】:

我正在开发一个接受文件并执行一些特定业务操作的 REST API 的过程,由于我们使用 apache cxf 3.1.0 进行 JAXRS 植入,端点自动采用 Attachment 而不是 Inputstream

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

现在我们需要使用 swagger 输出来发布这个 API,它显示的是复杂类型的附件。

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

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

【问题讨论】:

    标签: rest jax-rs cxf swagger swagger-2.0


    【解决方案1】:

    您可以在此处使用@ApiImplicitParam 注释。
    因此,对于您问题中提到的代码 sn-p,以下应该可以工作

      @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 不会显示它,因为它目前正在为您显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2018-05-05
      • 1970-01-01
      相关资源
      最近更新 更多