Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String enum with "YES/NO/NOT_APPLICABLE" being converted to "TRUE/FALSE/'NOT_APPLICABLE'" #1766

Open
iwt-kschoenrock opened this issue Dec 8, 2023 · 1 comment
Labels

Comments

@iwt-kschoenrock
Copy link

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.

@koxudaxi
Copy link
Owner

@iwt-kschoenrock
I'm sorry for my late reply.
I think this is not a bug.
please read the comment and the link
#1653 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants