Skip to content

fix(gengapic): use recursive resource name heuristic#1698

Closed
quartzmo wants to merge 1 commit intogoogleapis:mainfrom
quartzmo:gengapic-tracing-resource-reference
Closed

fix(gengapic): use recursive resource name heuristic#1698
quartzmo wants to merge 1 commit intogoogleapis:mainfrom
quartzmo:gengapic-tracing-resource-reference

Conversation

@quartzmo
Copy link
Copy Markdown
Member

@quartzmo quartzmo commented Feb 6, 2026

Refactor the resource identifying field heuristic to be recursive and address specific gaps in the current implementation.

Satisfies Requirements:

  1. Nested Field Support: Recursively searches for fields annotated with google.api.resource_reference up to 2 levels deep. This directly addresses AIP-134 (Update) scenarios where the resource is often nested (e.g., req.Secret.Name).
  2. Tie-breaking: Prioritizes annotated fields that also appear in the method's google.api.http path template, ensuring the correct "primary" resource is selected when multiple references exist.
  3. Code Generation: Returns the full field path (e.g., secret.name) to generate idiomatic Go accessors for nested fields (e.g., req.GetSecret().GetName()), addressing AIP-134 scenarios.

TODO (Remaining Requirements from Design):

  • Vocabulary Learning: Implement generation-time scanning to build a
    vocabulary of valid resource types from HTTP path literals. This is
    required for legacy services (Compute, SQL, BigQuery) that lack
    annotations.
  • Path Reconstruction: Implement logic to parse "exploded" HTTP
    paths and generate code to reassemble multiple request fields into a
    single canonical resource name.
  • Path Pruning: Implement logic to prune non-resource segments
    (custom verbs) from reconstructed paths.
  • Heuristic Allow-listing: Add configuration to restrict these
    advanced heuristics to the specific legacy services identified in the
    design.

Tests added in internal/gengapic/resource_name_test.go verify the recursive search and tie-breaking logic.

@quartzmo quartzmo requested a review from a team as a code owner February 6, 2026 21:05
@quartzmo quartzmo force-pushed the gengapic-tracing-resource-reference branch 3 times, most recently from 5f86b92 to 68ced14 Compare February 7, 2026 00:09
@quartzmo quartzmo changed the title feat(gengapic): recursive resource name heuristic and TODOs feat(gengapic): recursive resource name heuristic Feb 7, 2026
@quartzmo quartzmo changed the title feat(gengapic): recursive resource name heuristic feat(gengapic): use recursive resource name heuristic Feb 7, 2026
@quartzmo quartzmo changed the title feat(gengapic): use recursive resource name heuristic fix(gengapic): use recursive resource name heuristic Feb 7, 2026
Update the resource identifying field heuristic to be recursive.

Satisfies Requirements:
1.  **Nested Field Support:** Recursively searches for fields annotated
    with `google.api.resource_reference` up to 2 levels deep. This
    directly addresses AIP-134 (Update) scenarios where the resource is
    often nested (e.g., `req.Secret.Name`).
2.  **Tie-breaking:** Prioritizes annotated fields that also appear in
    the method's `google.api.http` path template, ensuring the correct
    "primary" resource is selected when multiple references exist.
3.  **Code Generation:** Returns the full field path (e.g., `secret.name`)
    and uses a `fieldGetter` helper to generate idiomatic Go accessors
    (e.g., `req.GetSecret().GetName()`), fixing a previous omission where
    nested fields could not be accessed.
@quartzmo quartzmo force-pushed the gengapic-tracing-resource-reference branch from 68ced14 to b934f91 Compare February 7, 2026 00:19
@quartzmo quartzmo marked this pull request as draft February 7, 2026 00:20
@quartzmo
Copy link
Copy Markdown
Member Author

Replaced by #1722

@quartzmo quartzmo closed this Apr 16, 2026
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.

1 participant