Skip to content

Extra underscore for an enum variant named replace #2970

@xu-cheng

Description

@xu-cheng

Describe the bug
There is an extra underscore if I have an enum including a variant named replace.

To Reproduce

Example schema:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Action",
    "enum": [
        "append",
        "prepend",
        "replace"
    ]
}

Used commandline:

$ datamodel-codegen \
    --input-file-type jsonschema \
    --output-model-type pydantic_v2.BaseModel \
    --capitalise-enum-members \
    --input test.json \
    --output test.py

Expected behavior

What I want to get:

class Action(Enum):
    APPEND = 'append'
    PREPEND = 'prepend'
    REPLACE = 'replace'

What I actually got, noted that extra _ in REPLACE_.

class Action(Enum):
    APPEND = 'append'
    PREPEND = 'prepend'
    REPLACE_ = 'replace'

Version:

  • OS: Linux
  • Python version: 3.12
  • datamodel-code-generator version: 0.53.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions