代码拉取完成,页面将自动刷新
使用了两个版本(业务代码完全相同)有一个版本显示的返回参数,另一个版本不显示返回参数。
显示返回参数版本这里说明下:
使用的与项目整合的版本。
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
返回参数显示如下:
一切正常。’
接下使用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
显示结果如下:
使用本地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对象"}}}}
这个情况说明一下,在目前的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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
登录 后才可以发表评论