Skip to content

Commit 2ef30b4

Browse files
committed
Support conflicting enum names. Closes #54
1 parent 3c7d395 commit 2ef30b4

File tree

18 files changed

+116
-209
lines changed

18 files changed

+116
-209
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Classes generated to be included within lists will now be named like <ListName>Item. For example, if a property
1111
named "statuses" is an array of enum values, previously the `Enum` class declared would be called "Statuses". Now it
1212
will be called "StatusesItem". If a "title" attribute was used in the OpenAPI document, that should still be respected
13-
and used instead of the generated name.
14-
- Clients now require httpx ^0.13.0 (up from ^0.12.1)
13+
and used instead of the generated name. You can restore previous names by adding "StatusesItem" to the `class_overrides`
14+
section of a config file.
15+
- Clients now require httpx ^0.13.0 (up from ^0.12.1). See [httpx release notes](https://github.com/encode/httpx/releases/tag/0.13.0)
16+
for details.
1517

1618
### Additions
1719
- Support for binary format strings (file payloads)
1820
- Support for multipart/form bodies
1921
- Support for any supported property within a list (array), including other lists.
2022
- Support for Union types ("anyOf" in OpenAPI document)
2123
- Support for more basic response types (integer, number, boolean)
24+
- Support for duplicate enums. Instead of erroring, enums with the same name (title) but differing values
25+
will have a number appended to the end. So if you have two conflicting enums named `MyEnum`, one of them
26+
will now be named `MyEnum1`. Note that the order in which these are processed and therefore named is entirely
27+
dependent on the order they are read from the OpenAPI document, so changes to the document could result
28+
in swapping the names of conflicting Enums.
2229

2330
### Changes
2431
- The way most imports are handled was changed which *should* lead to fewer unused imports in generated files.

end_to_end_tests/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ class_overrides:
22
_ABCResponse:
33
class_name: ABCResponse
44
module_name: abc_response
5+
AnEnumValueItem:
6+
class_name: AnEnumValue
7+
module_name: an_enum_value
8+
NestedListOfEnumsItemItem:
9+
class_name: AnEnumValue
10+
module_name: an_enum_value

end_to_end_tests/fastapi_app/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class AnEnum(Enum):
2727
SECOND_VALUE = "SECOND_VALUE"
2828

2929

30+
class DifferentEnum(Enum):
31+
FIRST_VALUE = "DIFFERENT"
32+
SECOND_VALUE = "OTHER"
33+
34+
3035
class OtherModel(BaseModel):
3136
""" A different model for calling from TestModel """
3237

@@ -37,7 +42,7 @@ class AModel(BaseModel):
3742
""" A Model for testing all the ways custom objects can be used """
3843

3944
an_enum_value: AnEnum
40-
nested_list_of_enums: List[List[AnEnum]]
45+
nested_list_of_enums: List[List[DifferentEnum]]
4146
aCamelDateTime: Union[datetime, date]
4247
a_date: date
4348

end_to_end_tests/fastapi_app/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
"type": "array",
165165
"items": {
166166
"enum": [
167-
"FIRST_VALUE",
168-
"SECOND_VALUE"
167+
"DIFFERENT",
168+
"OTHER"
169169
]
170170
}
171171
}

end_to_end_tests/golden-master/my_test_api_client/api/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from ..client import AuthenticatedClient, Client
88
from ..errors import ApiResponseError
99
from ..models.a_model import AModel
10-
from ..models.an_enum_value_item import AnEnumValueItem
10+
from ..models.an_enum_value import AnEnumValue
1111
from ..models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
1212
from ..models.http_validation_error import HTTPValidationError
1313

1414

1515
def get_user_list(
16-
*, client: Client, an_enum_value: List[AnEnumValueItem], some_date: Union[date, datetime],
16+
*, client: Client, an_enum_value: List[AnEnumValue], some_date: Union[date, datetime],
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:

end_to_end_tests/golden-master/my_test_api_client/async_api/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from ..client import AuthenticatedClient, Client
88
from ..errors import ApiResponseError
99
from ..models.a_model import AModel
10-
from ..models.an_enum_value_item import AnEnumValueItem
10+
from ..models.an_enum_value import AnEnumValue
1111
from ..models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
1212
from ..models.http_validation_error import HTTPValidationError
1313

1414

1515
async def get_user_list(
16-
*, client: Client, an_enum_value: List[AnEnumValueItem], some_date: Union[date, datetime],
16+
*, client: Client, an_enum_value: List[AnEnumValue], some_date: Union[date, datetime],
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:

end_to_end_tests/golden-master/my_test_api_client/models/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
from .a_model import AModel
44
from .an_enum_value import AnEnumValue
5-
from .an_enum_value_item import AnEnumValueItem
5+
from .an_enum_value1 import AnEnumValue1
66
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
77
from .http_validation_error import HTTPValidationError
8-
from .nested_list_of_enums_item_item import NestedListOfEnumsItemItem
98
from .types import *
109
from .validation_error import ValidationError

end_to_end_tests/golden-master/my_test_api_client/models/a_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from typing import Any, Dict, List, Union, cast
66

77
from .an_enum_value import AnEnumValue
8-
from .nested_list_of_enums_item_item import NestedListOfEnumsItemItem
8+
from .an_enum_value1 import AnEnumValue1
99

1010

1111
@dataclass
1212
class AModel:
1313
""" A Model for testing all the ways custom objects can be used """
1414

1515
an_enum_value: AnEnumValue
16-
nested_list_of_enums: List[List[NestedListOfEnumsItemItem]]
16+
nested_list_of_enums: List[List[AnEnumValue1]]
1717
a_camel_date_time: Union[datetime, date]
1818
a_date: date
1919

@@ -53,7 +53,7 @@ def from_dict(d: Dict[str, Any]) -> AModel:
5353
for nested_list_of_enums_item_data in d["nested_list_of_enums"]:
5454
nested_list_of_enums_item = []
5555
for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data:
56-
nested_list_of_enums_item_item = NestedListOfEnumsItemItem(nested_list_of_enums_item_item_data)
56+
nested_list_of_enums_item_item = AnEnumValue1(nested_list_of_enums_item_item_data)
5757

5858
nested_list_of_enums_item.append(nested_list_of_enums_item_item)
5959

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
4+
class AnEnumValue1(str, Enum):
5+
DIFFERENT = "DIFFERENT"
6+
OTHER = "OTHER"

end_to_end_tests/golden-master/my_test_api_client/models/an_enum_value_item.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)