Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions openapi_python_client/parser/properties/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def parse_reference_path(ref_path_raw: str) -> Union[ReferencePath, ParseError]:
return cast(ReferencePath, parsed.fragment)


EXISTING_MODULE_NAMES: set[PythonIdentifier] = set()

def _unique_module_name(candidate_name: PythonIdentifier) -> PythonIdentifier:
if candidate_name not in EXISTING_MODULE_NAMES:
EXISTING_MODULE_NAMES.add(candidate_name)
return candidate_name

counter = 0
while True:
new_name = f"{candidate_name}{counter}"

if new_name not in EXISTING_MODULE_NAMES:
EXISTING_MODULE_NAMES.add(new_name)
return new_name

counter += 1


@define
class Class:
"""Represents Python class which will be generated from an OpenAPI schema"""
Expand All @@ -67,7 +85,9 @@ def from_string(*, string: str, config: Config) -> "Class":
module_name = override.module_name
else:
module_name = class_name

module_name = PythonIdentifier(module_name, config.field_prefix)
module_name = _unique_module_name(module_name)

return Class(name=class_name, module_name=module_name)

Expand Down