Use original method names for gRPC paths

Stop converting method names to snake_case when generating the gRPC
service paths to maintain compatibility with protobuf definitions.
This commit is contained in:
2026-05-17 10:44:07 -07:00
parent 89455190b1
commit 33f3e58f74
2 changed files with 9 additions and 9 deletions
+8 -7
View File
@@ -754,22 +754,23 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
for method_res in svc_proto.method() {
let (method_data, _) = method_res.expect("Failed to iterate method");
let method_proto = MethodDescriptorProto::new(method_data).expect("Failed to parse MethodDescriptorProto");
let method_name = to_snake_case(method_proto.name().unwrap());
let original_method_name = method_proto.name().unwrap().to_string();
let method_name = to_snake_case(&original_method_name);
let input_full_name = method_proto.input_type().unwrap();
let input_type = input_full_name.split('.').last().unwrap();
let input_owned = format!("Owned{}", input_type);
let server_streaming = method_proto.server_streaming().unwrap_or(false);
methods.push((method_name, input_owned, server_streaming));
methods.push((original_method_name, method_name, input_owned, server_streaming));
}
for (method_name, input_owned, server_streaming) in methods {
for (original_method_name, method_name, input_owned, server_streaming) in methods {
if server_streaming {
// For streaming RPCs, we don't implement the server logic yet.
// We just make it compile by returning a "not implemented" response.
let full_path = if package.is_empty() {
format!("/{}/{}", svc_proto.name().unwrap(), method_name)
format!("/{}/{}", svc_proto.name().unwrap(), original_method_name)
} else {
format!("/{}.{}/{}", package, svc_proto.name().unwrap(), method_name)
format!("/{}.{}/{}", package, svc_proto.name().unwrap(), original_method_name)
};
output.push_str(&format!(" if path == \"{}\" {{\n", full_path));
output.push_str(" let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));\n");
@@ -778,9 +779,9 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut
continue;
}
let full_path = if package.is_empty() {
format!("/{}/{}", svc_proto.name().unwrap(), method_name)
format!("/{}/{}", svc_proto.name().unwrap(), original_method_name)
} else {
format!("/{}.{}/{}", package, svc_proto.name().unwrap(), method_name)
format!("/{}.{}/{}", package, svc_proto.name().unwrap(), original_method_name)
};
output.push_str(&format!(" if path == \"{}\" {{\n", full_path));
output.push_str(&format!(" let request_msg = match {}::decode(payload) {{\n", input_owned));