Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spring): extend hasRestOption fix to properties composer and add golden tests #1348

Merged
merged 4 commits into from
Feb 16, 2023

Conversation

emmileaf
Copy link
Contributor

@emmileaf emmileaf commented Feb 13, 2023

This PR is a follow-up on #1343:

  • Extends fix to SpringPropertiesClassComposer, so that for services without REST-enabled rpcs, the unused useRest property is also not generated
  • Adds golden tests for the updated hasRestOption scenario using the wicked proto
  • Updates SpringAutoconfigCommentComposer for javadoc comments alluding to the useRest option

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Feb 13, 2023
@emmileaf emmileaf added spring pr that's related to spring code gen, intend to merge into autoconfig-gen-draft2 branch. and removed size: l Pull request size is large. labels Feb 13, 2023
@emmileaf emmileaf marked this pull request as ready for review February 13, 2023 14:09
@emmileaf emmileaf requested a review from a team as a code owner February 13, 2023 14:09
@emmileaf emmileaf requested review from blakeli0 and lqiu96 February 13, 2023 14:10
@@ -82,4 +83,35 @@ public GapicContext parseShowcaseEcho() {
.setTransport(getTransport())
.build();
}

public GapicContext parseShowcaseWicked() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to need to add an entry in this class for every Showcase client that we generate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need an entry in the test loader for every new test proto as the unit tests need to access the protoc generated Java files.
The name is a little confusing in this test due to historic reasons, but I don't consider this proto a showcase proto that will be used by showcase clients, this proto is used for unit tests only.

ServiceDescriptor messagingService = fileDescriptor.getServices().get(0);
assertEquals("Wicked", messagingService.getName());

Map<String, Message> messageTypes = Parser.parseMessages(fileDescriptor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic looks duplicated with the above method's. If this pattern will be repeated for further clients, consider refactoring this common logic out into something like createGapicContext(fileDescriptor)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! This might be refactoring to look into for the main branch's GrpcRestTestProtoLoader.

Some additional context on this PR: for now the spring branch has diverged from the main branch (after the monorepo migration), so this is just a copied over change from #1236 to re-use this latest addition in main. The next-phase plan would have spring-related test code such as in this PR's https://github.com/googleapis/gapic-generator-java/blob/90838fe105931feb0cca0433e478e81889da1d0e/src/test/java/com/google/api/generator/spring/composer/SpringAutoConfigClassComposerTest.java#L37 switched to call this method from the published gapic-generator-java jar, once the spring generator is migrated to depend on it.

@@ -75,7 +75,18 @@ public GapicClass generate(GapicContext context, Service service) {
String className = Utils.getServicePropertiesClassName(service);
GapicServiceConfig gapicServiceConfig = context.serviceConfig();
Map<String, TypeNode> dynamicTypes = createDynamicTypes(service, packageName);
boolean hasRestOption = context.transport().equals(Transport.GRPC_REST);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this property used in this composer? Why we don't need this logic in #1343?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeli0 The changes from #1343 removed the generation of SpringAutoConfiguration code that condition on this property (if (this.clientProperties.getUseRest())) to set rest-specific defaults. (e.g. this change to TetherSpringAutoconfiguration)

The property itself is still there (just ignored by the autoconfig), and will be removed as part of this PR's changes. I realized when updating these tests that we shouldn't be generating the property either, and it was something I had overlooked in #1343's patch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the explanation! It was an unused property hence not causing any compilation issues.

I did a quick search for rest and see that it is mentioned in this comment , we may want to update it to something like unless the useRest option is supported and provided, as not every client library support rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense - I've updated the comment composer correspondingly. Thanks for the suggestion!

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Feb 14, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

88.9% 88.9% Coverage
0.0% 0.0% Duplication

@emmileaf emmileaf merged commit dcd0823 into autoconfig-gen-draft2 Feb 16, 2023
@emmileaf emmileaf deleted the spring-rest-option-test branch February 16, 2023 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large. spring pr that's related to spring code gen, intend to merge into autoconfig-gen-draft2 branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants