question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snake Case Field Option

See original GitHub issue

Is your feature request related to a problem? Please describe. OpenAPI or JsonSchema may describe key of objects as camelCase. But, attributes of python should be snake_case. The generator should provide a feature that converts filed names CamelCase to sanke_case.

Describe the solution you’d like I would the feature give the generator a command-line option

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
camerondavisoncommented, Sep 3, 2020

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 https://github.com/samuelcolvin/pydantic/issues/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.

1reaction
FlorianLudwigcommented, Jul 28, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snake case - Wikipedia
Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced with an underscore (_) character, and...
Read more >
What is snake case? - TheServerSide.com
Snake case, or snake_case, is a naming convention that allows a developer to create white space between words in code with an underscore....
Read more >
Camel Case vs. Snake Case vs. Pascal Case - Khalil Stemmler
Snake case (also referred to as underscore case) is when all the letters of the word are lower case but delimited by an...
Read more >
Snake case property names - Json.NET
Snake case property names. This sample uses a SnakeCaseNamingStrategy specified using a contract resolver to snake case serialized property names.
Read more >
Ability to create a snake_case field with the graphql_object ...
a way to create snake_case fields should be provided. ... All this is about is a option to disable the automatic camel case...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found