Comments (4)
Thanks for the feedback, I will fix this in version 0.2.0.1.
from protobuf_to_pydantic.
@so1n There's another bug created that's caused by the fix.
For fields such as:
repeated string a = 1;
It now generates this:
a: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)
which is not allowed in Pydantic. You cannot have default_factory and a default.
from protobuf_to_pydantic.
@so1n There's another bug created that's caused by the fix.
For fields such as:
repeated string a = 1;
It now generates this:
a: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)
which is not allowed in Pydantic. You cannot have default_factory and a default.
Please provide the Protobuf file or Message, I can't reproduce the problem at the moment
from protobuf_to_pydantic.
@so1n Here it is:
syntax = "proto3";
message A {
optional string a = 2;
repeated string b = 3;
}
Output:
# This is an automatically generated file, please do not change
# gen by protobuf_to_pydantic[v0.2.0.1](https://github.com/so1n/protobuf_to_pydantic)
# Protobuf Version: 4.24.3
# Pydantic Version: 1.10.12
from google.protobuf.message import Message # type: ignore
from pydantic import BaseModel
from pydantic import Field
import typing
class A(BaseModel):
a: typing.Optional[str] = Field(default="")
b: typing.Optional[typing.List[str]] = Field(default_factory=list, default=None)
It doesn't happen if you only have a single repeated field b
.
from protobuf_to_pydantic.
Related Issues (20)
- Support of protobuf services HOT 1
- default_factory and default generated together
- Integrate plugin with buf cli HOT 2
- ImportError: cannot import name 'PydanticGeneralMetadata' from 'pydantic._internal._fields' with latest pydantic HOT 1
- Oneof for non primitive types HOT 5
- py3.11 support
- [DELETED]
- Typo in readme.
- Missing typing import for optional field HOT 1
- feat: Handle google protobuf FieldMask HOT 3
- Syntax Errors generating model from mapbox vector tile spec HOT 1
- Remote buf plugin doesn't exist HOT 1
- dependencies clash with protobuf-5.26.1 HOT 2
- Document how to convert objects between proto and pydantic and reverse HOT 1
- Issue with google.protobuf.DoubleValue HOT 1
- make the model field to snake_case HOT 1
- Replace deprecated `FieldValidationInfo` with `ValidationInfo` in customer validator HOT 1
- Plugin Mode support text annotation rule
- Plugin Mode support mutli config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf_to_pydantic.