Skip to content

Commit

Permalink
fix: fixes regionTag breakage (#1068)
Browse files Browse the repository at this point in the history
* fix: fixes regionTag breakage

* update credentials integration test

* removing getPureServiceName function

* linter

* refactor test

* chore(deps): update dependency org.apache.maven.plugins:maven-shade-plugin to v3.4.1 (#1072)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.apache.maven.plugins:maven-shade-plugin](https://maven.apache.org/plugins/) | `3.4.0` -> `3.4.1` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-shade-plugin/3.4.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-shade-plugin/3.4.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-shade-plugin/3.4.1/compatibility-slim/3.4.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-shade-plugin/3.4.1/confidence-slim/3.4.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-generator-java).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yLjMiLCJ1cGRhdGVkSW5WZXIiOiIzNC42LjEifQ==-->

* refactor: expose parsed api short name and version as fields in Service (#1075)

* Exposes parsed apiShortName and apiVersion as fields in Service.java, since the source fields (defaultHost and protoPakkage) are both defined per-service. 

* Adds these two fields correspondingly to GapicClass so that it can be composed from Service given these two upstream fields, then replaces withDefaultHost (for building GapicClass) withApiShortName and withApiVersion. (Composers and tests where this is currently used for sample generation are updated)

* This change will enable Spring Codegen (when eventually split out from this repo) to reuse this parsing logic in descriptive comments and metadata. It also moves the parsing logic to earlier in the parse-compose process.

* fix: fix REST transport client creation generated javadoc sample (#1077)

* fix: fixes regionTag breakage

* remove errant comment

Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Emily Wang <emmwang@google.com>
Co-authored-by: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 1, 2022
1 parent 9ac0ca8 commit bed9f72
Show file tree
Hide file tree
Showing 306 changed files with 1,118 additions and 746 deletions.
Expand Up @@ -200,9 +200,11 @@ protected List<CommentStatement> createClassHeaderComments(
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
service, clientType, resourceNames, messageTypes);
Sample credentialsSampleCode =
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(clientType, settingsType);
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(
clientType, settingsType, service);
Sample endpointSampleCode =
ServiceClientHeaderSampleComposer.composeSetEndpointSample(clientType, settingsType);
ServiceClientHeaderSampleComposer.composeSetEndpointSample(
clientType, settingsType, service);
samples.addAll(Arrays.asList(classMethodSampleCode, credentialsSampleCode, endpointSampleCode));
return ServiceClientCommentComposer.createClassHeaderComments(
service,
Expand Down Expand Up @@ -580,7 +582,8 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames,
samples);
samples,
service);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata
Expand All @@ -598,7 +601,8 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames,
samples);
samples,
service);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
Expand Down Expand Up @@ -638,7 +642,8 @@ private static List<MethodDefinition> createMethodVariants(
Map<String, Message> messageTypes,
TypeStore typeStore,
Map<String, ResourceName> resourceNames,
List<Sample> samples) {
List<Sample> samples,
Service service) {
List<MethodDefinition> javaMethods = new ArrayList<>();
String methodName = JavaStyle.toLowerCamelCase(method.name());
TypeNode methodInputType = method.inputType();
Expand Down Expand Up @@ -702,7 +707,12 @@ private static List<MethodDefinition> createMethodVariants(
Optional<Sample> methodSample =
Optional.of(
ServiceClientHeaderSampleComposer.composeShowcaseMethodSample(
method, typeStore.get(clientName), signature, resourceNames, messageTypes));
method,
typeStore.get(clientName),
signature,
resourceNames,
messageTypes,
service));
Optional<String> methodDocSample = Optional.empty();
if (methodSample.isPresent()) {
samples.add(methodSample.get());
Expand Down Expand Up @@ -746,7 +756,8 @@ private static MethodDefinition createMethodDefaultMethod(
Map<String, Message> messageTypes,
TypeStore typeStore,
Map<String, ResourceName> resourceNames,
List<Sample> samples) {
List<Sample> samples,
Service service) {
String methodName = JavaStyle.toLowerCamelCase(method.name());
TypeNode methodInputType = method.inputType();
TypeNode methodOutputType =
Expand Down Expand Up @@ -790,7 +801,7 @@ private static MethodDefinition createMethodDefaultMethod(
Optional<Sample> defaultMethodSample =
Optional.of(
ServiceClientMethodSampleComposer.composeCanonicalSample(
method, typeStore.get(clientName), resourceNames, messageTypes));
method, typeStore.get(clientName), resourceNames, messageTypes, service));
Optional<String> defaultMethodDocSample = Optional.empty();
if (defaultMethodSample.isPresent()) {
samples.add(defaultMethodSample.get());
Expand Down Expand Up @@ -932,15 +943,17 @@ private static MethodDefinition createCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes));
messageTypes,
service));
} else if (callableMethodKind.equals(CallableMethodKind.PAGED)) {
sampleCode =
Optional.of(
ServiceClientCallableMethodSampleComposer.composePagedCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes));
messageTypes,
service));
} else if (callableMethodKind.equals(CallableMethodKind.REGULAR)) {
if (method.stream().equals(Stream.NONE)) {
sampleCode =
Expand All @@ -949,15 +962,17 @@ private static MethodDefinition createCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes));
messageTypes,
service));
} else {
sampleCode =
Optional.of(
ServiceClientCallableMethodSampleComposer.composeStreamCallableMethod(
method,
typeStore.get(ClassNames.getServiceClientClassName(service)),
resourceNames,
messageTypes));
messageTypes,
service));
}
}
Optional<String> sampleDocCode = Optional.empty();
Expand Down
Expand Up @@ -54,12 +54,14 @@ protected List<CommentStatement> createClassHeaderComments(
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
service, clientType, resourceNames, messageTypes);
Sample credentialsSampleCode =
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(clientType, settingsType);
ServiceClientHeaderSampleComposer.composeSetCredentialsSample(
clientType, settingsType, service);
Sample endpointSampleCode =
ServiceClientHeaderSampleComposer.composeSetEndpointSample(clientType, settingsType);
ServiceClientHeaderSampleComposer.composeSetEndpointSample(
clientType, settingsType, service);
Sample transportSampleCode =
ServiceClientHeaderSampleComposer.composeTransportSample(
clientType, settingsType, "newHttpJsonBuilder");
clientType, settingsType, "newHttpJsonBuilder", service);
samples.addAll(
Arrays.asList(
classMethodSampleCode, credentialsSampleCode, endpointSampleCode, transportSampleCode));
Expand Down
Expand Up @@ -42,13 +42,13 @@
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.Method;
import com.google.api.generator.gapic.model.RegionTag;
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Sample;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.utils.JavaStyle;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand All @@ -61,7 +61,7 @@

