@Test(description = "collect path with many slashes inside") public void collectPathWithSlashesInside() { final String path = PathUtils.collectPath("///api/users///", "///getUser///", "/ /"); assertEquals(path, "/api/users/getUser"); }
@Test(description = "not fail when passed path is empty") public void testEmptyCollectedPath() { final String path = PathUtils.collectPath(""); assertEquals(path, "/"); } }
@Test(description = "collect path") public void collectPath() { final String path = PathUtils.collectPath("api", "/users/", "{userId}/"); assertEquals(path, "/api/users/{userId}"); }
@Test(description = "not fail when passed path is null") public void testNullCollectedPath() { final String path = PathUtils.collectPath(null, null); assertEquals(path, "/"); }
/** * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#paths-object * * @param protoFile * @param service * @return */ @Override protected Paths getPath(ProtoFile protoFile, Service service) { Paths paths = new Paths(); String basePath = protoFile.packageName(); InterfaceMetaInfo interfaceMetaInfo = InterfaceMetaInfo.readFrom(protoFile, service); String servicePath = interfaceMetaInfo.getServicePath(); for (Rpc rpc : service.rpcs()) { String defaultName = PathUtils.collectPath(basePath , rpc.name()); MethodMetaInfo methodMetaInfo = MethodMetaInfo.readFrom(rpc); String path = methodMetaInfo.getPath(); path = StringUtils.isBlank(path) && StringUtils.isBlank(servicePath) ? defaultName : PathUtils.collectPath(servicePath, path); // TODO: 2018/5/23 处理path 相同,方法不同的问题, PathItem pathItem = paths.get(path); if(Objects.isNull(pathItem)){ paths.addPathItem(path, getPathItem(rpc)); }else{ addOperation(rpc,pathItem); } } return paths; }
/** * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#paths-object * * @param protoFile * @param service * @return */ protected Paths getPath(ProtoFile protoFile, Service service) { Paths paths = new Paths(); String basePath = protoFile.packageName(); for (Rpc rpc : service.rpcs()) { String path = PathUtils.collectPath(basePath, rpc.name()); // TODO: 2018/5/23 处理path 相同,方法不同的问题, paths.addPathItem(path, getPathItem(rpc)); } return paths; }