Skip to content

Commit 7387585

Browse files
committed
Start enumeration at 1
1 parent 30f42ac commit 7387585

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ If this option results in conflicts, you will need to manually override class na
182182

183183
Even with `use_path_prefixes_for_title_model_names` set to `true`, duplicate model class names can occur. By default, when duplicates are encountered they will be skipped.
184184

185-
Setting `enumerate_duplicate_model_names` to `true` in your config file will result in a number being added to duplicate names starting with 2. For instance, if `MyModelName` already exists, then the next time a model with that name is encountered, it will be named `MyModelName2`, then `MyModelName3` and so on.
185+
Setting `enumerate_duplicate_model_names` to `true` in your config file will result in a number being added to duplicate names starting with 1. For instance, if there are multiple occurances in the schema of `MyModelName`, the initial occurance will remain `MyModelName` and subsequent occurances will be named `MyModelName1`, `MyModelName2` and so on.
186186

187187
### http_timeout
188188

openapi_python_client/parser/properties/model_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def build(
7575
class_string = title
7676
class_info = Class.from_string(string=class_string, config=config)
7777
if config.enumerate_duplicate_model_names:
78-
suffix = 2
78+
suffix = 1
7979
while class_info.name in schemas.classes_by_name:
8080
class_info = Class.from_string(string=class_string + str(suffix), config=config)
8181
suffix += 1

tests/test_parser/test_properties/test_model_property.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,27 @@ def test_happy_path(self, model_property_factory, string_property_factory, date_
166166
)
167167

168168
@pytest.mark.parametrize(
169-
"existing_names, new_name, enumerate_duplicate_model_names, expected",
169+
"existing_names, new_name, enumerate_duplicate_model_names, should_raise, expected",
170170
ids=(
171171
"name without duplicate suffix",
172172
"name with duplicate suffix",
173173
"name with duplicate suffix and matching existing name",
174174
),
175175
argvalues=(
176-
(["OtherModel"], "OtherModel", None, 'Attempted to generate duplicate models with name "OtherModel"'),
177-
(["OtherModel"], "OtherModel", True, "OtherModel2"),
178-
(["OtherModel", "OtherModel2"], "OtherModel", True, "OtherModel3"),
176+
(["OtherModel"], "OtherModel", None, True, 'Attempted to generate duplicate models with name "OtherModel"'),
177+
(["OtherModel"], "OtherModel", True, False, "OtherModel1"),
178+
(["OtherModel", "OtherModel1"], "OtherModel", True, False, "OtherModel2"),
179179
),
180180
)
181-
def test_model_name_conflict(self, existing_names: str, new_name: str, enumerate_duplicate_model_names: Optional[str], expected: str, config):
181+
def test_model_name_conflict(
182+
self,
183+
existing_names: str,
184+
new_name: str,
185+
enumerate_duplicate_model_names: Optional[str],
186+
should_raise: bool,
187+
expected: str,
188+
config,
189+
):
182190
from openapi_python_client.parser.properties import ModelProperty
183191

184192
data = oai.Schema.model_construct()
@@ -195,11 +203,12 @@ def test_model_name_conflict(self, existing_names: str, new_name: str, enumerate
195203
process_properties=True,
196204
)
197205

198-
assert isinstance(result, (PropertyError, ModelProperty))
199-
if isinstance(result, PropertyError):
206+
if should_raise:
207+
assert isinstance(result, PropertyError)
200208
assert new_schemas == schemas
201-
assert result == PropertyError(detail=expected, data=data)
202-
else: # ModelProperty
209+
assert result.detail == expected
210+
else:
211+
assert isinstance(result, ModelProperty)
203212
assert result.class_info.name in new_schemas.classes_by_name
204213
assert result.class_info.name == expected
205214

0 commit comments

Comments
 (0)