xiaoymin / knife4j

Knife4j is a set of Swagger2 and OpenAPI3 All-in-one enhancement solution
https://doc.xiaominfo.com
Apache License 2.0
4.06k stars 612 forks source link

gateway nacos Knife4j聚合时地址有误 #655

Open yangbeibei69 opened 11 months ago

yangbeibei69 commented 11 months ago

Describe the bug gateway+nacos+Knife4j,v2/api-docs请求的地址有误,下图是进入gateway文档后,请求子服务地址时404

image

实际子服务地址应该是/sys/v2/api-docs?group=default

image

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem. gateway路由规则如下图

image

Knife4j Version (please complete the following information): gateway:knife4j-gateway-spring-boot-starter:4.3.0 sys子服务:knife4j-openapi2-spring-boot-starter:4.3.0 Additional context Add any other context about the problem here.

xiaoymin commented 11 months ago

从你贴的图来看,我觉得不太可能呢

knife4j-gateway取子服务的路由上取的gateway中的predicates中的path,不会取LB的

如果是取了服务名称,说明你的网关配置中开启了以服务名称进行转发的配置,Knife4j-gateway组件读取DiscoveryClientRouteDefinitionLocator中拿到了服务名称的路由,然后自动聚合了

yangbeibei69 commented 11 months ago

从你贴的图来看,我觉得不太可能呢

knife4j-gateway取子服务的路由上取的gateway中的predicates中的path,不会取LB的

如果是取了服务名称,说明你的网关配置中开启了以服务名称进行转发的配置,Knife4j-gateway组件读取DiscoveryClientRouteDefinitionLocator中拿到了服务名称的路由,然后自动聚合了

我把gateway配置去掉后,直接无法获取url了

image image
xiaoymin commented 11 months ago

这个需要你调试了,knife4j-gateway里面有四种策略来聚合来源,可能调试一下能更快的定位问题

zpf124 commented 5 months ago

我在研究我项目问题时顺道发现了此问题的原因。

我提的issue 类似, 此处也是由于knife4j对于多种配置写法的支持不全面导致的识别错误。
提问者的 配置中 uri 格式为 lb:http://xx-service 而不是 lb://xx-service

此处问题为 DiscoverClientRouteServiceConvert.process() 中过滤方法错误的将需要解析的内容排除了 ServiceUtils.startLoadBalance(routeDefinition.getUri())) 中对于 lb 的判断是 path.startsWith("lb://")

作者可能需要在这里添加正则匹配以满足以下多种格式.

lb://a-service
lb:http://b-service
lb:ws://c-service