feat(gapic-generator-typescript): add compatibility-resources flag#8405
feat(gapic-generator-typescript): add compatibility-resources flag#8405jskeet wants to merge 1 commit into
Conversation
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.)
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
The variable compatibilityResourceDescriptor is never reassigned, so it should be declared using const instead of let to adhere to TypeScript best practices.
| let compatibilityResourceDescriptor = this.getResourceDescriptor( | |
| const compatibilityResourceDescriptor = this.getResourceDescriptor( |
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:
Fixes #<issue_number_goes_here> 🦕