/** Returns the current package name from the context stack. */ String packageName() { for (Object context : contextStack) { if (context instanceof ProtoFile) return ((ProtoFile) context).packageName(); } return null; }
private static String javaPackage(ProtoFile protoFile) { String javaPackage = protoFile.javaPackage(); if (javaPackage != null) { return javaPackage; } else if (protoFile.packageName() != null) { return protoFile.packageName(); } else { return ""; } }
private String resolveContext() { for (int i = contextStack.size() - 1; i >= 0; i--) { Object context = contextStack.get(i); if (context instanceof Type) { return ((Type) context).type().toString(); } else if (context instanceof ProtoFile) { String packageName = ((ProtoFile) context).packageName(); return packageName != null ? packageName : ""; } else if (context instanceof Field && ((Field) context).isExtension()) { String packageName = ((Field) context).packageName(); return packageName != null ? packageName : ""; } } throw new IllegalStateException(); }
/** Returns the current package name from the context stack. */ String packageName() { for (Object context : contextStack) { if (context instanceof ProtoFile) return ((ProtoFile) context).packageName(); } return null; }
/** Returns the current package name from the context stack. */ String packageName() { for (Object context : contextStack) { if (context instanceof ProtoFile) return ((ProtoFile) context).packageName(); } return null; }
private boolean isGoogle(ProtoFile protoFile) { return GOOGLE_PACKAGE.equals(protoFile.packageName()); }
private static String javaPackage(ProtoFile protoFile) { String javaPackage = protoFile.javaPackage(); if (javaPackage != null) { return javaPackage; } else if (protoFile.packageName() != null) { return protoFile.packageName(); } else { return ""; } }
private static String javaPackage(ProtoFile protoFile) { String javaPackage = protoFile.javaPackage(); if (javaPackage != null) { return javaPackage; } else if (protoFile.packageName() != null) { return protoFile.packageName(); } else { return ""; } }
private String resolveContext() { for (int i = contextStack.size() - 1; i >= 0; i--) { Object context = contextStack.get(i); if (context instanceof Type) { return ((Type) context).type().toString(); } else if (context instanceof ProtoFile) { String packageName = ((ProtoFile) context).packageName(); return packageName != null ? packageName : ""; } else if (context instanceof Field && ((Field) context).isExtension()) { String packageName = ((Field) context).packageName(); return packageName != null ? packageName : ""; } } throw new IllegalStateException(); }
private String resolveContext() { for (int i = contextStack.size() - 1; i >= 0; i--) { Object context = contextStack.get(i); if (context instanceof Type) { return ((Type) context).type().toString(); } else if (context instanceof ProtoFile) { String packageName = ((ProtoFile) context).packageName(); return packageName != null ? packageName : ""; } else if (context instanceof Field && ((Field) context).isExtension()) { String packageName = ((Field) context).packageName(); return packageName != null ? packageName : ""; } } throw new IllegalStateException(); }
/** * 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; }
/** * 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; }