8000 fix(sidekick/swift): tighten conversion imports by coryan · Pull Request #8019 · googleapis/librarian · GitHub
[go: up one dir, main page]

Skip to content

fix(sidekick/swift): tighten conversion imports - #8019

Open
coryan wants to merge 1 commit into
googleapis:mainfrom
coryan:fix-issue-1704
Open

coryan wants to merge 1 commit into
googleapis:mainfrom
coryan:fix-issue-1704

Conversation

@coryan
@coryan coryan commented Dec 5, 2026
Copy link
Copy Markdown
Contributor

Remove extraneous imports from generated Swift conversion files. Previously, message conversion files unconditionally imported GoogleGax and always emitted GoogleWKTConvert alongside GoogleWKT, while enum conversion files unconditionally imported SwiftProtobuf.

Message conversion files now import GoogleWKTConvert only when the message or a nested message converts a google.protobuf field without an LROAnyConverter, recomputing NeedsWktConvert after LROAnyConverter fields are populated on Operation. They import GoogleGax only when the message or a nested message declares nested enums, which throw ProtobufConversionError. Enum conversion files omit SwiftProtobuf when ModulePath is configured, because generated proto enums declare the rawValue initializer directly.

For googleapis/google-cloud-swift#1704

Generated code at googleapis/google-cloud-swift#1754

Remove extraneous imports from generated Swift conversion files.
Previously, message conversion files unconditionally imported GoogleGax
and always emitted GoogleWKTConvert alongside GoogleWKT, while enum
conversion files unconditionally imported SwiftProtobuf.

Message conversion files now import GoogleWKTConvert only when the
message or a nested message converts a google.protobuf field without an
LROAnyConverter, recomputing NeedsWktConvert after LROAnyConverter
fields are populated on Operation. They import GoogleGax only when the
message or a nested message declares nested enums, which throw
ProtobufConversionError. Enum conversion files omit SwiftProtobuf when
ModulePath is configured, because generated proto enums declare the
rawValue initializer directly.

For googleapis/google-cloud-swift#1704
@gemini-code-assist gemini-code-assist Bot left a comment
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.

Code Review

This pull request optimizes Swift code generation by conditionally importing GoogleGax and GoogleWKTConvert based on whether a message contains nested enums or requires Well-Known Type (WKT) conversions. It introduces helper functions to determine these requirements, updates the messageAnnotations struct, and refactors the template files to apply these conditional imports. Comprehensive unit tests have been added and updated to verify the new import logic. No review comments were provided, and the implementation is clean and well-tested.

@coryan
coryan marked this pull request as ready for review December 5, 2026 16:28
@coryan
coryan requested a review from a team as a code owner December 5, 2026 16:28
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

0