Skip to content

Conversation

@cabeedelhertz
Copy link
Contributor

@cabeedelhertz cabeedelhertz commented Jun 24, 2025

References to other Issues or PRs

Fixes #5678

Have you read the Contributing Guidelines? Yes

Brief description of what is fixed or changed

When using standalone=true, this would end up as response := m.extPackageNamepb.ResponseObject where extPackageNamepb is the import alias for the main proto type package. This resulted in invalid syntax and failed to compile.

Seems to have been introduced here #5510 which went out in the latest release. Noticed this issue when bumping protos, and the registering of my gateway handler failed to compile

Other comments

for reference, current behavior vs with this fix, using the response_body_service.proto example:

Current Behavior

...
import (
	extExamplepb "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb"
)
...
type response_ResponseBodyService_GetResponseBody_0 struct {
	*extExamplepb.ResponseBodyOut
}

func (m response_ResponseBodyService_GetResponseBody_0) XXX_ResponseBody() interface{} {
	response := m.extExamplepb.ResponseBodyOut // the "extExamplepb is the package import which should not be there
	return response.Response
}

New behavior

...
import (
	extExamplepb "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb"
)
...
type response_ResponseBodyService_GetResponseBody_0 struct {
	*extExamplepb.ResponseBodyOut
}

func (m response_ResponseBodyService_GetResponseBody_0) XXX_ResponseBody() interface{} {
	response := m.ResponseBodyOut
	return response.Response
}

}

func (m response_UnannotatedEchoService_EchoNested_0) XXX_ResponseBody() interface{} {
response := m.UnannotatedSimpleMessage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

example of standalone=false, the type defined on line 484 is the type defined in the same package

}

func (m response_UnannotatedEchoService_EchoNested_0) XXX_ResponseBody() interface{} {
response := m.UnannotatedSimpleMessage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

example of standalone=true, the type defined on line 839 is the type defined from the external package, but the reference to the object uses the actual type name because thats how we'd reference it from m

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thank you so much for this quick fix! I'll put out a new patch release with this fix as soon as its merged.

@johanbrandhorst johanbrandhorst enabled auto-merge (squash) June 24, 2025 15:59
@johanbrandhorst johanbrandhorst merged commit d08f8db into grpc-ecosystem:main Jun 24, 2025
14 checks passed
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.

Invalid syntax when using standalone with response_body bindings

2 participants