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:
Additional context
Add any other context about the problem here.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too