【问题标题】:Incomplete Swagger documentation for SpringBoot endpoint with MultipartFile parameter带有 MultipartFile 参数的 Spring Boot 端点的 Swagger 文档不完整
【发布时间】:2020-04-25 18:53:46
【问题描述】:

我使用 Swagger 和 SprintBoot 来生成端点文档,它运行良好,但有一个例外:我有一个带有 MultipartFile 参数的 POST 端点。在这种情况下,Swagger 会生成文档,但不会生成示例值(它是空的)。

public String create(@ApiParam(value = "Record to be created", required = true, type = "json", format = "json")
        @RequestPart(name = "candidate") MyDto record,
        @ApiParam(value = "File associated to the record", required = false)
        @RequestPart(value = "file", required = false) MultipartFile file) throws Exception 

如果没有 MultipartFile,Example Value 显示了可以使用的 JSON 示例。当包含一个额外的(可选的)MultipartFile 参数时,我希望拥有相同的参数。

这个问题可以解决吗?

【问题讨论】:

    标签: java spring-boot swagger


    【解决方案1】:

    据我所知,在添加类似这样的注释时可以放置 swagger 文档:

    @ApiModel(value="MyFile")
    public class MyFile{
    
      @ApiModelProperty(value = "originalFileName", example="The original filename")
      private String getOriginalFilename;
    
      [...]
    }
    

    我建议扩展 MultipartFile 对象并添加此注释。因此,您也可以将文档添加到参数和可选参数。

    附: MultipartFile 是一个接口,因此您必须扩展其中一个实现,例如CommonsMultipart 文件。比你必须在你的项目中包含 org.apache.commons.fileupload 依赖项(对于 FileItem)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2021-11-12
      • 2023-03-12
      • 2016-03-05
      • 1970-01-01
      相关资源
      最近更新 更多