glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.77k stars 1.04k forks source link

Key names are formatted in the target language, and not the source language #2421

Open raldebsi opened 9 months ago

raldebsi commented 9 months ago

This is more of a request than an issue, but almost in all of my use case scenarios (at least in python) I've noticed that the classes being made are using python naming scheme (snake case) rather than the import JSON's scheme, which makes me unable to use the models generated without lots of modifications. Example:

{
    "userName": "User1"
}

This would generate the following class:

class UserName(Enum):
    USER1 = "User1"

class Root:
    user_name: UserName

    def __init__(...)

This would not allow me to use the above model to reference the request response's JSON object, as user_name is not the right field. It is also worth noting that most code I've seen that deals with data models also rely on PyDantic / TypedDict, therefore inherting from TypedDict would also be optimal.

Therefore, is it possible to set a flag that would enable TypedDict + Original Naming Convention instead of using whatever is native to that language?

renanzulian commented 3 weeks ago

I'm dealing with the same problem. In my JSON samples, some fields are camelCase, and others are snake_case. It's impossible to have only the types with the original names.