Skip to content

feat(generator/rust): methods w/o HTTP annotations #1818

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

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
17 changes: 16 additions & 1 deletion generator/internal/rust/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func newCodec(protobufSource bool, options map[string]string) (*codec, error) {
codec.disabledRustdocWarnings = strings.Split(definition, ",")
case key == "template-override":
codec.templateOverride = definition
case key == "include-grpc-only-methods":
value, err := strconv.ParseBool(definition)
if err != nil {
return nil, fmt.Errorf("cannot convert `include-grpc-only-methods` value %q to boolean: %w", definition, err)
}
codec.includeGrpcOnlyMethods = value
default:
return nil, fmt.Errorf("unknown Rust codec option %q", key)
}
Expand Down Expand Up @@ -204,6 +210,9 @@ type codec struct {
systemParameters []systemParameter
// Overrides the template sudirectory.
templateOverride string
// If true, this includes gRPC-only methods, such as methods without HTTP
// annotations.
includeGrpcOnlyMethods bool
}

type systemParameter struct {
Expand Down Expand Up @@ -1520,7 +1529,13 @@ func (c *codec) generateMethod(m *api.Method) bool {
// RPCs for them.
// TODO(#499) - switch to explicitly excluding such functions. Easier to
// find them and fix them that way.
return !m.ClientSideStreaming && !m.ServerSideStreaming && m.PathInfo != nil && len(m.PathInfo.PathTemplate) != 0
if m.ClientSideStreaming || m.ServerSideStreaming {
return false
}
if c.includeGrpcOnlyMethods {
return true
}
return m.PathInfo != nil && len(m.PathInfo.PathTemplate) != 0
}

// The list of Rust keywords and reserved words can be found at:
Expand Down
16 changes: 9 additions & 7 deletions generator/internal/rust/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ func createRustCodec() *codec {

func TestParseOptionsProtobuf(t *testing.T) {
options := map[string]string{
"version": "1.2.3",
"package-name-override": "test-only",
"copyright-year": "2035",
"module-path": "alternative::generated",
"package:wkt": "package=types,path=src/wkt,source=google.protobuf,source=test-only",
"package:gax": "package=gax,path=src/gax,feature=unstable-sdk-client",
"package:serde_with": "package=serde_with,version=2.3.4,default-features=false",
"version": "1.2.3",
"package-name-override": "test-only",
"copyright-year": "2035",
"module-path": "alternative::generated",
"package:wkt": "package=types,path=src/wkt,source=google.protobuf,source=test-only",
"package:gax": "package=gax,path=src/gax,feature=unstable-sdk-client",
"package:serde_with": "package=serde_with,version=2.3.4,default-features=false",
"include-grpc-only-methods": "true",
}
got, err := newCodec(true, options)
if err != nil {
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestParseOptionsProtobuf(t *testing.T) {
systemParameters: []systemParameter{
{Name: "$alt", Value: "json;enum-encoding=int"},
},
includeGrpcOnlyMethods: true,
}
sort.Slice(want.extraPackages, func(i, j int) bool {
return want.extraPackages[i].name < want.extraPackages[j].name
Expand Down
Loading