Skip to content

Commit ae678d2

Browse files
authored
extensions/prost/private/protoc_wrapper: codegen for enums was broken (#3326)
When generating a message that contains a field that is an enum, the generated code was not following the proper upper camel case convention, making it fail to build. Example: ``` message Test { some.pkg.SomethingID test = 1; } ``` ``` #[prost(enumeration="super::some::pkg::SomethingID", tag="1")] pub test: i32, ``` When we actually expects `SomethingId` because prost generates it like that.
1 parent f2ec612 commit ae678d2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

extensions/prost/private/protoc_wrapper.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ fn enum_type_to_extern_paths(
393393
.expect("Failed to get enum type name");
394394
extern_paths.insert(
395395
proto_path.join(enum_type_name),
396-
rust_path.join(enum_type_name),
396+
rust_path.join(&enum_type_name.to_upper_camel_case()),
397397
);
398398
}
399399

@@ -1017,6 +1017,30 @@ mod test {
10171017
}
10181018
}
10191019

1020+
#[test]
1021+
fn enum_type_to_extern_paths_upper_camel_case_test() {
1022+
let enum_descriptor = EnumDescriptorProto {
1023+
name: Some("SomethingID".to_string()),
1024+
..EnumDescriptorProto::default()
1025+
};
1026+
1027+
{
1028+
let mut extern_paths = BTreeMap::new();
1029+
enum_type_to_extern_paths(
1030+
&mut extern_paths,
1031+
&ProtoPath::from("bar"),
1032+
&RustModulePath::from("bar"),
1033+
&enum_descriptor,
1034+
);
1035+
1036+
assert_eq!(extern_paths.len(), 1);
1037+
assert_eq!(
1038+
extern_paths.get(&ProtoPath::from("bar.SomethingID")),
1039+
Some(&RustModulePath::from("bar::SomethingId"))
1040+
);
1041+
}
1042+
}
1043+
10201044
#[test]
10211045
fn enum_type_to_extern_paths_test() {
10221046
let enum_descriptor = EnumDescriptorProto {

extensions/prost/private/tests/camel_case/another.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import "camel_case.proto";
66

77
message Another {
88
camel_case.NameWithCAPS inner = 1;
9+
camel_case.SomethingID something = 2;
910
}

extensions/prost/private/tests/camel_case/camel_case.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ syntax = "proto3";
22

33
package camel_case;
44

5+
enum SomethingID {
6+
UNKNOWN = 0;
7+
SOMETHING = 1;
8+
}
9+
510
message NameWithCAPS {
611
string name = 1;
712
}

0 commit comments

Comments
 (0)