Skip to content

Commit 600a039

Browse files
Merge pull request #47 from oshmoun/main
normalize model names to avoid invalid characters in classes and imports
2 parents ea12f97 + b6c650e commit 600a039

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/openapi_python_generator/language_converters/python/model_generator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def type_converter( # noqa: C901
4949
if isinstance(sub_schema, Schema):
5050
conversions.append(type_converter(sub_schema, True))
5151
else:
52-
import_type = sub_schema.ref.split("/")[-1]
52+
import_type = common.normalize_symbol(sub_schema.ref.split("/")[-1])
5353
if import_type == model_name:
5454
conversions.append(
5555
TypeConversion(
@@ -91,7 +91,7 @@ def type_converter( # noqa: C901
9191
if isinstance(sub_schema, Schema):
9292
conversions.append(type_converter(sub_schema, True))
9393
else:
94-
import_type = sub_schema.ref.split("/")[-1]
94+
import_type = common.normalize_symbol(sub_schema.ref.split("/")[-1])
9595
import_types = [f"from .{import_type} import {import_type}"]
9696
conversions.append(
9797
TypeConversion(
@@ -221,7 +221,7 @@ def _generate_property_from_reference(
221221
and parent_schema.required is not None
222222
and name in parent_schema.required
223223
) or force_required
224-
import_model = reference.ref.split("/")[-1]
224+
import_model = common.normalize_symbol(reference.ref.split("/")[-1])
225225

226226
if import_model == model_name:
227227
type_conv = TypeConversion(
@@ -262,7 +262,8 @@ def generate_models(components: Components) -> List[Model]:
262262
if components.schemas is None:
263263
return models
264264

265-
for name, schema_or_reference in components.schemas.items():
265+
for schema_name, schema_or_reference in components.schemas.items():
266+
name = common.normalize_symbol(schema_name)
266267
if schema_or_reference.enum is not None:
267268
value_dict = schema_or_reference.dict()
268269
regex = re.compile(r"[\s\/=\*\+]+")

0 commit comments

Comments
 (0)