762 Star 6.6K Fork 1.4K

GVP萧明 / knife4j

 / 详情

Knife4jAggregation与swagger3.0 返回参数不显示

已完成
创建于  
2021-04-01 16:48

使用了两个版本(业务代码完全相同)有一个版本显示的返回参数,另一个版本不显示返回参数。

显示返回参数版本这里说明下:
使用的与项目整合的版本。

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>

返回参数显示如下:
Image description
一切正常。’
接下使用Knife4jAggregation 整合该项目的swagger文档,在Knife4jAggregation 中出现了不显示返回参数。
尝试使用了两种方法,本地json的方法。json来自与上面能正常显示的项目提取。json贴最后。
Knife4jAggregation启动引入的pom为:

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-aggregation-spring-boot-starter</artifactId>
            <version>2.0.8</version>
        </dependency>

配置参数

server:
  port: 19081
knife4j:
  enableAggregation: true
  cloud:
    enable: true
    routes:
      - name: 测试分组1
        uri: localhost:8080/test
        location: /v3/api-docs

显示结果如下:
Image description

使用本地json的方式,也同上面一样不显示。json文本如下:

{"openapi":"3.0.3","info":{"title":"丁税宝1.0","description":"接口文档","version":"1.0"},"servers":[{"url":"http://localhost:8080","description":"Inferred Url"}],"tags":[{"name":"测试接口","description":"测试接口"}],"paths":{"/test/test/get/testA":{"post":{"tags":["测试接口"],"summary":"testA只返回对象","operationId":"getTestAUsingPOST","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestParam"}}}},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/TestVO"}}}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/test/test/get/testB":{"post":{"tags":["测试接口"],"summary":"testB返回Api对象","operationId":"getTestBUsingPOST","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestParam"}}}},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiResponse«TestVO»"}}}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}},"components":{"schemas":{"ApiResponse«TestVO»":{"title":"ApiResponse«TestVO»","type":"object","properties":{"code":{"type":"string","description":"返回码"},"data":{"description":"返回结果","$ref":"#/components/schemas/TestVO"},"error":{"type":"string","description":"错误信息"},"errorTrace":{"type":"string","description":"错误堆栈"},"requestId":{"type":"string","description":"请求唯一Id"}},"description":"返回结果集"},"TestParam":{"title":"TestParam","type":"object","properties":{"testA":{"type":"string","description":"测试属性A"},"testB":{"type":"integer","description":"测试属性B","format":"int64"},"testC":{"type":"integer","description":"测试属性C","format":"int32"},"testList":{"type":"array","description":"测试数组属性","items":{"type":"string"}}},"description":"测试的vo对象"},"TestVO":{"title":"TestVO","type":"object","properties":{"testA":{"type":"string","description":"测试属性A"},"testB":{"type":"integer","description":"测试属性B","format":"int64"},"testC":{"type":"integer","description":"测试属性C","format":"int32"},"testList":{"type":"array","description":"测试数组属性","items":{"type":"string"}}},"description":"测试的vo对象"}}}}

评论 (1)

浪仁 创建了任务
浪仁 关联仓库设置为萧明/knife4j
浪仁 修改了描述
展开全部操作日志

这个情况说明一下,在目前的Knife4jAggregation聚合组件中,ui中会针对聚合接口做一次判断,也就是swagger-resources接口响应的swaggerVersion字段,如果是OpenAPI3的版本,开发者使用的时候应该给赋值3.0或者3.0.3都行,比如这样:

server:
  port: 19081
knife4j:
  enableAggregation: true
  cloud:
    enable: true
    routes:
      - name: 测试分组1
        uri: localhost:8080/test
        location: /v3/api-docs
        swaggerVersion: 3.0.3

这样,前端swagger-resources分组接口响应的JSON结构如下:

[
    {
        "name": "测试分组1",
        "url": "/v3/api-docs",
        "swaggerVersion": "3.0.3",
        "location": "/v3/api-docs"
    }
]

在下个版本中,ui会根据当前OpenAPI接口响应的实例在做一次判断,以优化该逻辑,自动判断响应的规范是OpenAPI3还是Swagger2

萧明 里程碑设置为Knife4j 2.0.9版本
萧明 添加了
 
enhancement
标签
萧明 任务状态待办的 修改为进行中
萧明 通过xiaoym/knife4j Pull Request !47任务状态进行中 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
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

搜索帮助

53164aa7 5694891 3bd8fe86 5694891