Skip to content

Commit

Permalink
feat: Support explicit dynamic routing header (#887)
Browse files Browse the repository at this point in the history
This PR is to support explicit dynamic routing header feature proposed in go/actools-dynamic-routing-proposal.

All examples provided in routing.proto are covered by golden files unit tests.
Added validation that the field has to be of String type as suggested(Compare to implicit routing headers support primitive types as well).
For nested fields, when getting field values, added null check for each level to prevent null pointer exception during runtime.
  • Loading branch information
blakeli0 authored Jan 28, 2022
1 parent 50a8693 commit bcc1bdb
Show file tree
Hide file tree
Showing 29 changed files with 2,014 additions and 79 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jvm_maven_import_external(
# which in its turn, prioritizes actual generated clients runtime dependencies
# over the generator dependencies.

_gax_java_version = "2.10.0"
_gax_java_version = "2.11.0"

http_archive(
name = "com_google_api_gax_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.StubCommentComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.composer.utils.PackageChecker;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
Expand Down Expand Up @@ -204,15 +203,15 @@ public GapicClass generate(GapicContext context, Service service) {
.setName(className)
.setExtendsType(
typeStore.get(getTransportContext().classNames().getServiceStubClassName(service)))
.setStatements(classStatements)
.setMethods(
createClassMethods(
context,
service,
typeStore,
classMemberVarExprs,
callableClassMemberVarExprs,
protoMethodNameToDescriptorVarExprs))
protoMethodNameToDescriptorVarExprs, classStatements))
.setStatements(classStatements)
.build();
return GapicClass.create(kind, classDef);
}
Expand Down Expand Up @@ -249,7 +248,8 @@ protected List<MethodDefinition> createOperationsStubGetterMethod(
}

protected abstract Expr createTransportSettingsInitExpr(
Method method, VariableExpr transportSettingsVarExpr, VariableExpr methodDescriptorVarExpr);
Method method, VariableExpr transportSettingsVarExpr, VariableExpr methodDescriptorVarExpr,
List<Statement> classStatements);

protected List<MethodDefinition> createGetMethodDescriptorsMethod(
Service service,
Expand Down Expand Up @@ -430,7 +430,8 @@ protected List<MethodDefinition> createClassMethods(
TypeStore typeStore,
Map<String, VariableExpr> classMemberVarExprs,
Map<String, VariableExpr> callableClassMemberVarExprs,
Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs) {
Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs,
List<Statement> classStatements) {
List<MethodDefinition> javaMethods = new ArrayList<>();
javaMethods.addAll(createStaticCreatorMethods(service, typeStore, "newBuilder"));
javaMethods.addAll(
Expand All @@ -440,7 +441,8 @@ protected List<MethodDefinition> createClassMethods(
typeStore,
classMemberVarExprs,
callableClassMemberVarExprs,
protoMethodNameToDescriptorVarExprs));
protoMethodNameToDescriptorVarExprs,
classStatements));
javaMethods.addAll(
createGetMethodDescriptorsMethod(service, typeStore, protoMethodNameToDescriptorVarExprs));
javaMethods.addAll(
Expand Down Expand Up @@ -541,7 +543,8 @@ protected List<MethodDefinition> createConstructorMethods(
TypeStore typeStore,
Map<String, VariableExpr> classMemberVarExprs,
Map<String, VariableExpr> callableClassMemberVarExprs,
Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs) {
Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs,
List<Statement> classStatements) {
TypeNode stubSettingsType =
typeStore.get(getTransportContext().classNames().getServiceStubSettingsClassName(service));
VariableExpr settingsVarExpr =
Expand Down Expand Up @@ -666,7 +669,7 @@ protected List<MethodDefinition> createConstructorMethods(
m,
javaStyleMethodNameToTransportSettingsVarExprs.get(
JavaStyle.toLowerCamelCase(m.name())),
protoMethodNameToDescriptorVarExprs.get(m.name())))
protoMethodNameToDescriptorVarExprs.get(m.name()), classStatements))
.collect(Collectors.toList()));
secondCtorStatements.addAll(
secondCtorExprs.stream().map(ExprStatement::withExpr).collect(Collectors.toList()));
Expand Down
Loading

0 comments on commit bcc1bdb

Please sign in to comment.