Skip to content

Commit 5f7a6d8

Browse files
authored
Merge pull request #77 from so1n/76-unbalanced-when-processing-cases-like-same-name-but-in-diffrent-ds
76 unbalanced when processing cases like same name but in diffrent ds
2 parents 1a5555c + 709fabb commit 5f7a6d8

File tree

75 files changed

+1972
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1972
-99
lines changed

example/example_proto/demo/demo.proto

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,21 @@ message AnOtherMessage {
141141
string text = 1;
142142
}
143143
}
144+
145+
// Test inline structure of the same name
146+
// from: https://github.com/so1n/protobuf_to_pydantic/issues/76
147+
message TestSameName0 {
148+
message Body {
149+
string input_model = 1;
150+
map<string, string> input_info = 3;
151+
}
152+
Body body = 1;
153+
}
154+
155+
message TestSameName1 {
156+
message Body {
157+
string output_model = 1;
158+
map<string, string> output_info = 3;
159+
}
160+
Body body = 1;
161+
}

example/gen_simple_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
def gen_code() -> None:
3333
pydantic_model_to_py_file(
3434
str(now_path.parent.joinpath(target_p, "demo_gen_code.py")),
35-
*[msg_to_pydantic_model(model) for model in message_class_list if model.__name__ == "OptionalMessage"],
35+
*[msg_to_pydantic_model(model) for model in message_class_list],
3636
)
3737

3838

example/proto_3_20_pydanticv1/demo_gen_code.py

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,121 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing
6+
from datetime import datetime
7+
from enum import IntEnum
68

9+
from google.protobuf.field_mask_pb2 import FieldMask # type: ignore
10+
from google.protobuf.wrappers_pb2 import DoubleValue # type: ignore
711
from protobuf_to_pydantic.customer_validator.v1 import check_one_of
812
from pydantic import BaseModel, Field, root_validator
913

1014

15+
class AfterReferMessage(BaseModel):
16+
uid: str = Field(default="")
17+
age: int = Field(default=0)
18+
19+
20+
class AnOtherMessage(BaseModel):
21+
class SubMessage(BaseModel):
22+
text: str = Field(default="")
23+
24+
field1: str = Field(default="")
25+
field2: SubMessage = Field()
26+
27+
28+
class EmptyMessage(BaseModel):
29+
pass
30+
31+
32+
class InvoiceItem2(BaseModel):
33+
name: str = Field(default="")
34+
amount: int = Field(default=0)
35+
quantity: int = Field(default=0)
36+
items: typing.List["InvoiceItem2"] = Field(default_factory=list)
37+
invoice: "Invoice3" = Field()
38+
39+
40+
class Invoice3(BaseModel):
41+
name: str = Field(default="")
42+
amount: int = Field(default=0)
43+
quantity: int = Field(default=0)
44+
items: typing.List[InvoiceItem2] = Field(default_factory=list)
45+
46+
1147
class InvoiceItem(BaseModel):
1248
name: str = Field(default="")
1349
amount: int = Field(default=0)
1450
quantity: int = Field(default=0)
1551
items: typing.List["InvoiceItem"] = Field(default_factory=list)
1652

1753

54+
class SexType(IntEnum):
55+
man = 0
56+
women = 1
57+
58+
59+
class ExampleExampleProtoCommonSingleDemoEnum(IntEnum):
60+
"""Note: The current class does not belong to the package
61+
ExampleExampleProtoCommonSingleDemoEnum protobuf path:example/example_proto/common/single.proto"""
62+
63+
zero = 0
64+
one = 1
65+
two = 3
66+
67+
68+
class ExampleExampleProtoCommonSingleDemoMessage(BaseModel):
69+
"""Note: The current class does not belong to the package
70+
ExampleExampleProtoCommonSingleDemoMessage protobuf path:example/example_proto/common/single.proto"""
71+
72+
earth: str = Field(default="")
73+
mercury: str = Field(default="")
74+
mars: str = Field(default="")
75+
76+
77+
class UserMessage(BaseModel):
78+
uid: str = Field(default="")
79+
age: int = Field(default=0)
80+
height: float = Field(default=0.0)
81+
sex: SexType = Field(default=0)
82+
demo: ExampleExampleProtoCommonSingleDemoEnum = Field(default=0)
83+
is_adult: bool = Field(default=False)
84+
user_name: str = Field(default="")
85+
demo_message: ExampleExampleProtoCommonSingleDemoMessage = Field()
86+
87+
88+
class MapMessage(BaseModel):
89+
user_map: typing.Dict[str, UserMessage] = Field(default_factory=dict)
90+
user_flag: typing.Dict[str, bool] = Field(default_factory=dict)
91+
92+
93+
class RepeatedMessage(BaseModel):
94+
str_list: typing.List[str] = Field(default_factory=list)
95+
int_list: typing.List[int] = Field(default_factory=list)
96+
user_list: typing.List[UserMessage] = Field(default_factory=list)
97+
98+
99+
class NestedMessage(BaseModel):
100+
class UserPayMessage(BaseModel):
101+
bank_number: str = Field(default="")
102+
exp: datetime = Field(default_factory=datetime.now)
103+
uuid: str = Field(default="")
104+
105+
class IncludeEnum(IntEnum):
106+
zero = 0
107+
one = 1
108+
two = 2
109+
110+
user_list_map: typing.Dict[str, RepeatedMessage] = Field(default_factory=dict)
111+
user_map: typing.Dict[str, MapMessage] = Field(default_factory=dict)
112+
user_pay: UserPayMessage = Field()
113+
include_enum: IncludeEnum = Field(default=0)
114+
not_enable_user_pay: UserPayMessage = Field()
115+
empty: typing.Any = Field()
116+
after_refer: AfterReferMessage = Field()
117+
118+
18119
class OptionalMessage(BaseModel):
19120
_one_of_dict = {"user.OptionalMessage.a": {"fields": {"x", "y"}, "required": False}}
20121

