762 Star 6.6K Fork 1.4K

GVP萧明 / knife4j

 / 详情

某些情况不能正确识别 MediaType (swagger-ui/index.html 是正常的)

已完成
创建于  
2023-02-23 16:43

输入图片说明
如上图所示,JavaBean (包含一个 MultipartFile[] file 属性) 作为参数时,不能正确识别 MediaType 为 multipart/form-data

版本信息

springboot 2.2.7.RELEASE
springdoc-openapi-ui 1.6.9
knife4j-openapi3-spring-boot-starter 4.0.0

重现步骤

knife4j 效果图 (正确识别需要放开注释部分)
knife4j 效果图
swagger 效果图
swagger 效果图

api-docs json

api-docs

github issue : https://github.com/xiaoymin/swagger-bootstrap-ui/issues/538

评论 (2)

XKind 创建了任务

在OpenAPI3里面确实我复测了一下,有这个问题,但是是因为那个array没解析出来(目前版本的ui确实存在问题)

不过我后来升级了springdoc的版本1.6.14(后面Knife4j的版本会迭代到这个),解析出来的OpenAPI规范却不太一样。。

第一种情况是加注解描述的,代码如下:

@Operation(summary = "附件上传",description = "附近上传-xxx",requestBody = @RequestBody(content = {
            @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE,schema = @Schema(type = "object"),
            schemaProperties = {
                    @SchemaProperty(name = "file",array = @ArraySchema(schema = @Schema(type = "string",format = "binary",requiredMode = Schema.RequiredMode.REQUIRED))),
                    @SchemaProperty(name = "module",schema = @Schema(type = "string",required = true)),
                    @SchemaProperty(name = "bizNo",schema = @Schema(type = "string",required = true)),
                    @SchemaProperty(name = "bizType",schema = @Schema(type = "integer",required = true))
            })
    }))
    @PostMapping(value = "/module/upload1",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> fileModule1(FileRequestVo fileRequestVo){
        return ResponseEntity.ok(RandomUtil.randomString(23));
    }

解析的规范:

输入图片说明

第二种情况,不加任何注释,代码:

@PostMapping(value = "/module/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> fileModule(FileRequestVo fileRequestVo){
    return ResponseEntity.ok(RandomUtil.randomString(23));
}

解析得到的规范:

输入图片说明

我只能先以这个版本为准了

萧明 添加了
 
bug
标签
萧明 添加了
 
enhancement
标签
萧明 里程碑设置为Knife4j 4.1版本
萧明 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
118100 xiaoym 1578918321
Java
1
https://gitee.com/xiaoym/knife4j.git
git@gitee.com:xiaoym/knife4j.git
xiaoym
knife4j
knife4j

搜索帮助