Comments (6)
I implemented this here:
https://github.com/FlorianLudwig/pdk8s/blob/master/pdk8s/gen_k8s.py#L59
By changing the name to camel_case and keeping the old name as alias.
from datamodel-code-generator.
Maybe I am off base here but I feel like this is doing the opposite of what I am exepcting.
class Model(BaseModel):
notification_type: Optional[str] = Field(
None,
alias="notificationType",
)
self.assertEqual("{\"notification_type\": \"test\"}", Model(notificationType='test').json())
where I was expecting to have
self.assertEqual("{\"notificationType\": \"test\"}", Model(notification_type='test').json())
Since javascript and json is usually camel case, and python is usually snake case.
EDIT: reading through pydantic/pydantic#565
it looks like pydantic is taking the approach that the constructor is taking in the camel case version. It is still odd that the json
does not return the public verions.
from datamodel-code-generator.
@FlorianLudwig
Thank you for reviewing the PR.
I have released the version as 0.5.21
🎉
from datamodel-code-generator.
It looks like adding
class Config:
allow_population_by_field_name = True
and the whenever generating the json doing .dict(by_alias=True)
works more like I was hoping. Is there a way to add pydantic
config options to the generated classes?
from datamodel-code-generator.
@camerondavison
The code-generator can't add a custom config.
But, I prefer to generate custom configs.
I will implement it.
Thank you.
from datamodel-code-generator.
@camerondavison
I added an option for allow_population_by_field_name
It's included in version 0.5.33
from datamodel-code-generator.
Related Issues (20)
- datamodel-codegen produces class with missing body parts
- Improve `mypy` hinting on `RootModel` with `oneOf` HOT 4
- How to change endpoints naming template?
- Support pydantic.dataclasses as output format
- Nullability info excluded from templates for optional, no-default OpenAPI fields
- [yaml] The generator does not generate Python code from models in external files referenced by $ref. HOT 1
- Generation of Shopify GraphQL schema fails
- oneOf with subschema array items not incorporated/generated as Any for pydantic.v2 HOT 4
- [graphql] Add support for --use-subclass-enum
- Base class for main object, not for properties HOT 1
- msgspec: Mandatory attributes follow optional ones
- msgspec: Optional fields are missing a default when using `--snake-case-field` HOT 6
- Generated models using RootModel to represent Annotated Unions are out of order HOT 2
- JSON Schema: oneOf with const
- Default value of enum field isn't an enum member HOT 2
- Discriminated union with a List: annotation is on the list, not the union
- CLI options `use-standard-collections` and `use-union-operator` are not being applied for input file type `graphql` HOT 2
- When using snake-case-fields and msgspec, field ordering does not always work correctly
- [pydantic_v2.BaseModel] Field specified as `date-time` is generated as `AwareDatetime` HOT 1
- Forward-compatible usage of Pydantic v1
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 datamodel-code-generator.