Skip to content

Commit

Permalink
Merge pull request #52 from so1n/51-issue-with-googleprotobufdoublevalue
Browse files Browse the repository at this point in the history
Feat, support google.protobuf.xxx message and plugin add protobuf typ…
  • Loading branch information
so1n authored Apr 17, 2024
2 parents c1d71ab + 16e8056 commit 6f626ea
Show file tree
Hide file tree
Showing 31 changed files with 432 additions and 458 deletions.
7 changes: 3 additions & 4 deletions example/example_proto/demo/demo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/wrappers.proto";
import "example/example_proto/common/single.proto";

enum SexType {
Expand All @@ -29,11 +30,9 @@ message UserMessage {
single.DemoMessage demo_message=9; // p2p: {"extra": {"customer_string": "c1", "customer_int": 1}}
}

message StructMessage {
message OtherMessage {
google.protobuf.Struct metadata=1;
}

message FieldMaskMessage {
google.protobuf.DoubleValue double_value = 2;
optional google.protobuf.FieldMask field_mask = 100;
}

Expand Down
15 changes: 7 additions & 8 deletions example/proto_3_20_pydanticv1/demo_gen_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from enum import IntEnum

from google.protobuf.field_mask_pb2 import FieldMask # type: ignore
from google.protobuf.wrappers_pb2 import DoubleValue # type: ignore
from pydantic import BaseModel, Field


Expand All @@ -19,13 +20,6 @@ class EmptyMessage(BaseModel):
pass


class FieldMaskMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)


class InvoiceItem(BaseModel):
name: str = Field(default="")
amount: int = Field(default=0)
Expand Down Expand Up @@ -106,5 +100,10 @@ class OptionalMessage(BaseModel):
int_map: typing.Dict[str, int] = Field(default_factory=dict)


class StructMessage(BaseModel):
class OtherMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

metadata: typing.Dict[str, typing.Any] = Field(default_factory=dict)
double_value: DoubleValue = Field(default_factory=DoubleValue)
field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from uuid import uuid4

from google.protobuf.field_mask_pb2 import FieldMask # type: ignore
from google.protobuf.wrappers_pb2 import DoubleValue # type: ignore
from pydantic import BaseModel, Field
from pydantic.types import PaymentCardNumber

Expand All @@ -23,13 +24,6 @@ class EmptyMessage(BaseModel):
pass


class FieldMaskMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)


class InvoiceItem(BaseModel):
name: str = Field(default="")
amount: int = Field(default=0)
Expand Down Expand Up @@ -109,5 +103,10 @@ class OptionalMessage(BaseModel):
int_map: typing.Dict[str, int] = Field(default_factory=dict)


class StructMessage(BaseModel):
class OtherMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

metadata: typing.Dict[str, typing.Any] = Field(default_factory=dict)
double_value: DoubleValue = Field(default_factory=DoubleValue)
field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from uuid import uuid4

from google.protobuf.field_mask_pb2 import FieldMask # type: ignore
from google.protobuf.wrappers_pb2 import DoubleValue # type: ignore
from pydantic import BaseModel, Field
from pydantic.types import PaymentCardNumber

Expand All @@ -23,13 +24,6 @@ class EmptyMessage(BaseModel):
pass


class FieldMaskMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)


class InvoiceItem(BaseModel):
name: str = Field(default="")
amount: int = Field(default=0)
Expand Down Expand Up @@ -109,5 +103,10 @@ class OptionalMessage(BaseModel):
int_map: typing.Dict[str, int] = Field(default_factory=dict)


class StructMessage(BaseModel):
class OtherMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

metadata: typing.Dict[str, typing.Any] = Field(default_factory=dict)
double_value: DoubleValue = Field(default_factory=DoubleValue)
field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from google.protobuf.field_mask_pb2 import FieldMask # type: ignore
from google.protobuf.message import Message # type: ignore
from google.protobuf.wrappers_pb2 import DoubleValue # type: ignore
from pydantic import BaseModel, Field

from ..common.single_p2p import DemoEnum, DemoMessage
Expand All @@ -29,14 +30,12 @@ class UserMessage(BaseModel):
demo_message: DemoMessage = Field()


class StructMessage(BaseModel):
metadata: typing.Dict = Field(default_factory=dict)


class FieldMaskMessage(BaseModel):
class OtherMessage(BaseModel):
class Config:
arbitrary_types_allowed = True

metadata: typing.Dict = Field(default_factory=dict)
double_value: DoubleValue = Field(default_factory=DoubleValue)
field_mask: typing.Optional[FieldMask] = Field(default_factory=FieldMask)


Expand Down
Loading

0 comments on commit 6f626ea

Please sign in to comment.