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() { for method_res in svc_proto.method() {
let (method_data, _) = method_res.expect("Failed to iterate 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_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_full_name = method_proto.input_type().unwrap();
let input_type = input_full_name.split('.').last().unwrap(); let input_type = input_full_name.split('.').last().unwrap();
let input_owned = format!("Owned{}", input_type); let input_owned = format!("Owned{}", input_type);
let server_streaming = method_proto.server_streaming().unwrap_or(false); 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 { if server_streaming {
// For streaming RPCs, we don't implement the server logic yet. // For streaming RPCs, we don't implement the server logic yet.
// We just make it compile by returning a "not implemented" response. // We just make it compile by returning a "not implemented" response.
let full_path = if package.is_empty() { let full_path = if package.is_empty() {
format!("/{}/{}", svc_proto.name().unwrap(), method_name) format!("/{}/{}", svc_proto.name().unwrap(), original_method_name)
} else { } 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!(" 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"); 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; continue;
} }
let full_path = if package.is_empty() { let full_path = if package.is_empty() {
format!("/{}/{}", svc_proto.name().unwrap(), method_name) format!("/{}/{}", svc_proto.name().unwrap(), original_method_name)
} else { } 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!(" if path == \"{}\" {{\n", full_path));
output.push_str(&format!(" let request_msg = match {}::decode(payload) {{\n", input_owned)); output.push_str(&format!(" let request_msg = match {}::decode(payload) {{\n", input_owned));
+1 -2
View File
@@ -463,7 +463,6 @@ impl Service<http::Request<BoxBody>> for InteropServiceServer {
let payload = bytes_vec.slice(5..); let payload = bytes_vec.slice(5..);
let mut routed = false; let mut routed = false;
if path == "/interop.InteropService/UnaryCall" { if path == "/interop.InteropService/UnaryCall" {
let request_msg = match OwnedUnaryRequest::decode(payload) { let request_msg = match OwnedUnaryRequest::decode(payload) {
Ok(msg) => msg, Ok(msg) => msg,
@@ -495,7 +494,7 @@ impl Service<http::Request<BoxBody>> for InteropServiceServer {
routed = true; routed = true;
return Ok(http::Response::builder().status(200).header("content-type", "application/grpc").body(res_body).unwrap()); return Ok(http::Response::builder().status(200).header("content-type", "application/grpc").body(res_body).unwrap());
} }
if path == "/interop.InteropService/streaming_call" { if path == "/interop.InteropService/StreamingCall" {
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
return Ok(http::Response::builder().status(200).body(res_body).unwrap()); return Ok(http::Response::builder().status(200).body(res_body).unwrap());
} }