public class ServiceClientCallableMethodSampleComposer {
private static Sample composeUnaryOrLroCallableSample(
Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr) {
Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr, Service service) {
List<Statement> bodyStatements = new ArrayList<>();
// Create api future variable expression, and assign it with a value by invoking callable
// method.
Expand Down Expand Up @@ -125,8 +125,7 @@ private static Sample composeUnaryOrLroCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand All @@ -141,7 +140,8 @@ private static Sample composePagedCallableSample(
Method method,
VariableExpr clientVarExpr,
VariableExpr requestVarExpr,
Map<String, Message> messageTypes) {
Map<String, Message> messageTypes,
Service service) {
// Find the repeated field.
Message methodOutputMessage = messageTypes.get(method.outputType().reference().fullName());
Field repeatedPagedResultsField = methodOutputMessage.findAndUnwrapPaginatedRepeatedField();
Expand Down Expand Up @@ -280,8 +280,7 @@ private static Sample composePagedCallableSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setOverloadDisambiguation("Paged")
.setIsAsynchronous(true)
Expand All @@ -297,7 +296,8 @@ public static Sample composeLroCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Map<String, Message> messageTypes,
Service service) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -397,7 +397,7 @@ public static Sample composeLroCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.setOverloadDisambiguation("LRO")
Expand All @@ -418,7 +418,8 @@ public static Sample composePagedCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Map<String, Message> messageTypes,
Service service) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -534,7 +535,7 @@ public static Sample composePagedCallableMethod(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(ClassNames.getPureServiceName(clientType.reference().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand All @@ -546,7 +547,8 @@ public static Sample composeRegularCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Map<String, Message> messageTypes,
Service service) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -578,13 +580,13 @@ public static Sample composeRegularCallableMethod(
RegionTag regionTag;
if (method.isPaged()) {
Sample pagedCallable =
composePagedCallableSample(method, clientVarExpr, requestVarExpr, messageTypes);
composePagedCallableSample(method, clientVarExpr, requestVarExpr, messageTypes, service);
bodyStatements.addAll(pagedCallable.body());
regionTag = pagedCallable.regionTag();
} else {
// e.g. echoClient.echoCallable().futureCall(request)
Sample unaryOrLroCallable =
composeUnaryOrLroCallableSample(method, clientVarExpr, requestVarExpr);
composeUnaryOrLroCallableSample(method, clientVarExpr, requestVarExpr, service);
bodyStatements.addAll(unaryOrLroCallable.body());
regionTag = unaryOrLroCallable.regionTag();
}
Expand All @@ -604,7 +606,8 @@ public static Sample composeStreamCallableMethod(
Method method,
TypeNode clientType,
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes) {
Map<String, Message> messageTypes,
Service service) {
VariableExpr clientVarExpr =
VariableExpr.withVariable(
Variable.builder()
Expand Down Expand Up @@ -633,16 +636,19 @@ public static Sample composeStreamCallableMethod(
List<Statement> bodyStatements = new ArrayList<>();
if (method.stream().equals(Method.Stream.SERVER)) {
// e.g. ServerStream<EchoResponse> stream = echoClient.expandCallable().call(request);
Sample streamServer = composeStreamServerSample(method, clientVarExpr, requestAssignmentExpr);
Sample streamServer =
composeStreamServerSample(method, clientVarExpr, requestAssignmentExpr, service);
bodyStatements.addAll(streamServer.body());
regionTag = streamServer.regionTag();
} else if (method.stream().equals(Method.Stream.BIDI)) {
// e.g. echoClient.collect().clientStreamingCall(responseObserver);
Sample streamBidi = composeStreamBidiSample(method, clientVarExpr, requestAssignmentExpr);
Sample streamBidi =
composeStreamBidiSample(method, clientVarExpr, requestAssignmentExpr, service);
bodyStatements.addAll(streamBidi.body());
regionTag = streamBidi.regionTag();
} else if (method.stream().equals(Method.Stream.CLIENT)) {
Sample streamClient = composeStreamClientSample(method, clientVarExpr, requestAssignmentExpr);
Sample streamClient =
composeStreamClientSample(method, clientVarExpr, requestAssignmentExpr, service);
bodyStatements.addAll(streamClient.body());
regionTag = streamClient.regionTag();
}
Expand All @@ -659,7 +665,10 @@ public static Sample composeStreamCallableMethod(
}

private static Sample composeStreamServerSample(
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
List<Expr> bodyExprs = new ArrayList<>();
bodyExprs.add(requestAssignmentExpr);

Expand Down Expand Up @@ -720,16 +729,18 @@ private static Sample composeStreamServerSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
return Sample.builder().setBody(bodyStatements).setRegionTag(regionTag).build();
}

private static Sample composeStreamBidiSample(
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
List<Expr> bodyExprs = new ArrayList<>();

// Create bidi stream variable expression and assign it with invoking client's bidi stream
Expand Down Expand Up @@ -800,16 +811,18 @@ private static Sample composeStreamBidiSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
return Sample.builder().setBody(bodyStatements).setRegionTag(regionTag).build();
}

private static Sample composeStreamClientSample(
Method method, VariableExpr clientVarExpr, AssignmentExpr requestAssignmentExpr) {
Method method,
VariableExpr clientVarExpr,
AssignmentExpr requestAssignmentExpr,
Service service) {
List<Expr> bodyExprs = new ArrayList<>();

// Create responseObserver variable expression.
Expand Down Expand Up @@ -933,8 +946,7 @@ private static Sample composeStreamClientSample(

RegionTag regionTag =
RegionTag.builder()
.setServiceName(
ClassNames.getPureServiceName(clientVarExpr.variable().identifier().name()))
.setServiceName(service.name())
.setRpcName(method.name())
.setIsAsynchronous(true)
.build();
Expand Down

0 comments on commit bed9f72

Please sign in to comment.