Skip to content

Commit e01f7ea

Browse files
committed
feat: update OpenAPI type handling to support Reference30 and Reference31
1 parent a9310e1 commit e01f7ea

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: poetry run pytest --cov=src/ --cov-report=xml --cov-fail-under 90 --cov-config=.coveragerc
3939

4040
- name: 🔍 Type checking with mypy
41-
run: poetry run ty src/
41+
run: poetry run ty check src/
4242

4343
- name: 🎨 Code formatting with black
4444
run: poetry run black --check .

src/openapi_python_generator/language_converters/python/model_generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def type_converter( # noqa: C901
5151
:return: The converted type
5252
"""
5353
# Handle Reference objects by converting them to type references
54-
if isinstance(schema, Reference):
54+
if isinstance(schema, Reference30) or isinstance(schema, Reference31):
5555
import_type = common.normalize_symbol(schema.ref.split("/")[-1])
5656
if required:
5757
converted_type = import_type
@@ -85,7 +85,7 @@ def type_converter( # noqa: C901
8585
if schema.allOf is not None:
8686
conversions = []
8787
for sub_schema in schema.allOf:
88-
if isinstance(sub_schema, Schema):
88+
if isinstance(sub_schema, Schema30) or isinstance(sub_schema, Schema31):
8989
conversions.append(type_converter(sub_schema, True))
9090
else:
9191
import_type = common.normalize_symbol(sub_schema.ref.split("/")[-1])
@@ -130,7 +130,7 @@ def type_converter( # noqa: C901
130130
used = used if used is not None else []
131131
conversions = []
132132
for sub_schema in used:
133-
if isinstance(sub_schema, Schema):
133+
if isinstance(sub_schema, Schema30) or isinstance(sub_schema, Schema31):
134134
conversions.append(type_converter(sub_schema, True))
135135
else:
136136
import_type = common.normalize_symbol(sub_schema.ref.split("/")[-1])
@@ -191,14 +191,14 @@ def type_converter( # noqa: C901
191191
converted_type = pre_type + "bool" + post_type
192192
elif schema.type == "array" or str(schema.type) == "DataType.ARRAY":
193193
retVal = pre_type + "List["
194-
if isinstance(schema.items, Reference):
194+
if isinstance(schema.items, Reference30) or isinstance(schema.items, Reference31):
195195
converted_reference = _generate_property_from_reference(
196196
model_name or "", "", schema.items, schema, required
197197
)
198198
import_types = converted_reference.type.import_types
199199
original_type = "array<" + converted_reference.type.original_type + ">"
200200
retVal += converted_reference.type.converted_type
201-
elif isinstance(schema.items, Schema):
201+
elif isinstance(schema.items, Schema30) or isinstance(schema.items, Schema31):
202202
type_str = schema.items.type
203203
if hasattr(type_str, "value"):
204204
type_value = str(type_str.value) if type_str is not None else "unknown"
@@ -440,7 +440,7 @@ def generate_models(
440440
else {}
441441
)
442442
for prop_name, property in property_iterator:
443-
if isinstance(property, Reference):
443+
if isinstance(property, Reference30) or isinstance(property, Reference31):
444444
conv_property = _generate_property_from_reference(
445445
name, prop_name, property, schema_or_reference
446446
)

src/openapi_python_generator/language_converters/python/service_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def generate_body_param(operation: Operation) -> Union[str, None]:
9696
if operation.requestBody is None:
9797
return None
9898
else:
99-
if isinstance(operation.requestBody, Reference):
99+
if isinstance(operation.requestBody, Reference30) or isinstance(operation.requestBody, Reference31):
100100
return "data.dict()"
101101

102102
if operation.requestBody.content is None:
@@ -156,18 +156,18 @@ def _generate_params_from_content(content: Any):
156156
required = False
157157
param_name_cleaned = common.normalize_symbol(param.name)
158158

159-
if isinstance(param.param_schema, Schema):
159+
if isinstance(param.param_schema, Schema30) or isinstance(param.param_schema, Schema31):
160160
converted_result = (
161161
f"{param_name_cleaned} : {type_converter(param.param_schema, param.required).converted_type}"
162162
+ ("" if param.required else " = None")
163163
)
164164
required = param.required
165-
elif isinstance(param.param_schema, Reference):
165+
elif isinstance(param.param_schema, Reference30) or isinstance(param.param_schema, Reference31):
166166
converted_result = (
167167
f"{param_name_cleaned} : {param.param_schema.ref.split('/')[-1] }"
168168
+ (
169169
""
170-
if isinstance(param, Reference) or param.required
170+
if isinstance(param, Reference30) or isinstance(param, Reference31) or param.required
171171
else " = None"
172172
)
173173
)

0 commit comments

Comments
 (0)