From 38706313f86dc5bb470abcf00c1fa3e13352835a Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Thu, 16 Jan 2025 17:06:57 +0100 Subject: [PATCH 1/2] Fix synthetic oneofs --- src/betterproto2_compiler/plugin/parser.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/betterproto2_compiler/plugin/parser.py b/src/betterproto2_compiler/plugin/parser.py index cdea4999..29dda0af 100644 --- a/src/betterproto2_compiler/plugin/parser.py +++ b/src/betterproto2_compiler/plugin/parser.py @@ -227,14 +227,21 @@ def read_protobuf_type( ) ) - for index, oneof in enumerate(item.oneof_decl): - message_data.oneofs.append( - OneofCompiler( - source_file=source_file, - path=path + [8, index], - proto_obj=oneof, + # Synthetic oneofs are generated for optional fields. We should not generate code or documentation for them. + is_synthetic_oneof = [True for _ in item.oneof_decl] + for field in item.field: + if field.oneof_index is not None and not field.proto3_optional: + is_synthetic_oneof[field.oneof_index] = False + + for index, (oneof, is_synthetic) in enumerate(zip(item.oneof_decl, is_synthetic_oneof)): + if not is_synthetic: + message_data.oneofs.append( + OneofCompiler( + source_file=source_file, + path=path + [8, index], + proto_obj=oneof, + ) ) - ) elif isinstance(item, EnumDescriptorProto): # Enum From 9ff96fa9644877cfbf2b01642defd5ebe05f8c56 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Thu, 16 Jan 2025 17:07:24 +0100 Subject: [PATCH 2/2] Bump to 0.2.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e5c9696f..e93ccaa3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "betterproto2_compiler" -version = "0.2.0" +version = "0.2.1" description = "Compiler for betterproto2" authors = ["Adrien Vannson ", "Daniel G. Taylor "] readme = "README.md"