datamodel-code-generator
datamodel-code-generator copied to clipboard
String enum with "YES/NO/NOT_APPLICABLE" being converted to "TRUE/FALSE/'NOT_APPLICABLE'"
Describe the bug
A model that defines a string enum with 3 options YES/NO/NOT_APPLICABLE is turned into a bool enum with one string option.
To Reproduce
Example schema:
openapi: "3.0.0"
info:
title: "test"
description: "test"
version: "0.1"
components:
schemas:
HaveHaveNots:
type: "object"
properties:
hasIt:
type: string
enum:
- YES
- NO
- NOT_APPLICABLE
example: YES
This results in the following class:
from __future__ import annotations
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class HasIt(Enum):
True_ = True
False_ = False
NOT_APPLICABLE = 'NOT_APPLICABLE'
class HaveHaveNots(BaseModel):
hasIt: Optional[HasIt] = Field(None, example=True)
Used commandline:
$ datamodel-codegen --input test.yaml --output test.py
Expected behavior
I would have expected the class to look like this (just strings):
class HasIt(Enum):
YES = "YES"
NO = "NO"
NOT_APPLICABLE = 'NOT_APPLICABLE'
class HaveHaveNots(BaseModel):
hasIt: Optional[HasIt] = Field(None, example="YES")
Version:
- OS: Mac Sonoma
- Python version: 3.11
- datamodel-code-generator version: 0.25.1
Additional context Add any other context about the problem here.
@iwt-kschoenrock I'm sorry for my late reply. I think this is not a bug. please read the comment and the link https://github.com/koxudaxi/datamodel-code-generator/issues/1653#issuecomment-1792627944