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: allow empty services and java keywords as a method names #985

Merged
merged 4 commits into from
Apr 29, 2022

Conversation

vam-google
Copy link
Contributor

@vam-google vam-google commented Apr 23, 2022

This is specifically needed to enable sqladmin API, which has the following issues:

  1. Using import, reserved java keyword, as a method name: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instances.proto#L109
  2. Has an empty service (no methods whatsoevver) defined: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instance_names.proto#L31

I plan to add a full integration tests with sqladmin (which will also test pure REGAPIC case) once this is pushed (need to integrate these changes first for technical reasons).

This is specifically needed to enable sqladmin API, which has the following issues:
1) Using "import", reserved java keyword, as a method name: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instances.proto#L109
2) Has an empty service (no methods whatsoevver) defined: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instance_names.proto#L31

I plan to add a full integration tests with sqladmin (which will also test pure REGAPIC case) once this is pushed (need to integrate these changes first for technical reasons).
@vam-google vam-google requested review from a team as code owners April 23, 2022 00:00
@vam-google vam-google requested a review from blakeli0 April 23, 2022 00:01
RegionTag regionTag =
RegionTag.builder().setServiceName(service.name()).setRpcName("emtpy").build();

return Sample.builder().setRegionTag(regionTag).build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think each Sample will end up as a Java file, instead of creating an empty sample, we should probably either check it before entering the method, or return null and handle it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Compiling an empty file does not result in error in java, so I was under impression that empy sample is a valid case here (i.e. empty sample for empty service and no need to have special handling for nulls). On the other hand, empty service is a suspicious thing in API surface in a first place, so maybe the best way to fix it is for API team to stop publishing empty service definition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I agree that empty service should probably be prohibited in the first place, but in case it happens, is an empty sample file more helpful to developers? or not generating samples at all more helpful? I think the former might cause more confusion unless we are required to generate samples for empty services. @eaball35 what's your take on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this shouldn't even be a case in the first place, but here we are. I think it would be the preferred developer experience to not generate the empty sample. It's not that big of a deal to generate it, but it won't provide much value and will be confusing. Checking before entering or return null/optional and handling makes sense

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, @eaball35 Ok, I changed it to generate a legit sample to the extent possible - it shows how to create a client, but does not call any methods on the generated client, since there are none. I think it is a good balance between possible options. This will produce a valid compilable sample - a pretty useless (but valid) example for a pretty useless (empty) service. The rest is on the API side, I think - once they add methods we would not have this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this better because it's clear this behavior is more intentional, but "empty" is kind of a confusing name.

The goal of generating these samples in files with region tags is so they can be more easily be pulled into documentation/sample browser as desired. I can't see why anyone would ever want these "empty" samples. It's not going to necessarily hurt to include them, but it doesn't provide any value. What is the pushback against just not generating them?

Copy link
Contributor Author

@vam-google vam-google Apr 27, 2022

Choose a reason for hiding this comment

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

Because we still generate the client class. The class still has methods, create is one of them, so the sample generates as much as it can for a specific client class and it is still a valid example. Moving nulls around is an antipattern in java, plus, if we stop generating the sample we will have to change accordingly the whole header of the generated class documentation, which currently says:

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

I.e. not generating sample at all will have impliaitons on this comment (we can't say "Sample codeto get started" if there is no sample code). Also, assuming Emily's samples are there in their final form: still generating sample would let that code not to have to bother with special null handling, it can simply assume that sample is always generated. I.e. it literally feels to me like a better, simpler and more robust design. Otherwise all sampling logic would always have to be null-aware (not the case now), which unnecessarily complicates things. Yes, the emply sample is basically useless. But it is a useless (but formally valid) sample for a useless (but formally valid) client class, so they are in a perfect harmony here...

On the other hand, this is a very minor thing. Mainly, empty services should not even be a thing. Here I'm just trying to make presence of an empty service in API not fail the generation of the client for the whole API (which has many other non-empty services). Basically the whole goal of this is to make generator stop failing if there is a bogus service and ensure some more or less reasonable behavior of generator in case like this, without imposing a burden on the rest of the team on maintaining nulls.

Copy link
Contributor

@eaball35 eaball35 Apr 27, 2022

Choose a reason for hiding this comment

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

Thanks for explaining. I was thinking maybe returning an Optional< Sample> for that method and handling but can see the annoyance still. I still think creating the empty sample is kind of weird, but I understand why you want to do this. Because this is such a minor case that will rarely appear I guess it's fine to do this way. I can always add logic to the Writer to ignore writing "empty" samples. Maybe add some additional comments on composeEmptySample to explain what it's for, otherwise lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using Optional<Sample> would break the whole contract in samples generator and make it inconsistent with the rest of the methods (having one method in ServiceClientMethodSampleComposer return Optional<Sample> while the rest return Sample would be weird).

@vam-google vam-google changed the title fix: allow empty services and java keywords as a method name cases fix: allow empty services and java keywords as a method names Apr 25, 2022
@eaball35 eaball35 self-requested a review April 27, 2022 23:03
@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 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@vam-google
Copy link
Contributor Author

@eaball35 Changed the name of the method and added some comments. PTAL

@blakeli0
Copy link
Collaborator

@eaball35 Changed the name of the method and added some comments. PTAL

Emily is out today but it looks good to me based the conversation history.

@vam-google vam-google merged commit e37893c into googleapis:main Apr 29, 2022
suztomo pushed a commit that referenced this pull request Dec 16, 2022
This is specifically needed to enable `sqladmin` API, which has the following issues:
1) Using `import`, reserved java keyword, as a method name: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instances.proto#L109
2) Has an empty service (no methods whatsoevver) defined: https://github.com/googleapis/googleapis/blob/master/google/cloud/sql/v1/cloud_sql_instance_names.proto#L31

I plan to add a full integration tests with sqladmin (which will also test pure REGAPIC case) once this is pushed (need to integrate these changes first for technical reasons).
suztomo pushed a commit that referenced this pull request Mar 21, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [io.grpc:grpc-bom](https://togithub.com/grpc/grpc-java) | `1.50.0` -> `1.50.1` | [![age](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.50.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.50.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.50.1/compatibility-slim/1.50.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.50.1/confidence-slim/1.50.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>grpc/grpc-java</summary>

### [`v1.50.1`](https://togithub.com/grpc/grpc-java/compare/v1.50.0...v1.50.1)

[Compare Source](https://togithub.com/grpc/grpc-java/compare/v1.50.0...v1.50.1)

</details>

---

### 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/java-core).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yMzguNCIsInVwZGF0ZWRJblZlciI6IjMyLjI0MC41In0=-->
zhumin8 added a commit that referenced this pull request Jul 19, 2024
zhumin8 added a commit that referenced this pull request Jul 23, 2024
fixes #2750
Skip parsing a service if no RPCs found for. 
In the scenario that only one service with no RPCs or all services have
no RPCs, falls back to #2460

This pr also reverts a change brought by #985, and removes the relevant
tests. For more context, this has been discussed
[here](#2750 (comment)).

---------

Co-authored-by: Lawrence Qiu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants