Skip to content

fix: Fail when duplicate names are generated #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 10, 2021
12 changes: 12 additions & 0 deletions openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ def build_model_property(
name=name,
additional_properties=additional_properties,
)
if prop.reference.class_name in schemas.models:
error = PropertyError(
data=data, detail=f'Attempted to generate duplicate models with name "{prop.reference.class_name}"'
)
return error, schemas

schemas = attr.evolve(schemas, models={**schemas.models, prop.reference.class_name: prop})
return prop, schemas

Expand Down Expand Up @@ -374,6 +380,12 @@ def build_enum_property(
values=values,
value_type=value_type,
)
if prop.reference.class_name in schemas.enums:
error = PropertyError(
data=data, detail=f'Attempted to generate duplicate enums with name "{prop.reference.class_name}"'
)
return error, schemas

schemas = attr.evolve(schemas, enums={**schemas.enums, prop.reference.class_name: prop})
return prop, schemas

Expand Down