datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

`snake-case-field` incorrectly applies to union names for graphql schema.

Open davner opened this issue 6 months ago • 0 comments

Describe the bug Thank you for this great tool. When --snake-case-field is enabled, datamodel-codegen incorrectly converts union variant type names to snake_case.

To Reproduce

Example schema:


union ExampleUnion = FooCamel | BarCamel

type FooCamel {
  a: String!
}

type BarCamel {
  b: String!
}

Used commandline:

$ datamodel-codegen --input test.graphql --output model.py --input-file-type graphql --output-model-type pydantic_v2.BaseModel --snake-case-field

Current behavior

ExampleUnion: TypeAlias = Union[
    'bar_camel',
    'foo_camel',
]

Expected behavior

ExampleUnion: TypeAlias = Union[
    'BarCamel',
    'FooCamel',
]

Version:

  • OS: macOS 14.6.1
  • Python version: 3.10.17
  • datamodel-code-generator version: 0.30.1

davner avatar May 23 '25 21:05 davner