Skip to content

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

@davner

Description

@davner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions