Skip to content

feat(gapic-generator-typescript): add compatibility-resources flag#8405

Draft
jskeet wants to merge 1 commit into
googleapis:mainfrom
jskeet:multi-pattern-compatibility
Draft

feat(gapic-generator-typescript): add compatibility-resources flag#8405
jskeet wants to merge 1 commit into
googleapis:mainfrom
jskeet:multi-pattern-compatibility

Conversation

@jskeet
Copy link
Copy Markdown
Contributor

@jskeet jskeet commented Jun 1, 2026

This allows resources which have multiple patterns to also still generate the functions/templates which would have been generated if it were a single-pattern resource.

Addresses #7718 but in a selective way. (We don't always generate the legacy pattern, only when requested.)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

This allows resources which have multiple patterns to also still
generate the functions/templates which would have been generated if it
were a single-pattern resource.

Addresses googleapis#7718 but in a selective way. (We don't *always* generate
the legacy pattern, only when requested.)
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new compatibility-resources option to the TypeScript GAPIC generator, allowing multi-pattern resources to also generate old single-pattern functions for backwards compatibility. The changes span CLI parsing, generator configuration, and resource database handling. Feedback on the changes includes fixing an incorrectly formatted error string in proto.ts that fails to interpolate the type variable, and changing a variable declaration from let to const in resource-database.ts as it is never reassigned.

if (compatibilityResource) {
uniqueResources[compatibilityResource.name] = compatibilityResource;
} else {
throw new Error('Resource "${type} has no compatibility pattern')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The error message is defined as a single-quoted string literal but contains a ${type} placeholder, which will not be interpolated. Additionally, it has an unclosed double quote. Use string concatenation or a template literal to correctly interpolate the type variable.

        throw new Error('Resource "' + type + '" has no compatibility pattern');

const pattern = patterns![0]
const name = arr![1];
const params = this.getParams(pattern);
let compatibilityResourceDescriptor = this.getResourceDescriptor(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The variable compatibilityResourceDescriptor is never reassigned, so it should be declared using const instead of let to adhere to TypeScript best practices.

Suggested change
let compatibilityResourceDescriptor = this.getResourceDescriptor(
const compatibilityResourceDescriptor = this.getResourceDescriptor(

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