Skip to content

Commit

Permalink
Modify, Fix, fix option field has default and default_factory value
Browse files Browse the repository at this point in the history
  • Loading branch information
so1n committed Oct 19, 2023
1 parent eb2679c commit fdab3a3
Show file tree
Hide file tree
Showing 33 changed files with 37 additions and 75 deletions.
2 changes: 1 addition & 1 deletion example/proto_pydanticv1/demo_gen_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime
Expand Down
2 changes: 1 addition & 1 deletion example/proto_pydanticv1/demo_gen_code_by_p2p.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime, timedelta
Expand Down
2 changes: 1 addition & 1 deletion example/proto_pydanticv1/demo_gen_code_by_pgv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime, timedelta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
from enum import IntEnum

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime, timedelta
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 1.10.7
import typing
from datetime import datetime, timedelta
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/proto_pydanticv2/demo_gen_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime
Expand Down
2 changes: 1 addition & 1 deletion example/proto_pydanticv2/demo_gen_code_by_p2p.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime, timedelta
Expand Down
2 changes: 1 addition & 1 deletion example/proto_pydanticv2/demo_gen_code_by_pgv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime, timedelta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
from enum import IntEnum

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime, timedelta
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.2](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.0
# Protobuf Version: 4.24.4
# Pydantic Version: 2.0.3
import typing
from datetime import datetime, timedelta
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions protobuf_to_pydantic/plugin/field_desc_proto_to_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ def _message_field_handle(

if optional_dict.get(field.name, {}).get("is_proto3_optional", False):
type_str = f"typing.Optional[{type_str}]"
if (
field_info_dict.get("default", _pydantic_adapter.PydanticUndefined)
is _pydantic_adapter.PydanticUndefined
):
if field_info_dict.get(
"default", _pydantic_adapter.PydanticUndefined
) is _pydantic_adapter.PydanticUndefined and not field_info_dict.get("default_factory", None):
field_info_dict["default"] = None

# arranging field info parameters
Expand Down Expand Up @@ -392,26 +391,24 @@ def _message(
if desc.enum_type:
class_head_content += self._enum(desc.enum_type, scl_prefix, indent + self.code_indent)

if desc.oneof_decl:
one_of_dict, optional_dict = self._gen_one_of_dict(desc)
if one_of_dict:
if one_of_dict:
class_head_content += (
f"{' ' * (indent + self.code_indent)}_one_of_dict = {self._get_value_code(one_of_dict)}\n"
)

self._add_import_code("protobuf_to_pydantic.customer_validator", "check_one_of")
if _pydantic_adapter.is_v1:
class_head_content += (
f"{' ' * (indent + self.code_indent)}_one_of_dict = {self._get_value_code(one_of_dict)}\n"
f"{' ' * (indent + self.code_indent)}"
f"one_of_validator = root_validator(pre=True, allow_reuse=True)(check_one_of)\n"
)

self._add_import_code("protobuf_to_pydantic.customer_validator", "check_one_of")
if _pydantic_adapter.is_v1:
class_head_content += (
f"{' ' * (indent + self.code_indent)}"
f"one_of_validator = root_validator(pre=True, allow_reuse=True)(check_one_of)\n"
)
self._add_import_code("pydantic", "root_validator")
else:
class_head_content += (
f"{' ' * (indent + self.code_indent)}"
f'one_of_validator = model_validator(mode="before")(check_one_of)\n'
)
self._add_import_code("pydantic", "model_validator")
self._add_import_code("pydantic", "root_validator")
else:
class_head_content += (
f"{' ' * (indent + self.code_indent)}"
f'one_of_validator = model_validator(mode="before")(check_one_of)\n'
)
self._add_import_code("pydantic", "model_validator")

if use_custom_type:
if _pydantic_adapter.is_v1:
Expand Down
4 changes: 0 additions & 4 deletions protobuf_to_pydantic/protos/protos/p2p_validate_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions protobuf_to_pydantic/protos/protos/validate_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdab3a3

Please sign in to comment.