Describe the bug
Hi! It seems that when using an array of enum (string type), the code is not being generated properly. Instead of making a List of enums, it always allows any string because it makes a List[str].
To Reproduce
Example schema:
openapi: 3.0.0
info:
title: datamodel-code-generator bug example
components:
schemas:
Type1:
type: array
items:
type: string
enum:
- enumOne
- enumTwo
Type2:
type: string
enum:
- enumFour
- enumFive
Code generated:
from __future__ import annotations
from enum import Enum
from typing import List
from pydantic import BaseModel
class Type1(BaseModel):
__root__: List[str]
class Type2(Enum):
enumFour = 'enumFour'
enumFive = 'enumFive'
Used commandline:
$ datamodel-codegen --input input.yaml --output tmp.py
Expected behavior
Expected behaviour would be that inside of Type1, there should be List[Enum] where Enum is a class that has the correct enum types allowed.
Version:
Or is there an alternative way of achieving the above that I am missing?
The goal is to essentially have a class that accepts a List of enum.
Thanks!
@jaydhulia
Thank you for creating this issue.
I have fixed it and released a new version as 0.5.5
Thank you for quickly fixing that, going to close this issue!
Most helpful comment
Thank you for quickly fixing that, going to close this issue!