Skip to content

Commit 044befe

Browse files
authored
Fix protoc-gen-go schema variable case handling (#808)
<!-- 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]>
1 parent 867dac8 commit 044befe

File tree

6 files changed

+359
-2
lines changed

6 files changed

+359
-2
lines changed

cmd/protoc-gen-connect-go/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func generateServiceMethodsVar(g *protogen.GeneratedFile, file *protogen.File, s
259259
if len(service.Methods) == 0 {
260260
return
261261
}
262-
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", service.Desc.Name()))
262+
serviceMethodsName := serviceVarMethodsName(service)
263263
g.P(serviceMethodsName, ` := `,
264264
g.QualifiedGoIdent(file.GoDescriptorIdent),
265265
`.Services().ByName("`, service.Desc.Name(), `").Methods()`)
@@ -558,8 +558,12 @@ func procedureHandlerName(m *protogen.Method) string {
558558
return fmt.Sprintf("%s%sHandler", unexport(m.Parent.GoName), m.GoName)
559559
}
560560

561+
func serviceVarMethodsName(m *protogen.Service) string {
562+
return unexport(fmt.Sprintf("%sMethods", m.GoName))
563+
}
564+
561565
func procedureVarMethodDescriptor(m *protogen.Method) string {
562-
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", m.Parent.GoName))
566+
serviceMethodsName := serviceVarMethodsName(m.Parent)
563567
return serviceMethodsName + `.ByName("` + string(m.Desc.Name()) + `")`
564568
}
565569

cmd/protoc-gen-connect-go/main_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/diffpackage/diffpackagediff"
4343
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/noservice"
4444
"connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/samepackage"
45+
_ "connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/v1beta1service"
4546
)
4647

4748
//go:embed testdata
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: v2
2+
managed:
3+
enabled: true
4+
override:
5+
- file_option: go_package_prefix
6+
value: connectrpc.com/connect/cmd/protoc-gen-connect-go/testdata/v1beta1service
7+
plugins:
8+
- local: protoc-gen-go
9+
out: .
10+
opt: paths=source_relative
11+
- local: protoc-gen-connect-go
12+
out: .
13+
opt:
14+
- paths=source_relative
15+
- package_suffix

cmd/protoc-gen-connect-go/testdata/v1beta1service/v1beta1service.connect.go

+123
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/protoc-gen-connect-go/testdata/v1beta1service/v1beta1service.pb.go

+188
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2021-2024 The Connect Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This file tests varying casing of the service name and method name.
16+
syntax = "proto3";
17+
18+
package example;
19+
20+
message GetExample_Request {}
21+
22+
message Get1example_response {}
23+
24+
service ExampleV1beta {
25+
rpc Method(GetExample_Request) returns (Get1example_response) {}
26+
}

0 commit comments

Comments
 (0)