We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
--enum-field-as-literal=one converts integer to string
**Describe the bug**

When using the `--enum-field-as-literal=one` arg, the generated literal is always a string. Even if you explicitly set `type: integer`.

**To Reproduce**

Example schema:
```yaml
Foo:
  type: object
  properties:
    bar:
      type: integer
      enum: [1]
```

Creates:

```py
class Foo(BaseModel):
    bar: Optional[Literal['1']] = None
```

Used commandline:
```
$ datamodel-codegen --input openapi.yaml --output models.py --enum-field-as-literal=one
```

**Expected behavior**

If an enum type is `integer` then the resulting literal is also an integer.

**Version:**
 - OS: macOS `11.4`
 - Python version: `3.9.2`
 - datamodel-code-generator version: `0.11.6`

**Additional context**

This appears to be a problem with this type:

https://github.com/koxudaxi/datamodel-code-generator/blob/master/datamodel_code_generator/types.py#L74

Changing that type to `List[int]` results in an int literal. Not that we should change the type to `List[int]` specifically, but rather that the type likely needs to be more flexible.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `datamodel_code_generator/types.py`
Content:
```
1 from abc import ABC, abstractmethod
2 from enum import Enum, auto
3 from itertools import chain
4 from typing import (
5     TYPE_CHECKING,
6     Any,
7     ClassVar,
8     Dict,
9     FrozenSet,
10     Iterable,
11     Iterator,
12     List,
13     Optional,
14     Sequence,
15     Set,
16     Tuple,
17     Type,
18     TypeVar,
19 )
20 
21 from pydantic import create_model
22 
23 from datamodel_code_generator import Protocol, runtime_checkable
24 from datamodel_code_generator.format import PythonVersion
25 from datamodel_code_generator.imports import (
26     IMPORT_ABC_MAPPING,
27     IMPORT_ABC_SEQUENCE,
28     IMPORT_DICT,
29     IMPORT_LIST,
30     IMPORT_LITERAL,
31     IMPORT_LITERAL_BACKPORT,
32     IMPORT_MAPPING,
33     IMPORT_OPTIONAL,
34     IMPORT_SEQUENCE,
35     IMPORT_UNION,
36     Import,
37 )
38 from datamodel_code_generator.reference import Reference, _BaseModel
39 
40 T = TypeVar('T')
41 
42 
43 class StrictTypes(Enum):
44     str = 'str'
45     bytes = 'bytes'
46     int = 'int'
47     float = 'float'
48     bool = 'bool'
49 
50 
51 def chain_as_tuple(*iterables: Iterable[T]) -> Tuple[T, ...]:
52     return tuple(chain(*iterables))
53 
54 
55 @runtime_checkable
56 class Modular(Protocol):
57     @property
58     def module_name(self) -> str:
59         raise NotImplementedError
60 
61 
62 class DataType(_BaseModel):
63     type: Optional[str]
64     reference: Optional[Reference]
65     data_types: List['DataType'] = []
66     is_func: bool = False
67     kwargs: Optional[Dict[str, Any]]
68     import_: Optional[Import] = None
69     python_version: PythonVersion = PythonVersion.PY_37
70     is_optional: bool = False
71     is_dict: bool = False
72     is_list: bool = False
73     is_custom_type: bool = False
74     literals: List[str] = []
75     use_standard_collections: bool = False
76     use_generic_container: bool = False
77     alias: Optional[str] = None
78     parent: Optional[Any] = None
79     children: List[Any] = []
80     strict: bool = False
81 
82     _exclude_fields: ClassVar[Set[str]] = {'parent', 'children'}
83     _pass_fields: ClassVar[Set[str]] = {'parent', 'children', 'data_types', 'reference'}
84 
85     @classmethod
86     def from_import(
87         cls: Type['DataTypeT'],
88         import_: Import,
89         *,
90         is_optional: bool = False,
91         is_dict: bool = False,
92         is_list: bool = False,
93         is_custom_type: bool = False,
94         strict: bool = False,
95         kwargs: Optional[Dict[str, Any]] = None,
96     ) -> 'DataTypeT':
97         return cls(
98             type=import_.import_,
99             import_=import_,
100             is_optional=is_optional,
101             is_dict=is_dict,
102             is_list=is_list,
103             is_func=True if kwargs else False,
104             is_custom_type=is_custom_type,
105             strict=strict,
106             kwargs=kwargs,
107         )
108 
109     @property
110     def unresolved_types(self) -> FrozenSet[str]:
111         return frozenset(
112             {
113                 t.reference.path
114                 for data_types in self.data_types
115                 for t in data_types.all_data_types
116                 if t.reference
117             }
118             | ({self.reference.path} if self.reference else set())
119         )
120 
121     def replace_reference(self, reference: Reference) -> None:
122         if not self.reference:  # pragma: no cover
123             raise Exception(
124                 f'`{self.__class__.__name__}.replace_reference()` can\'t be called'
125                 f' when `reference` field is empty.'
126             )
127 
128         self.reference.children.remove(self)
129         self.reference = reference
130         reference.children.append(self)
131 
132     @property
133     def module_name(self) -> Optional[str]:
134         if self.reference and isinstance(self.reference.source, Modular):
135             return self.reference.source.module_name
136         return None  # pragma: no cover
137 
138     @property
139     def full_name(self) -> str:
140         module_name = self.module_name
141         if module_name:
142             return f'{module_name}.{self.reference.short_name}'  # type: ignore
143         return self.reference.short_name  # type: ignore
144 
145     @property
146     def all_data_types(self) -> Iterator['DataType']:
147         for data_type in self.data_types:
148             yield from data_type.all_data_types
149         yield self
150 
151     @property
152     def all_imports(self) -> Iterator[Import]:
153         for data_type in self.data_types:
154             yield from data_type.all_imports
155         yield from self.imports
156 
157     @property
158     def imports(self) -> Iterator[Import]:
159         if self.import_:
160             yield self.import_
161         imports: Tuple[Tuple[bool, Import], ...] = (
162             (self.is_optional, IMPORT_OPTIONAL),
163             (len(self.data_types) > 1, IMPORT_UNION),
164         )
165         if any(self.literals):
166             import_literal = (
167                 IMPORT_LITERAL
168                 if self.python_version.has_literal_type
169                 else IMPORT_LITERAL_BACKPORT
170             )
171             imports = (
172                 *imports,
173                 (any(self.literals), import_literal),
174             )
175 
176         if self.use_generic_container:
177             if self.use_standard_collections:
178                 imports = (
179                     *imports,
180                     (self.is_list, IMPORT_ABC_SEQUENCE),
181                     (self.is_dict, IMPORT_ABC_MAPPING),
182                 )
183             else:
184                 imports = (
185                     *imports,
186                     (self.is_list, IMPORT_SEQUENCE),
187                     (self.is_dict, IMPORT_MAPPING),
188                 )
189         elif not self.use_standard_collections:
190             imports = (
191                 *imports,
192                 (self.is_list, IMPORT_LIST),
193                 (self.is_dict, IMPORT_DICT),
194             )
195         for field, import_ in imports:
196             if field and import_ != self.import_:
197                 yield import_
198 
199     def __init__(self, **values: Any) -> None:
200         super().__init__(**values)  # type: ignore
201 
202         for type_ in self.data_types:
203             if type_.type == 'Any' and type_.is_optional:
204                 if any(
205                     t for t in self.data_types if t.type != 'Any'
206                 ):  # pragma: no cover
207                     self.is_optional = True
208                     self.data_types = [
209                         t
210                         for t in self.data_types
211                         if not (t.type == 'Any' and t.is_optional)
212                     ]
213                 break
214 
215         for data_type in self.data_types:
216             if data_type.reference:
217                 data_type.parent = self
218 
219         if self.reference:
220             self.reference.children.append(self)
221 
222     @property
223     def type_hint(self) -> str:
224         type_: Optional[str] = self.alias or self.type
225         if not type_:
226             if len(self.data_types) > 1:
227                 type_ = f"Union[{', '.join(data_type.type_hint for data_type in self.data_types)}]"
228             elif len(self.data_types) == 1:
229                 type_ = self.data_types[0].type_hint
230             elif self.literals:
231                 type_ = (
232                     f"Literal[{', '.join(repr(literal) for literal in self.literals)}]"
233                 )
234             else:
235                 if self.reference:
236                     type_ = self.reference.short_name
237                 else:
238                     # TODO support strict Any
239                     # type_ = 'Any'
240                     type_ = ''
241         if self.reference and self.python_version == PythonVersion.PY_36:
242             type_ = f"'{type_}'"
243         if self.is_list:
244             if self.use_generic_container:
245                 list_ = 'Sequence'
246             elif self.use_standard_collections:
247                 list_ = 'list'
248             else:
249                 list_ = 'List'
250             type_ = f'{list_}[{type_}]' if type_ else list_
251         elif self.is_dict:
252             if self.use_generic_container:
253                 dict_ = 'Mapping'
254             elif self.use_standard_collections:
255                 dict_ = 'dict'
256             else:
257                 dict_ = 'Dict'
258             type_ = f'{dict_}[str, {type_}]' if type_ else dict_
259         if self.is_optional and type_ != 'Any':
260             type_ = f'Optional[{type_}]'
261         elif self.is_func:
262             if self.kwargs:
263                 kwargs: str = ', '.join(f'{k}={v}' for k, v in self.kwargs.items())
264                 return f'{type_}({kwargs})'
265             return f'{type_}()'
266         return type_
267 
268 
269 DataType.update_forward_refs()
270 
271 DataTypeT = TypeVar('DataTypeT', bound=DataType)
272 
273 
274 class Types(Enum):
275     integer = auto()
276     int32 = auto()
277     int64 = auto()
278     number = auto()
279     float = auto()
280     double = auto()
281     decimal = auto()
282     time = auto()
283     string = auto()
284     byte = auto()
285     binary = auto()
286     date = auto()
287     date_time = auto()
288     password = auto()
289     email = auto()
290     uuid = auto()
291     uuid1 = auto()
292     uuid2 = auto()
293     uuid3 = auto()
294     uuid4 = auto()
295     uuid5 = auto()
296     uri = auto()
297     hostname = auto()
298     ipv4 = auto()
299     ipv6 = auto()
300     boolean = auto()
301     object = auto()
302     null = auto()
303     array = auto()
304     any = auto()
305 
306 
307 class DataTypeManager(ABC):
308     def __init__(
309         self,
310         python_version: PythonVersion = PythonVersion.PY_37,
311         use_standard_collections: bool = False,
312         use_generic_container_types: bool = False,
313         strict_types: Optional[Sequence[StrictTypes]] = None,
314     ) -> None:
315         self.python_version = python_version
316         self.use_standard_collections: bool = use_standard_collections
317         self.use_generic_container_types: bool = use_generic_container_types
318         self.strict_types: Sequence[StrictTypes] = strict_types or ()
319 
320         if (
321             use_generic_container_types and python_version == PythonVersion.PY_36
322         ):  # pragma: no cover
323             raise Exception(
324                 "use_generic_container_types can not be used with target_python_version 3.6.\n"
325                 " The version will be not supported in a future version"
326             )
327 
328         if TYPE_CHECKING:
329             self.data_type: Type[DataType]
330         else:
331             self.data_type: Type[DataType] = create_model(
332                 'ContextDataType',
333                 python_version=python_version,
334                 use_standard_collections=use_standard_collections,
335                 use_generic_container=use_generic_container_types,
336                 __base__=DataType,
337             )
338 
339     @abstractmethod
340     def get_data_type(self, types: Types, **kwargs: Any) -> DataType:
341         raise NotImplementedError
342 
343     def get_data_type_from_full_path(
344         self, full_path: str, is_custom_type: bool
345     ) -> DataType:
346         return self.data_type.from_import(
347             Import.from_full_path(full_path), is_custom_type=is_custom_type
348         )
349
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py
--- a/datamodel_code_generator/types.py
+++ b/datamodel_code_generator/types.py
@@ -16,6 +16,7 @@
     Tuple,
     Type,
     TypeVar,
+    Union,
 )
 
 from pydantic import create_model
@@ -71,7 +72,7 @@
     is_dict: bool = False
     is_list: bool = False
     is_custom_type: bool = False
-    literals: List[str] = []
+    literals: List[Union[int, str]] = []
     use_standard_collections: bool = False
     use_generic_container: bool = False
     alias: Optional[str] = None

{"golden_diff": "diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py\n--- a/datamodel_code_generator/types.py\n+++ b/datamodel_code_generator/types.py\n@@ -16,6 +16,7 @@\n     Tuple,\n     Type,\n     TypeVar,\n+    Union,\n )\n \n from pydantic import create_model\n@@ -71,7 +72,7 @@\n     is_dict: bool = False\n     is_list: bool = False\n     is_custom_type: bool = False\n-    literals: List[str] = []\n+    literals: List[Union[int, str]] = []\n     use_standard_collections: bool = False\n     use_generic_container: bool = False\n     alias: Optional[str] = None\n", "issue": "--enum-field-as-literal=one converts integer to string\n**Describe the bug**\r\n\r\nWhen using the `--enum-field-as-literal=one` arg, the generated literal is always a string. Even if you explicitly set `type: integer`.\r\n\r\n**To Reproduce**\r\n\r\nExample schema:\r\n```yaml\r\nFoo:\r\n  type: object\r\n  properties:\r\n    bar:\r\n      type: integer\r\n      enum: [1]\r\n```\r\n\r\nCreates:\r\n\r\n```py\r\nclass Foo(BaseModel):\r\n    bar: Optional[Literal['1']] = None\r\n```\r\n\r\nUsed commandline:\r\n```\r\n$ datamodel-codegen --input openapi.yaml --output models.py --enum-field-as-literal=one\r\n```\r\n\r\n**Expected behavior**\r\n\r\nIf an enum type is `integer` then the resulting literal is also an integer.\r\n\r\n**Version:**\r\n - OS: macOS `11.4`\r\n - Python version: `3.9.2`\r\n - datamodel-code-generator version: `0.11.6`\r\n\r\n**Additional context**\r\n\r\nThis appears to be a problem with this type:\r\n\r\nhttps://github.com/koxudaxi/datamodel-code-generator/blob/master/datamodel_code_generator/types.py#L74\r\n\r\nChanging that type to `List[int]` results in an int literal. Not that we should change the type to `List[int]` specifically, but rather that the type likely needs to be more flexible.\r\n\n", "before_files": [{"content": "from abc import ABC, abstractmethod\nfrom enum import Enum, auto\nfrom itertools import chain\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    ClassVar,\n    Dict,\n    FrozenSet,\n    Iterable,\n    Iterator,\n    List,\n    Optional,\n    Sequence,\n    Set,\n    Tuple,\n    Type,\n    TypeVar,\n)\n\nfrom pydantic import create_model\n\nfrom datamodel_code_generator import Protocol, runtime_checkable\nfrom datamodel_code_generator.format import PythonVersion\nfrom datamodel_code_generator.imports import (\n    IMPORT_ABC_MAPPING,\n    IMPORT_ABC_SEQUENCE,\n    IMPORT_DICT,\n    IMPORT_LIST,\n    IMPORT_LITERAL,\n    IMPORT_LITERAL_BACKPORT,\n    IMPORT_MAPPING,\n    IMPORT_OPTIONAL,\n    IMPORT_SEQUENCE,\n    IMPORT_UNION,\n    Import,\n)\nfrom datamodel_code_generator.reference import Reference, _BaseModel\n\nT = TypeVar('T')\n\n\nclass StrictTypes(Enum):\n    str = 'str'\n    bytes = 'bytes'\n    int = 'int'\n    float = 'float'\n    bool = 'bool'\n\n\ndef chain_as_tuple(*iterables: Iterable[T]) -> Tuple[T, ...]:\n    return tuple(chain(*iterables))\n\n\n@runtime_checkable\nclass Modular(Protocol):\n    @property\n    def module_name(self) -> str:\n        raise NotImplementedError\n\n\nclass DataType(_BaseModel):\n    type: Optional[str]\n    reference: Optional[Reference]\n    data_types: List['DataType'] = []\n    is_func: bool = False\n    kwargs: Optional[Dict[str, Any]]\n    import_: Optional[Import] = None\n    python_version: PythonVersion = PythonVersion.PY_37\n    is_optional: bool = False\n    is_dict: bool = False\n    is_list: bool = False\n    is_custom_type: bool = False\n    literals: List[str] = []\n    use_standard_collections: bool = False\n    use_generic_container: bool = False\n    alias: Optional[str] = None\n    parent: Optional[Any] = None\n    children: List[Any] = []\n    strict: bool = False\n\n    _exclude_fields: ClassVar[Set[str]] = {'parent', 'children'}\n    _pass_fields: ClassVar[Set[str]] = {'parent', 'children', 'data_types', 'reference'}\n\n    @classmethod\n    def from_import(\n        cls: Type['DataTypeT'],\n        import_: Import,\n        *,\n        is_optional: bool = False,\n        is_dict: bool = False,\n        is_list: bool = False,\n        is_custom_type: bool = False,\n        strict: bool = False,\n        kwargs: Optional[Dict[str, Any]] = None,\n    ) -> 'DataTypeT':\n        return cls(\n            type=import_.import_,\n            import_=import_,\n            is_optional=is_optional,\n            is_dict=is_dict,\n            is_list=is_list,\n            is_func=True if kwargs else False,\n            is_custom_type=is_custom_type,\n            strict=strict,\n            kwargs=kwargs,\n        )\n\n    @property\n    def unresolved_types(self) -> FrozenSet[str]:\n        return frozenset(\n            {\n                t.reference.path\n                for data_types in self.data_types\n                for t in data_types.all_data_types\n                if t.reference\n            }\n            | ({self.reference.path} if self.reference else set())\n        )\n\n    def replace_reference(self, reference: Reference) -> None:\n        if not self.reference:  # pragma: no cover\n            raise Exception(\n                f'`{self.__class__.__name__}.replace_reference()` can\\'t be called'\n                f' when `reference` field is empty.'\n            )\n\n        self.reference.children.remove(self)\n        self.reference = reference\n        reference.children.append(self)\n\n    @property\n    def module_name(self) -> Optional[str]:\n        if self.reference and isinstance(self.reference.source, Modular):\n            return self.reference.source.module_name\n        return None  # pragma: no cover\n\n    @property\n    def full_name(self) -> str:\n        module_name = self.module_name\n        if module_name:\n            return f'{module_name}.{self.reference.short_name}'  # type: ignore\n        return self.reference.short_name  # type: ignore\n\n    @property\n    def all_data_types(self) -> Iterator['DataType']:\n        for data_type in self.data_types:\n            yield from data_type.all_data_types\n        yield self\n\n    @property\n    def all_imports(self) -> Iterator[Import]:\n        for data_type in self.data_types:\n            yield from data_type.all_imports\n        yield from self.imports\n\n    @property\n    def imports(self) -> Iterator[Import]:\n        if self.import_:\n            yield self.import_\n        imports: Tuple[Tuple[bool, Import], ...] = (\n            (self.is_optional, IMPORT_OPTIONAL),\n            (len(self.data_types) > 1, IMPORT_UNION),\n        )\n        if any(self.literals):\n            import_literal = (\n                IMPORT_LITERAL\n                if self.python_version.has_literal_type\n                else IMPORT_LITERAL_BACKPORT\n            )\n            imports = (\n                *imports,\n                (any(self.literals), import_literal),\n            )\n\n        if self.use_generic_container:\n            if self.use_standard_collections:\n                imports = (\n                    *imports,\n                    (self.is_list, IMPORT_ABC_SEQUENCE),\n                    (self.is_dict, IMPORT_ABC_MAPPING),\n                )\n            else:\n                imports = (\n                    *imports,\n                    (self.is_list, IMPORT_SEQUENCE),\n                    (self.is_dict, IMPORT_MAPPING),\n                )\n        elif not self.use_standard_collections:\n            imports = (\n                *imports,\n                (self.is_list, IMPORT_LIST),\n                (self.is_dict, IMPORT_DICT),\n            )\n        for field, import_ in imports:\n            if field and import_ != self.import_:\n                yield import_\n\n    def __init__(self, **values: Any) -> None:\n        super().__init__(**values)  # type: ignore\n\n        for type_ in self.data_types:\n            if type_.type == 'Any' and type_.is_optional:\n                if any(\n                    t for t in self.data_types if t.type != 'Any'\n                ):  # pragma: no cover\n                    self.is_optional = True\n                    self.data_types = [\n                        t\n                        for t in self.data_types\n                        if not (t.type == 'Any' and t.is_optional)\n                    ]\n                break\n\n        for data_type in self.data_types:\n            if data_type.reference:\n                data_type.parent = self\n\n        if self.reference:\n            self.reference.children.append(self)\n\n    @property\n    def type_hint(self) -> str:\n        type_: Optional[str] = self.alias or self.type\n        if not type_:\n            if len(self.data_types) > 1:\n                type_ = f\"Union[{', '.join(data_type.type_hint for data_type in self.data_types)}]\"\n            elif len(self.data_types) == 1:\n                type_ = self.data_types[0].type_hint\n            elif self.literals:\n                type_ = (\n                    f\"Literal[{', '.join(repr(literal) for literal in self.literals)}]\"\n                )\n            else:\n                if self.reference:\n                    type_ = self.reference.short_name\n                else:\n                    # TODO support strict Any\n                    # type_ = 'Any'\n                    type_ = ''\n        if self.reference and self.python_version == PythonVersion.PY_36:\n            type_ = f\"'{type_}'\"\n        if self.is_list:\n            if self.use_generic_container:\n                list_ = 'Sequence'\n            elif self.use_standard_collections:\n                list_ = 'list'\n            else:\n                list_ = 'List'\n            type_ = f'{list_}[{type_}]' if type_ else list_\n        elif self.is_dict:\n            if self.use_generic_container:\n                dict_ = 'Mapping'\n            elif self.use_standard_collections:\n                dict_ = 'dict'\n            else:\n                dict_ = 'Dict'\n            type_ = f'{dict_}[str, {type_}]' if type_ else dict_\n        if self.is_optional and type_ != 'Any':\n            type_ = f'Optional[{type_}]'\n        elif self.is_func:\n            if self.kwargs:\n                kwargs: str = ', '.join(f'{k}={v}' for k, v in self.kwargs.items())\n                return f'{type_}({kwargs})'\n            return f'{type_}()'\n        return type_\n\n\nDataType.update_forward_refs()\n\nDataTypeT = TypeVar('DataTypeT', bound=DataType)\n\n\nclass Types(Enum):\n    integer = auto()\n    int32 = auto()\n    int64 = auto()\n    number = auto()\n    float = auto()\n    double = auto()\n    decimal = auto()\n    time = auto()\n    string = auto()\n    byte = auto()\n    binary = auto()\n    date = auto()\n    date_time = auto()\n    password = auto()\n    email = auto()\n    uuid = auto()\n    uuid1 = auto()\n    uuid2 = auto()\n    uuid3 = auto()\n    uuid4 = auto()\n    uuid5 = auto()\n    uri = auto()\n    hostname = auto()\n    ipv4 = auto()\n    ipv6 = auto()\n    boolean = auto()\n    object = auto()\n    null = auto()\n    array = auto()\n    any = auto()\n\n\nclass DataTypeManager(ABC):\n    def __init__(\n        self,\n        python_version: PythonVersion = PythonVersion.PY_37,\n        use_standard_collections: bool = False,\n        use_generic_container_types: bool = False,\n        strict_types: Optional[Sequence[StrictTypes]] = None,\n    ) -> None:\n        self.python_version = python_version\n        self.use_standard_collections: bool = use_standard_collections\n        self.use_generic_container_types: bool = use_generic_container_types\n        self.strict_types: Sequence[StrictTypes] = strict_types or ()\n\n        if (\n            use_generic_container_types and python_version == PythonVersion.PY_36\n        ):  # pragma: no cover\n            raise Exception(\n                \"use_generic_container_types can not be used with target_python_version 3.6.\\n\"\n                \" The version will be not supported in a future version\"\n            )\n\n        if TYPE_CHECKING:\n            self.data_type: Type[DataType]\n        else:\n            self.data_type: Type[DataType] = create_model(\n                'ContextDataType',\n                python_version=python_version,\n                use_standard_collections=use_standard_collections,\n                use_generic_container=use_generic_container_types,\n                __base__=DataType,\n            )\n\n    @abstractmethod\n    def get_data_type(self, types: Types, **kwargs: Any) -> DataType:\n        raise NotImplementedError\n\n    def get_data_type_from_full_path(\n        self, full_path: str, is_custom_type: bool\n    ) -> DataType:\n        return self.data_type.from_import(\n            Import.from_full_path(full_path), is_custom_type=is_custom_type\n        )\n", "path": "datamodel_code_generator/types.py"}], "after_files": [{"content": "from abc import ABC, abstractmethod\nfrom enum import Enum, auto\nfrom itertools import chain\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    ClassVar,\n    Dict,\n    FrozenSet,\n    Iterable,\n    Iterator,\n    List,\n    Optional,\n    Sequence,\n    Set,\n    Tuple,\n    Type,\n    TypeVar,\n    Union,\n)\n\nfrom pydantic import create_model\n\nfrom datamodel_code_generator import Protocol, runtime_checkable\nfrom datamodel_code_generator.format import PythonVersion\nfrom datamodel_code_generator.imports import (\n    IMPORT_ABC_MAPPING,\n    IMPORT_ABC_SEQUENCE,\n    IMPORT_DICT,\n    IMPORT_LIST,\n    IMPORT_LITERAL,\n    IMPORT_LITERAL_BACKPORT,\n    IMPORT_MAPPING,\n    IMPORT_OPTIONAL,\n    IMPORT_SEQUENCE,\n    IMPORT_UNION,\n    Import,\n)\nfrom datamodel_code_generator.reference import Reference, _BaseModel\n\nT = TypeVar('T')\n\n\nclass StrictTypes(Enum):\n    str = 'str'\n    bytes = 'bytes'\n    int = 'int'\n    float = 'float'\n    bool = 'bool'\n\n\ndef chain_as_tuple(*iterables: Iterable[T]) -> Tuple[T, ...]:\n    return tuple(chain(*iterables))\n\n\n@runtime_checkable\nclass Modular(Protocol):\n    @property\n    def module_name(self) -> str:\n        raise NotImplementedError\n\n\nclass DataType(_BaseModel):\n    type: Optional[str]\n    reference: Optional[Reference]\n    data_types: List['DataType'] = []\n    is_func: bool = False\n    kwargs: Optional[Dict[str, Any]]\n    import_: Optional[Import] = None\n    python_version: PythonVersion = PythonVersion.PY_37\n    is_optional: bool = False\n    is_dict: bool = False\n    is_list: bool = False\n    is_custom_type: bool = False\n    literals: List[Union[int, str]] = []\n    use_standard_collections: bool = False\n    use_generic_container: bool = False\n    alias: Optional[str] = None\n    parent: Optional[Any] = None\n    children: List[Any] = []\n    strict: bool = False\n\n    _exclude_fields: ClassVar[Set[str]] = {'parent', 'children'}\n    _pass_fields: ClassVar[Set[str]] = {'parent', 'children', 'data_types', 'reference'}\n\n    @classmethod\n    def from_import(\n        cls: Type['DataTypeT'],\n        import_: Import,\n        *,\n        is_optional: bool = False,\n        is_dict: bool = False,\n        is_list: bool = False,\n        is_custom_type: bool = False,\n        strict: bool = False,\n        kwargs: Optional[Dict[str, Any]] = None,\n    ) -> 'DataTypeT':\n        return cls(\n            type=import_.import_,\n            import_=import_,\n            is_optional=is_optional,\n            is_dict=is_dict,\n            is_list=is_list,\n            is_func=True if kwargs else False,\n            is_custom_type=is_custom_type,\n            strict=strict,\n            kwargs=kwargs,\n        )\n\n    @property\n    def unresolved_types(self) -> FrozenSet[str]:\n        return frozenset(\n            {\n                t.reference.path\n                for data_types in self.data_types\n                for t in data_types.all_data_types\n                if t.reference\n            }\n            | ({self.reference.path} if self.reference else set())\n        )\n\n    def replace_reference(self, reference: Reference) -> None:\n        if not self.reference:  # pragma: no cover\n            raise Exception(\n                f'`{self.__class__.__name__}.replace_reference()` can\\'t be called'\n                f' when `reference` field is empty.'\n            )\n\n        self.reference.children.remove(self)\n        self.reference = reference\n        reference.children.append(self)\n\n    @property\n    def module_name(self) -> Optional[str]:\n        if self.reference and isinstance(self.reference.source, Modular):\n            return self.reference.source.module_name\n        return None  # pragma: no cover\n\n    @property\n    def full_name(self) -> str:\n        module_name = self.module_name\n        if module_name:\n            return f'{module_name}.{self.reference.short_name}'  # type: ignore\n        return self.reference.short_name  # type: ignore\n\n    @property\n    def all_data_types(self) -> Iterator['DataType']:\n        for data_type in self.data_types:\n            yield from data_type.all_data_types\n        yield self\n\n    @property\n    def all_imports(self) -> Iterator[Import]:\n        for data_type in self.data_types:\n            yield from data_type.all_imports\n        yield from self.imports\n\n    @property\n    def imports(self) -> Iterator[Import]:\n        if self.import_:\n            yield self.import_\n        imports: Tuple[Tuple[bool, Import], ...] = (\n            (self.is_optional, IMPORT_OPTIONAL),\n            (len(self.data_types) > 1, IMPORT_UNION),\n        )\n        if any(self.literals):\n            import_literal = (\n                IMPORT_LITERAL\n                if self.python_version.has_literal_type\n                else IMPORT_LITERAL_BACKPORT\n            )\n            imports = (\n                *imports,\n                (any(self.literals), import_literal),\n            )\n\n        if self.use_generic_container:\n            if self.use_standard_collections:\n                imports = (\n                    *imports,\n                    (self.is_list, IMPORT_ABC_SEQUENCE),\n                    (self.is_dict, IMPORT_ABC_MAPPING),\n                )\n            else:\n                imports = (\n                    *imports,\n                    (self.is_list, IMPORT_SEQUENCE),\n                    (self.is_dict, IMPORT_MAPPING),\n                )\n        elif not self.use_standard_collections:\n            imports = (\n                *imports,\n                (self.is_list, IMPORT_LIST),\n                (self.is_dict, IMPORT_DICT),\n            )\n        for field, import_ in imports:\n            if field and import_ != self.import_:\n                yield import_\n\n    def __init__(self, **values: Any) -> None:\n        super().__init__(**values)  # type: ignore\n\n        for type_ in self.data_types:\n            if type_.type == 'Any' and type_.is_optional:\n                if any(\n                    t for t in self.data_types if t.type != 'Any'\n                ):  # pragma: no cover\n                    self.is_optional = True\n                    self.data_types = [\n                        t\n                        for t in self.data_types\n                        if not (t.type == 'Any' and t.is_optional)\n                    ]\n                break\n\n        for data_type in self.data_types:\n            if data_type.reference:\n                data_type.parent = self\n\n        if self.reference:\n            self.reference.children.append(self)\n\n    @property\n    def type_hint(self) -> str:\n        type_: Optional[str] = self.alias or self.type\n        if not type_:\n            if len(self.data_types) > 1:\n                type_ = f\"Union[{', '.join(data_type.type_hint for data_type in self.data_types)}]\"\n            elif len(self.data_types) == 1:\n                type_ = self.data_types[0].type_hint\n            elif self.literals:\n                type_ = (\n                    f\"Literal[{', '.join(repr(literal) for literal in self.literals)}]\"\n                )\n            else:\n                if self.reference:\n                    type_ = self.reference.short_name\n                else:\n                    # TODO support strict Any\n                    # type_ = 'Any'\n                    type_ = ''\n        if self.reference and self.python_version == PythonVersion.PY_36:\n            type_ = f\"'{type_}'\"\n        if self.is_list:\n            if self.use_generic_container:\n                list_ = 'Sequence'\n            elif self.use_standard_collections:\n                list_ = 'list'\n            else:\n                list_ = 'List'\n            type_ = f'{list_}[{type_}]' if type_ else list_\n        elif self.is_dict:\n            if self.use_generic_container:\n                dict_ = 'Mapping'\n            elif self.use_standard_collections:\n                dict_ = 'dict'\n            else:\n                dict_ = 'Dict'\n            type_ = f'{dict_}[str, {type_}]' if type_ else dict_\n        if self.is_optional and type_ != 'Any':\n            type_ = f'Optional[{type_}]'\n        elif self.is_func:\n            if self.kwargs:\n                kwargs: str = ', '.join(f'{k}={v}' for k, v in self.kwargs.items())\n                return f'{type_}({kwargs})'\n            return f'{type_}()'\n        return type_\n\n\nDataType.update_forward_refs()\n\nDataTypeT = TypeVar('DataTypeT', bound=DataType)\n\n\nclass Types(Enum):\n    integer = auto()\n    int32 = auto()\n    int64 = auto()\n    number = auto()\n    float = auto()\n    double = auto()\n    decimal = auto()\n    time = auto()\n    string = auto()\n    byte = auto()\n    binary = auto()\n    date = auto()\n    date_time = auto()\n    password = auto()\n    email = auto()\n    uuid = auto()\n    uuid1 = auto()\n    uuid2 = auto()\n    uuid3 = auto()\n    uuid4 = auto()\n    uuid5 = auto()\n    uri = auto()\n    hostname = auto()\n    ipv4 = auto()\n    ipv6 = auto()\n    boolean = auto()\n    object = auto()\n    null = auto()\n    array = auto()\n    any = auto()\n\n\nclass DataTypeManager(ABC):\n    def __init__(\n        self,\n        python_version: PythonVersion = PythonVersion.PY_37,\n        use_standard_collections: bool = False,\n        use_generic_container_types: bool = False,\n        strict_types: Optional[Sequence[StrictTypes]] = None,\n    ) -> None:\n        self.python_version = python_version\n        self.use_standard_collections: bool = use_standard_collections\n        self.use_generic_container_types: bool = use_generic_container_types\n        self.strict_types: Sequence[StrictTypes] = strict_types or ()\n\n        if (\n            use_generic_container_types and python_version == PythonVersion.PY_36\n        ):  # pragma: no cover\n            raise Exception(\n                \"use_generic_container_types can not be used with target_python_version 3.6.\\n\"\n                \" The version will be not supported in a future version\"\n            )\n\n        if TYPE_CHECKING:\n            self.data_type: Type[DataType]\n        else:\n            self.data_type: Type[DataType] = create_model(\n                'ContextDataType',\n                python_version=python_version,\n                use_standard_collections=use_standard_collections,\n                use_generic_container=use_generic_container_types,\n                __base__=DataType,\n            )\n\n    @abstractmethod\n    def get_data_type(self, types: Types, **kwargs: Any) -> DataType:\n        raise NotImplementedError\n\n    def get_data_type_from_full_path(\n        self, full_path: str, is_custom_type: bool\n    ) -> DataType:\n        return self.data_type.from_import(\n            Import.from_full_path(full_path), is_custom_type=is_custom_type\n        )\n", "path": "datamodel_code_generator/types.py"}]}