Skip to content

fix(sidekick/swift): route scalar and enum fields - #7975

Draft
coryan wants to merge 1 commit into
googleapis:mainfrom
coryan:fix/swift-routing-scalars
Draft

coryan wants to merge 1 commit into
googleapis:mainfrom
coryan:fix/swift-routing-scalars

Conversation

@coryan

@coryan coryan commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Resolve routing parameter field paths against input messages in gRPC mode so generated Swift transport code handles string, primitive scalar, protobuf enum, and Discovery string enum fields across nested and optional paths while adding required package imports for MemberImportVisibility.

For googleapis/google-cloud-swift#1631

Resolve routing parameter field paths against input messages in gRPC
mode so generated Swift transport code handles string, primitive scalar,
protobuf enum, and Discovery string enum fields across nested and
optional paths while adding required package imports for
MemberImportVisibility.

For googleapis/google-cloud-swift#1631

@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 refactors the extraction and formatting of AIP-4222 routing parameters for Swift gRPC clients. It replaces the simple string-based FieldAccessor with a structured FieldSteps slice (using routingFieldStep), allowing robust resolution of nested, optional, and enum field paths. It also introduces comprehensive unit and integration tests to verify routing parameter generation across various scalar, optional, and enum types. The review feedback suggests simplifying the ensureRoutingFieldAnnotated method in internal/sidekick/swift/format_path.go to make it more idiomatic by directly returning the result of c.annotateField.

Comment on lines +293 to +306
func (c *codec) ensureRoutingFieldAnnotated(field *api.Field, modelAnn *modelAnnotations) (*fieldAnnotations, error) {
fieldAnn, ok := field.Codec().(*fieldAnnotations)
if !ok {
if c.Model == nil {
return nil, fmt.Errorf("internal error: field %s does not have swift fieldAnnotations", field.ID())
}
var err error
fieldAnn, err = c.annotateField(field, modelAnn)
if err != nil {
return nil, err
}
}
return fieldAnn, nil
}

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 implementation of ensureRoutingFieldAnnotated can be simplified and made more idiomatic by directly returning the result of c.annotateField if the field is not already annotated, rather than using an explicit var err error declaration and assignment inside the if !ok block.

func (c *codec) ensureRoutingFieldAnnotated(field *api.Field, modelAnn *modelAnnotations) (*fieldAnnotations, error) {
	if fieldAnn, ok := field.Codec().(*fieldAnnotations); ok {
		return fieldAnn, nil
	}
	if c.Model == nil {
		return nil, fmt.Errorf("internal error: field %s does not have swift fieldAnnotations", field.ID())
	}
	return c.annotateField(field, modelAnn)
}

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