GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: Use parent type instead of child_type in method doc sample by meltsufin · Pull Request #862 · googleapis/sdk-platform-java
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
Conversation
Contributor
Fixes: #852.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
meltsufin
force-pushed
the
fix_method_doc_child_type
branch
from
556da01 to
3389f74
Compare
meltsufin
force-pushed
the
fix_method_doc_child_type
branch
from
3389f74 to
ababe29
Compare
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@ ## main #862 +/- ## ========================================== + Coverage 87.59% 87.65% +0.05% ========================================== Files 152 153 +1 Lines 15982 16000 +18 Branches 1162 1168 +6 ========================================== + Hits 14000 14025 +25 + Misses 1641 1634 -7 Partials 341 341
Continue to review full report at Codecov.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM in substance, but please address the two concerns first:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
1e49e88 to
00028b3
Compare
00028b3 to
8c59769
Compare
@vam-google Can you point to some examples please?
The datastream was never intended to stay. It was there just to work on the PR. I did follow your suggestion to use I decided to make the condition a bit more flexible to allow the case of multiple parents, in which case we just choose the first one. Please take another look. Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I may be talking something different, but isn't it that we need to choose the best match (the longest match) when there are multiple parent candidates? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I don't think that's specified. Have you seen that somewhere? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
96318ad to
7578d45
Compare
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM to unblock things. There are two non-blocking concerns though (check the corresponding comments for details):
parseParentPattern method logic is probably no accurate (but it was like that before this PR).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if (inputMessage.fieldMap().containsKey("page_token") | ||
| if (inputMessage != null | ||
| && inputMessage.fieldMap() != null |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why did this if statement get so much bigger? Specifically, looks like inputMessage.fieldMap() was guaranteed to not be null (as we would get NPE otherwise).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good point on fieldMap() being non-nullible. However, inputMessage can be null as the new messaging test revealed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,49 @@ | |||
| // Copyright 2020 Google LLC | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
2021
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import java.util.Arrays; | ||
| import java.util.Optional; | ||
|
|
||
| public final class ResourceReferenceUtils { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
tl;dr; can we keep this in parser class?
It seems we can avoid creating a new util class for this:
It is one-method util class.
The only method is called parse* and we already have ResourceReferenceParser class, so it is hard to justify presence of ResourceReferenceUtils which does the parser's job.
I guess it is so because this new parse method is now used in two places - ResourceReferenceParser and DefaultValueComposer.
WDYT about keeping the parser method in parser class, but make the parent-child resolution logic persisted in ResourceName class (or another/new data structure returned by the parser class) and make the parser class precompute everything only once. If parent-child resolutin is not a property of a resource name but a property of an rpc method using that resource name, then it is not clear why that logic is still called in resource name parser class.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Map<String, ResourceName> identityResourceNames = Parser | ||
| .parseResourceNames(identityFileDescriptor); | ||
|
|
||
| resourceNames.put("showcase.googleapis.com/User", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? If there is stuff in the messaging.proto file, which just causes troubles but is not essential for the tests, please feel free to remove it. If there are missing imports please just add them on proot/bazel lavel.
Basically any API definition problems are expected to be solved on proto level, but not in the logic which loads/parse the protos.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| import "google/api/annotations.proto"; | ||
| import "google/api/client.proto"; | ||
| import "google/cloud/extended_operations.proto"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please put it back. It will be needed soon, even though it is technically not used now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| boolean allowAnonResourceNameClass) { | ||
|
|
||
| if (isChildType) { | ||
| resourceName = findParentResource(resourceName, resnames).orElse(resourceName); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
does the orElse part mean that if we did not manage to find a parent, the code will behave as before, basically meaning that the child is its own parent?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yep. Do you think we should fail instead?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No, just wanted to make sure I understood it right.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| for (String childPattern : childResource.patterns()) { | ||
| Optional<String> parentPattern = ResourceReferenceUtils.parseParentPattern(childPattern); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
*Please see the other comment in ResourceReferenceUtils class for context
I could be missing some more complicated interactions, but at first glance:
ResourceReferenceUtils.parseParentPattern(childPattern) is called for every pattern in childResource which is of type ResourceName, created by ResourceReferenceParser. So instead of computing the parentPattern portion here, it may be precomputed and included in ResourceName class itself, which is constructed in ResourceReferenceParser, thus eliminating the need to have the utils class.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, ResourceReferenceUtils.parseParentPattern(childPattern) is only called by MethodSigantureParser and by Parser, but only for Google Ads API. So, I don't see a straightforward way to include the mapping to the parent in the ResourceName itself, especially since the class is immutable, and you need to have access to all ResourceNames before computing the mapping from child to parent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| resourceName, isChildType, resnames, fieldOrMessageName, true); | ||
| } | ||
|
|
||
| private static Optional<ResourceName> findParentResource( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can this whole thing be included in ResourceReferenceParser class? This seems like a general resource names resolution logic, not necessarily specific to sample generation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| private ResourceReferenceUtils() {} | ||
|
|
||
| public static Optional<String> parseParentPattern(String pattern) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This logic was there before, but it does not look accurate, as it makes many different assumption, which may be false.
for examle, if there is a pattern /a/{b}/c/e/{f}
when we search for its parent we must check at least 3 possible cases:
/a/{b}/c/e/{f} - child
/a/{b}/c/e - parent candidate 1
/a/{b}/c - parent candidate 2 (if 1 did not match anything)
/a/{b} - parent candidate 3 (if neither 1 nor 2 matched anything)
Instead this logic always returns only one candidate. Not sure how many (if any) practical cases we have which the current implementation would not satisfy. I guess it is ok to keep the implementaiton as is for now, but maybe put a comment/request for refactoring it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's true, but according to https://google.aip.dev/122, this example is not a recommended pattern.
Resource name components should usually alternate between collection identifiers (example: publishers, books, users) and resource IDs (example: 123, les-miserables, vhugo1802).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Correct, but if it was guaranteed they would phrase it as "must" in the AIP. I think it is ok to keep the implementation as is, since it is beyond the scope of this PR, just maybe add a comment about it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.api.grpc:grpc-google-iam-v1](https://togithub.com/googleapis/java-iam/grpc-google-iam-v1) ([source](https://togithub.com/googleapis/java-iam)) | `1.6.3` -> `1.6.4` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [com.google.api.grpc:proto-google-iam-v1](https://togithub.com/googleapis/java-iam/proto-google-iam-v1) ([source](https://togithub.com/googleapis/java-iam)) | `1.6.3` -> `1.6.4` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/java-iam</summary> ### [`v1.6.4`](https://togithub.com/googleapis/java-iam/blob/HEAD/CHANGELOG.md#​164-httpsgithubcomgoogleapisjava-iamcomparev163v164-2022-10-10) [Compare Source](https://togithub.com/googleapis/java-iam/compare/v1.6.3...v1.6.4) ##### Dependencies - Update dependency com.google.cloud:google-iam-policy to v1.6.3 ([#​472](https://togithub.com/googleapis/java-iam/issues/472)) ([8f911be](https://togithub.com/googleapis/java-iam/commit/8f911bef57b66ab9dd092ed7912702c038e8565e)) </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 these updates 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-shared-dependencies). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjMyLjIzMC4wIn0=-->
🤖 I have created a release *beep* *boop* --- ## [3.0.5](https://togithub.com/googleapis/java-shared-dependencies/compare/v3.0.4...v3.0.5) (2022-10-20) ### Dependencies * Update dependency com.fasterxml.jackson:jackson-bom to v2.13.4.20221013 ([#868](https://togithub.com/googleapis/java-shared-dependencies/issues/868)) ([5c2a825](https://togithub.com/googleapis/java-shared-dependencies/commit/5c2a825c18af61784287dd41eba3a21be80bbe6b)) * Update dependency com.google.auth:google-auth-library-bom to v1.12.0 ([#870](https://togithub.com/googleapis/java-shared-dependencies/issues/870)) ([3e3a60d](https://togithub.com/googleapis/java-shared-dependencies/commit/3e3a60dfd45f08401ee3ac7a98007fae21d5bba6)) * Update dependency com.google.auth:google-auth-library-bom to v1.12.1 ([#871](https://togithub.com/googleapis/java-shared-dependencies/issues/871)) ([4d94c75](https://togithub.com/googleapis/java-shared-dependencies/commit/4d94c753b46d7f8c787b0efa21d7bc42b1ca1c6c)) * Update dependency com.google.cloud:grpc-gcp to v1.3.0 ([#867](https://togithub.com/googleapis/java-shared-dependencies/issues/867)) ([48ca222](https://togithub.com/googleapis/java-shared-dependencies/commit/48ca222a5e4d9f88737d4c4a4ee2a42a7145619e)) * Update dependency com.google.errorprone:error_prone_annotations to v2.16 ([#865](https://togithub.com/googleapis/java-shared-dependencies/issues/865)) ([d7a494d](https://togithub.com/googleapis/java-shared-dependencies/commit/d7a494dcd12a529121b74fd9fb9dfc679017f844)) * Update dependency com.google.protobuf:protobuf-bom to v3.21.8 ([#872](https://togithub.com/googleapis/java-shared-dependencies/issues/872)) ([ebe5d5f](https://togithub.com/googleapis/java-shared-dependencies/commit/ebe5d5f27dbe4f12c06d3a69c14c74bbf4e76dd1)) * Update dependency gcp-releasetool to v1.8.10 ([#853](https://togithub.com/googleapis/java-shared-dependencies/issues/853)) ([5c6367a](https://togithub.com/googleapis/java-shared-dependencies/commit/5c6367a643f491d2ec04be58c1ff0eca5aa10904)) * Update dependency google-api-core to v2.10.2 ([#858](https://togithub.com/googleapis/java-shared-dependencies/issues/858)) ([bc91e8d](https://togithub.com/googleapis/java-shared-dependencies/commit/bc91e8df54f9d919a9e0dc69e61d52fd855a8dbf)) * Update dependency io.grpc:grpc-bom to v1.50.0 ([#866](https://togithub.com/googleapis/java-shared-dependencies/issues/866)) ([50039f4](https://togithub.com/googleapis/java-shared-dependencies/commit/50039f41bfba37e65685c4a5b279d3cb2a92f2c5)) * Update dependency io.grpc:grpc-bom to v1.50.1 ([#873](https://togithub.com/googleapis/java-shared-dependencies/issues/873)) ([9fb1561](https://togithub.com/googleapis/java-shared-dependencies/commit/9fb15613976f83c5545e2b664c488e9811c1f185)) * Update dependency org.checkerframework:checker-qual to v3.26.0 ([#852](https://togithub.com/googleapis/java-shared-dependencies/issues/852)) ([1e8cd60](https://togithub.com/googleapis/java-shared-dependencies/commit/1e8cd609b3be0cdd748a8fea6bc0fcb15d8f4c96)) * Update dependency org.threeten:threetenbp to v1.6.3 ([#869](https://togithub.com/googleapis/java-shared-dependencies/issues/869)) ([e992190](https://togithub.com/googleapis/java-shared-dependencies/commit/e9921900ec590e281b5ae6e16ab51e7bd67c1242)) * Update dependency typing-extensions to v4.4.0 ([#854](https://togithub.com/googleapis/java-shared-dependencies/issues/854)) ([c909a13](https://togithub.com/googleapis/java-shared-dependencies/commit/c909a13fa626eb387c8ee87b7cc22607cb9cf889)) * Update dependency zipp to v3.9.0 ([#859](https://togithub.com/googleapis/java-shared-dependencies/issues/859)) ([971b84e](https://togithub.com/googleapis/java-shared-dependencies/commit/971b84eb801699b585cd35300bed8d4fb65046d8)) * Update gax.version to v2.19.4 ([#875](https://togithub.com/googleapis/java-shared-dependencies/issues/875)) ([2eb7f3d](https://togithub.com/googleapis/java-shared-dependencies/commit/2eb7f3d6cf834c474dcdc99740f8cdabf50bca51)) * Update google.core.version to v2.8.21 ([#861](https://togithub.com/googleapis/java-shared-dependencies/issues/861)) ([2fda421](https://togithub.com/googleapis/java-shared-dependencies/commit/2fda4213796df086450fdc3d69d53a0bd1d59f46)) * Update google.core.version to v2.8.22 ([#879](https://togithub.com/googleapis/java-shared-dependencies/issues/879)) ([e4f9f9a](https://togithub.com/googleapis/java-shared-dependencies/commit/e4f9f9ad6373fb52c069985ca4390663ccdacb7d)) * Update iam.version to v1.6.3 ([#857](https://togithub.com/googleapis/java-shared-dependencies/issues/857)) ([6758373](https://togithub.com/googleapis/java-shared-dependencies/commit/675837378642f39fe55c0e30b62755b9185bee3d)) * Update iam.version to v1.6.4 ([#862](https://togithub.com/googleapis/java-shared-dependencies/issues/862)) ([1e1bc34](https://togithub.com/googleapis/java-shared-dependencies/commit/1e1bc341c9dd0f8f5a2d14aa8dd52399b2ce71c1)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
….5.0 (#862) [](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.api.grpc:proto-google-iam-v1](https://togithub.com/googleapis/java-iam) | `1.4.1` -> `1.5.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/java-iam</summary> ### [`v1.5.0`](https://togithub.com/googleapis/java-iam/blob/HEAD/CHANGELOG.md#​150-httpsgithubcomgoogleapisjava-iamcomparev141v150-2022-06-30) [Compare Source](https://togithub.com/googleapis/java-iam/compare/v1.4.1...v1.5.0) ##### Features - add v2beta client ([#​364](https://togithub.com/googleapis/java-iam/issues/364)) ([0904baa](https://togithub.com/googleapis/java-iam/commit/0904baa7be7dda2b0c8ec9e68ade548d173761fd)) ##### Dependencies - update dependency com.google.cloud:google-cloud-shared-dependencies to v2.13.0 ([#​367](https://togithub.com/googleapis/java-iam/issues/367)) ([ece5f7d](https://togithub.com/googleapis/java-iam/commit/ece5f7dda5fcba488f1416593114ba6ab8ab31ef)) - update dependency com.google.protobuf:protobuf-java to v3.21.2 ([#​368](https://togithub.com/googleapis/java-iam/issues/368)) ([64b6349](https://togithub.com/googleapis/java-iam/commit/64b6349880792f3a534aa879ca1f0044d25603be)) </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).
🤖 I have created a release *beep* *boop* --- ## [2.8.2](googleapis/java-core@v2.8.1...v2.8.2) (2022-07-13) ### Bug Fixes * enable longpaths support for windows test ([#1485](https://github.com/googleapis/java-core/issues/1485)) ([#866](googleapis/java-core#866)) ([8a8ac99](googleapis/java-core@8a8ac99)) ### Dependencies * update dependency com.google.api-client:google-api-client-bom to v1.35.2 ([#859](googleapis/java-core#859)) ([6b51a1c](googleapis/java-core@6b51a1c)) * update dependency com.google.api:gax-bom to v2.18.3 ([#860](googleapis/java-core#860)) ([f5a5278](googleapis/java-core@f5a5278)) * update dependency com.google.api.grpc:proto-google-common-protos to v2.9.1 ([#855](googleapis/java-core#855)) ([4ec6635](googleapis/java-core@4ec6635)) * update dependency com.google.api.grpc:proto-google-iam-v1 to v1.5.0 ([#862](googleapis/java-core#862)) ([19aebbe](googleapis/java-core@19aebbe)) * update dependency com.google.http-client:google-http-client-bom to v1.42.1 ([#861](googleapis/java-core#861)) ([4d7548b](googleapis/java-core@4d7548b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Method documentation uses child_type resource instead of parent resource in examples
There was an error while loading. Please reload this page.