Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix protoc-gen-connect-go schema variable case handling #808

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
}
Loading