|
4 | 4 | from typing import Optional
|
5 | 5 |
|
6 | 6 | import click
|
7 |
| -from openapi_schema_pydantic import Components |
8 |
| -from openapi_schema_pydantic import Reference |
9 |
| -from openapi_schema_pydantic import Schema |
| 7 | +from openapi_pydantic.v3.v3_0 import Schema, Reference, Components |
10 | 8 |
|
11 | 9 | from openapi_python_generator.language_converters.python import common
|
12 | 10 | from openapi_python_generator.language_converters.python.jinja_config import (
|
@@ -42,7 +40,7 @@ def type_converter( # noqa: C901
|
42 | 40 | pre_type = "Optional["
|
43 | 41 | post_type = "]"
|
44 | 42 |
|
45 |
| - original_type = schema.type if schema.type is not None else "object" |
| 43 | + original_type = schema.type.value if schema.type is not None else "object" |
46 | 44 | import_types: Optional[List[str]] = None
|
47 | 45 |
|
48 | 46 | if schema.allOf is not None:
|
@@ -156,7 +154,7 @@ def type_converter( # noqa: C901
|
156 | 154 | original_type = "array<" + converted_reference.type.original_type + ">"
|
157 | 155 | retVal += converted_reference.type.converted_type
|
158 | 156 | elif isinstance(schema.items, Schema):
|
159 |
| - original_type = "array<" + str(schema.items.type) + ">" |
| 157 | + original_type = "array<" + (str(schema.items.type.value) if schema.items.type is not None else "unknown")+ ">" |
160 | 158 | retVal += type_converter(schema.items, True).converted_type
|
161 | 159 | else:
|
162 | 160 | original_type = "array<unknown>"
|
@@ -196,11 +194,17 @@ def _generate_property_from_schema(
|
196 | 194 | and parent_schema.required is not None
|
197 | 195 | and name in parent_schema.required
|
198 | 196 | )
|
| 197 | + |
| 198 | + import_type = None |
| 199 | + if required: |
| 200 | + import_type = [] if name == model_name else [name] |
| 201 | + |
199 | 202 | return Property(
|
200 | 203 | name=name,
|
201 | 204 | type=type_converter(schema, required, model_name),
|
202 | 205 | required=required,
|
203 | 206 | default=None if required else "None",
|
| 207 | + import_type=import_type, |
204 | 208 | )
|
205 | 209 |
|
206 | 210 |
|
|
0 commit comments