Giter Site home page Giter Site logo

Comments (6)

FlorianLudwig avatar FlorianLudwig commented on August 25, 2024 1

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.

camerondavison avatar camerondavison commented on August 25, 2024 1

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.

koxudaxi avatar koxudaxi commented on August 25, 2024

@FlorianLudwig
Thank you for reviewing the PR.

I have released the version as 0.5.21 🎉

from datamodel-code-generator.

camerondavison avatar camerondavison commented on August 25, 2024

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.

koxudaxi avatar koxudaxi commented on August 25, 2024

@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.

koxudaxi avatar koxudaxi commented on August 25, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.