/** Returns the RPC named {@code name}, or null if this service has no such method. */ public Rpc rpc(String name) { for (Rpc rpc : rpcs) { if (rpc.name().equals(name)) { return rpc; } } return null; }
Service retainAll(Schema schema, MarkSet markSet) { // If this service is not retained, prune it. if (!markSet.contains(protoType)) { return null; } ImmutableList.Builder<Rpc> retainedRpcs = ImmutableList.builder(); for (Rpc rpc : rpcs) { Rpc retainedRpc = rpc.retainAll(schema, markSet); if (retainedRpc != null && markSet.contains(ProtoMember.get(protoType, rpc.name()))) { retainedRpcs.add(retainedRpc); } } return new Service(protoType, location, documentation, name, retainedRpcs.build(), options.retainAll(schema, markSet)); }
error.append(String.format("%s rpc %s (%s)", prefix, rpc.name(), rpc.location()));
private void markRoots(Service service) { ProtoType protoType = service.type(); if (identifierSet.includes(protoType)) { marks.root(protoType); queue.add(protoType); } else { for (Rpc rpc : service.rpcs()) { markRoots(ProtoMember.get(protoType, rpc.name())); } } }
TypeName responseJavaType = javaGenerator.typeName(responseType); MethodSpec.Builder rpcBuilder = MethodSpec.methodBuilder(rpc.name()); rpcBuilder.addModifiers(PUBLIC, ABSTRACT); rpcBuilder.returns(responseJavaType);
private void markRpc(ProtoType declaringType, Rpc rpc) { if (marks.contains(ProtoMember.get(declaringType, rpc.name()))) { markOptions(rpc.options()); mark(rpc.requestType()); mark(rpc.responseType()); } } }
/** Returns the RPC named {@code name}, or null if this service has no such method. */ public Rpc rpc(String name) { for (Rpc rpc : rpcs) { if (rpc.name().equals(name)) { return rpc; } } return null; }
/** Returns the RPC named {@code name}, or null if this service has no such method. */ public Rpc rpc(String name) { for (Rpc rpc : rpcs) { if (rpc.name().equals(name)) { return rpc; } } return null; }
private Object defaultRequestPath(Rpc rpc, ClassName className) { ArrayList<String> params = Lists.newArrayList(RaptorConstants.RAPTOR, className.reflectionName(), rpc.name()); return RaptorConstants.PATH_SEPARATOR + StringUtils.join(params, RaptorConstants.PATH_SEPARATOR); }
Service retainAll(Schema schema, MarkSet markSet) { // If this service is not retained, prune it. if (!markSet.contains(protoType)) { return null; } ImmutableList.Builder<Rpc> retainedRpcs = ImmutableList.builder(); for (Rpc rpc : rpcs) { Rpc retainedRpc = rpc.retainAll(schema, markSet); if (retainedRpc != null && markSet.contains(ProtoMember.get(protoType, rpc.name()))) { retainedRpcs.add(retainedRpc); } } return new Service(protoType, location, documentation, name, retainedRpcs.build(), options.retainAll(schema, markSet)); }
Service retainAll(Schema schema, MarkSet markSet) { // If this service is not retained, prune it. if (!markSet.contains(protoType)) { return null; } ImmutableList.Builder<Rpc> retainedRpcs = ImmutableList.builder(); for (Rpc rpc : rpcs) { Rpc retainedRpc = rpc.retainAll(schema, markSet); if (retainedRpc != null && markSet.contains(ProtoMember.get(protoType, rpc.name()))) { retainedRpcs.add(retainedRpc); } } return new Service(protoType, location, documentation, name, retainedRpcs.build(), options.retainAll(schema, markSet)); }
error.append(String.format("%s rpc %s (%s)", prefix, rpc.name(), rpc.location()));
error.append(String.format("%s rpc %s (%s)", prefix, rpc.name(), rpc.location()));
private void markRoots(Service service) { ProtoType protoType = service.type(); if (identifierSet.includes(protoType)) { marks.root(protoType); queue.add(protoType); } else { for (Rpc rpc : service.rpcs()) { markRoots(ProtoMember.get(protoType, rpc.name())); } } }
private void markRoots(Service service) { ProtoType protoType = service.type(); if (identifierSet.includes(protoType)) { marks.root(protoType); queue.add(protoType); } else { for (Rpc rpc : service.rpcs()) { markRoots(ProtoMember.get(protoType, rpc.name())); } } }
public TypeSpec generateService(ProtoFile protoFile, Service service) { ClassName apiName = (ClassName) typeName(service.type()); TypeSpec.Builder typeBuilder = TypeSpec.interfaceBuilder(apiName.simpleName()); typeBuilder.addModifiers(PUBLIC); InterfaceMetaInfo interfaceMetaInfo = InterfaceMetaInfo.readFrom(protoFile, service); typeBuilder.addAnnotations(interfaceMetaInfo.generateAnnotations()); if (!service.documentation().isEmpty()) { typeBuilder.addJavadoc("$L\n", service.documentation()); } for (Rpc rpc : service.rpcs()) { ProtoType requestType = rpc.requestType(); TypeName requestJavaType = typeName(requestType); ProtoType responseType = rpc.responseType(); TypeName responseJavaType = typeName(responseType); MethodSpec.Builder rpcBuilder = MethodSpec.methodBuilder(rpc.name()); MethodMetaInfo methodMetaInfo = MethodMetaInfo.readFrom(rpc); rpcBuilder.addAnnotation(serviceAnnotation(rpc, apiName, interfaceMetaInfo)); rpcBuilder.addAnnotation(methodMetaInfo.generateRaptorMethod()); rpcBuilder.addModifiers(PUBLIC, ABSTRACT); rpcBuilder.returns(responseJavaType); ParameterSpec request = ParameterSpec.builder(requestJavaType, "request").build(); rpcBuilder.addParameter(request); if (!rpc.documentation().isEmpty()) { rpcBuilder.addJavadoc("$L\n", rpc.documentation()); } typeBuilder.addMethod(rpcBuilder.build()); } return typeBuilder.build(); }
/** * 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; }
private void markRpc(ProtoType declaringType, Rpc rpc) { if (marks.contains(ProtoMember.get(declaringType, rpc.name()))) { markOptions(rpc.options()); mark(rpc.requestType()); mark(rpc.responseType()); } } }
private void markRpc(ProtoType declaringType, Rpc rpc) { if (marks.contains(ProtoMember.get(declaringType, rpc.name()))) { markOptions(rpc.options()); mark(rpc.requestType()); mark(rpc.responseType()); } } }
/** * 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; }