@@ -28,3 +129,33 @@ class OptionalMessage(BaseModel):
28129
default_template_test: float = Field(default=0.0)
29130

30131
one_of_validator = root_validator(pre=True, allow_reuse=True)(check_one_of)
132+
133+
134+
class OtherMessage(BaseModel):
135+
class Config:
136+
arbitrary_types_allowed = True
137+
138+
metadata: typing.Dict[str, typing.Any] = Field(default_factory=dict)
139+
double_value: DoubleValue = Field(default_factory=DoubleValue)
140+
field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)
141+
142+
143+
class RootMessage(BaseModel):
144+
field1: str = Field(default="")
145+
field2: AnOtherMessage = Field()
146+
147+
148+
class TestSameName0(BaseModel):
149+
class Body(BaseModel):
150+
input_model: str = Field(default="")
151+
input_info: typing.Dict[str, str] = Field(default_factory=dict)
152+
153+
body: Body = Field()
154+
155+
156+
class TestSameName1(BaseModel):
157+
class Body(BaseModel):
158+
output_model: str = Field(default="")
159+
output_info: typing.Dict[str, str] = Field(default_factory=dict)
160+
161+
body: Body = Field()

example/proto_3_20_pydanticv1/demo_gen_code_by_p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing

example/proto_3_20_pydanticv1/demo_gen_code_by_pgv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing

example/proto_3_20_pydanticv1/demo_gen_code_by_text_comment_protobuf_field.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing
@@ -145,3 +145,19 @@ class Config:
145145
class RootMessage(BaseModel):
146146
field1: str = Field(default="")
147147
field2: AnOtherMessage = Field()
148+
149+
150+
class TestSameName0(BaseModel):
151+
class Body(BaseModel):
152+
input_model: str = Field(default="")
153+
input_info: typing.Dict[str, str] = Field(default_factory=dict)
154+
155+
body: Body = Field()
156+
157+
158+
class TestSameName1(BaseModel):
159+
class Body(BaseModel):
160+
output_model: str = Field(default="")
161+
output_info: typing.Dict[str, str] = Field(default_factory=dict)
162+
163+
body: Body = Field()

example/proto_3_20_pydanticv1/demo_gen_code_by_text_comment_pyi.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing
@@ -145,3 +145,19 @@ class Config:
145145
class RootMessage(BaseModel):
146146
field1: str = Field(default="")
147147
field2: AnOtherMessage = Field()
148+
149+
150+
class TestSameName0(BaseModel):
151+
class Body(BaseModel):
152+
input_model: str = Field(default="")
153+
input_info: typing.Dict[str, str] = Field(default_factory=dict)
154+
155+
body: Body = Field()
156+
157+
158+
class TestSameName1(BaseModel):
159+
class Body(BaseModel):
160+
output_model: str = Field(default="")
161+
output_info: typing.Dict[str, str] = Field(default_factory=dict)
162+
163+
body: Body = Field()

example/proto_3_20_pydanticv1/example/example_proto/common/single_p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
from enum import IntEnum

example/proto_3_20_pydanticv1/example/example_proto/demo/alias_demo_p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing

example/proto_3_20_pydanticv1/example/example_proto/demo/all_feidl_set_optional_demo_p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is an automatically generated file, please do not change
2-
# gen by protobuf_to_pydantic[v0.3.0](https://github.com/so1n/protobuf_to_pydantic)
2+
# gen by protobuf_to_pydantic[0.0.0](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 3.20.3
44
# Pydantic Version: 1.10.7
55
import typing

0 commit comments

Comments
 (0)