Skip to content

fix(sidekick/swift): omit default enum values - #7968

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

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

Conversation

@coryan

@coryan coryan commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Update the Swift code generator to support Proto3 default value omission in _ProtoJSONEncoder while preserving explicit presence for optional and oneof fields.

Non-optional singular enum fields are now guarded so default enum values are omitted during encoding. Oneof variants and optional singular Discovery URL-safe byte fields now use encodeIfPresent so explicit zero and empty values remain present in the serialized JSON.

Towards googleapis/google-cloud-swift#828

Generated draft at googleapis/google-cloud-swift#1677

Update the Swift code generator to support Proto3 default value omission
in _ProtoJSONEncoder while preserving explicit presence for optional and
oneof fields.

Non-optional singular enum fields are now guarded so default enum
values are omitted during encoding. Oneof variants and optional singular
Discovery URL-safe byte fields now use encodeIfPresent so explicit zero
and empty values remain present in the serialized JSON.

@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 refines Swift code generation by introducing distinct encoding styles, specifically EncodingOptional and EncodingSingularEnum. It updates the field annotation logic to classify fields accordingly and modifies the Swift templates to use encodeIfPresent for optional and oneof fields, and conditional encoding for singular enums to avoid encoding default values. Corresponding unit and integration tests have been added and updated to validate the generated Swift code. There are no review comments, and I have no feedback to provide.

@coryan
coryan marked this pull request as ready for review November 20, 2026 22:13
@coryan
coryan requested a review from a team as a code owner November 20, 2026 22:13
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