Skip to content

Commit

Permalink
Fix protoc-gen-go schema variable case handling (#808)
Browse files Browse the repository at this point in the history
<!--
Before submitting your PR, please read through the contribution guide!


https://github.com/connectrpc/connect-go/blob/main/.github/CONTRIBUTING.md
-->
This fixes the handling of various casing when generating the service
methods variable.

Fixes #807

Signed-off-by: Edward McFarlane <[email protected]>
  • Loading branch information
emcfarlane authored Jan 8, 2025
1 parent 867dac8 commit 044befe
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/protoc-gen-connect-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func generateServiceMethodsVar(g *protogen.GeneratedFile, file *protogen.File, s
if len(service.Methods) == 0 {
return
}
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", service.Desc.Name()))
serviceMethodsName := serviceVarMethodsName(service)
g.P(serviceMethodsName, ` := `,
g.QualifiedGoIdent(file.GoDescriptorIdent),
`.Services().ByName("`, service.Desc.Name(), `").Methods()`)
Expand Down Expand Up @@ -558,8 +558,12 @@ func procedureHandlerName(m *protogen.Method) string {
return fmt.Sprintf("%s%sHandler", unexport(m.Parent.GoName), m.GoName)
}

func serviceVarMethodsName(m *protogen.Service) string {
return unexport(fmt.Sprintf("%sMethods", m.GoName))
}

func procedureVarMethodDescriptor(m *protogen.Method) string {
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", m.Parent.GoName))
serviceMethodsName := serviceVarMethodsName(m.Parent)
return serviceMethodsName + `.ByName("` + string(m.Desc.Name()) + `")`
}

Expand Down
1 change: 1 addition & 0 deletions cmd/protoc-gen-connect-go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/diffpackage/diffpackagediff"
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/noservice"
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/samepackage"
_ "connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/v1beta1service"
)

//go:embed testdata
Expand Down
15 changes: 15 additions & 0 deletions cmd/protoc-gen-connect-go/testdata/v1beta1service/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: v2
managed:
enabled: true
override:
- file_option: go_package_prefix
value: connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/v1beta1service
plugins:
- local: protoc-gen-go
out: .
opt: paths=source_relative
- local: protoc-gen-connect-go
out: .
opt:
- paths=source_relative
- package_suffix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

188 changes: 188 additions & 0 deletions cmd/protoc-gen-connect-go/testdata/v1beta1service/v1beta1service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021-2024 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This file tests varying casing of the service name and method name.
syntax = "proto3";

package example;

message GetExample_Request {}

message Get1example_response {}

service ExampleV1beta {
rpc Method(GetExample_Request) returns (Get1example_response) {}
}

0 comments on commit 044befe

Please sign in to comment.