Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 27f3815

Browse files
committed
Support arbitrary list properties
Closes openapi-generators#46
1 parent 0e74b59 commit 27f3815

28 files changed

+467
-445
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dmypy.json
2222
/coverage.xml
2323
/.coverage
2424
htmlcov/
25+
26+
# Generated end to end test data
27+
my-test-api-client

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77

88
## 0.4.0 - Unreleased
9+
### Breaking Changes
10+
- Classes generated to be included within lists will now be named like <ListName>Item. For example, if a property
11+
named "statuses" is an array of enum values, previously the `Enum` class declared would be called "Statuses". Now it
12+
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+
915
### Additions
10-
- Add support for binary format strings (file payloads)
11-
- Add support for multipart/form bodies
16+
- Support for binary format strings (file payloads)
17+
- Support for multipart/form bodies
18+
- Support for any supported property within a list (array), including other lists.
19+
20+
### Changes
21+
- The way most imports are handled was changed which *should* lead to fewer unused imports in generated files.
1222

1323
## 0.3.0 - 2020-04-25
1424
### Additions

end_to_end_tests/fastapi_app/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class AModel(BaseModel):
4141
""" A Model for testing all the ways custom objects can be used """
4242

4343
an_enum_value: AnEnum
44-
a_list_of_enums: List[AnEnum]
45-
a_list_of_strings: List[str]
46-
a_list_of_objects: List[OtherModel]
44+
nested_list_of_enums: List[List[AnEnum]]
4745
aCamelDateTime: datetime
4846
a_date: date
4947

5048

5149
@test_router.get("/", response_model=List[AModel], operation_id="getUserList")
52-
def get_list(statuses: List[AnEnum] = Query(...), some_date: date = Query(...), some_datetime: datetime = Query(...)):
50+
def get_list(
51+
an_enum_value: List[AnEnum] = Query(...), some_date: date = Query(...), some_datetime: datetime = Query(...)
52+
):
5353
""" Get a list of things """
5454
return
5555

end_to_end_tests/fastapi_app/openapi.json

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{
3838
"required": true,
3939
"schema": {
40-
"title": "Statuses",
40+
"title": "An Enum Value",
4141
"type": "array",
4242
"items": {
4343
"enum": [
@@ -46,7 +46,7 @@
4646
]
4747
}
4848
},
49-
"name": "statuses",
49+
"name": "an_enum_value",
5050
"in": "query"
5151
},
5252
{
@@ -145,9 +145,7 @@
145145
"title": "AModel",
146146
"required": [
147147
"an_enum_value",
148-
"a_list_of_enums",
149-
"a_list_of_strings",
150-
"a_list_of_objects",
148+
"nested_list_of_enums",
151149
"aCamelDateTime",
152150
"a_date"
153151
],
@@ -160,28 +158,17 @@
160158
"SECOND_VALUE"
161159
]
162160
},
163-
"a_list_of_enums": {
164-
"title": "A List Of Enums",
161+
"nested_list_of_enums": {
162+
"title": "Nested List Of Enums",
165163
"type": "array",
166164
"items": {
167-
"enum": [
168-
"FIRST_VALUE",
169-
"SECOND_VALUE"
170-
]
171-
}
172-
},
173-
"a_list_of_strings": {
174-
"title": "A List Of Strings",
175-
"type": "array",
176-
"items": {
177-
"type": "string"
178-
}
179-
},
180-
"a_list_of_objects": {
181-
"title": "A List Of Objects",
182-
"type": "array",
183-
"items": {
184-
"$ref": "#/components/schemas/OtherModel"
165+
"type": "array",
166+
"items": {
167+
"enum": [
168+
"FIRST_VALUE",
169+
"SECOND_VALUE"
170+
]
171+
}
185172
}
186173
},
187174
"aCamelDateTime": {
@@ -224,20 +211,6 @@
224211
}
225212
}
226213
},
227-
"OtherModel": {
228-
"title": "OtherModel",
229-
"required": [
230-
"a_value"
231-
],
232-
"type": "object",
233-
"properties": {
234-
"a_value": {
235-
"title": "A Value",
236-
"type": "string"
237-
}
238-
},
239-
"description": "A different model for calling from TestModel "
240-
},
241214
"ValidationError": {
242215
"title": "ValidationError",
243216
"required": [

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
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
1011
from ..models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
1112
from ..models.http_validation_error import HTTPValidationError
12-
from ..models.statuses import Statuses
1313

1414

1515
def get_user_list(
16-
*, client: Client, statuses: List[Statuses], some_date: date, some_datetime: datetime,
16+
*, client: Client, an_enum_value: List[AnEnumValueItem], some_date: date, some_datetime: datetime,
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:
2020
""" Get a list of things """
2121
url = "{}/tests/".format(client.base_url)
2222

2323
params = {
24-
"statuses": statuses,
24+
"an_enum_value": an_enum_value,
2525
"some_date": some_date.isoformat(),
2626
"some_datetime": some_datetime.isoformat(),
2727
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
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
1011
from ..models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
1112
from ..models.http_validation_error import HTTPValidationError
12-
from ..models.statuses import Statuses
1313

1414

1515
async def get_user_list(
16-
*, client: Client, statuses: List[Statuses], some_date: date, some_datetime: datetime,
16+
*, client: Client, an_enum_value: List[AnEnumValueItem], some_date: date, some_datetime: datetime,
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:
2020
""" Get a list of things """
2121
url = "{}/tests/".format(client.base_url)
2222

2323
params = {
24-
"statuses": statuses,
24+
"an_enum_value": an_enum_value,
2525
"some_date": some_date.isoformat(),
2626
"some_datetime": some_datetime.isoformat(),
2727
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
""" Contains all the data models used in inputs/outputs """
22

3-
from .a_list_of_enums import AListOfEnums
43
from .a_model import AModel
54
from .abc_response import ABCResponse
65
from .an_enum_value import AnEnumValue
6+
from .an_enum_value_item import AnEnumValueItem
77
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
88
from .http_validation_error import HTTPValidationError
9-
from .other_model import OtherModel
10-
from .statuses import Statuses
9+
from .nested_list_of_enums_item_item import NestedListOfEnumsItemItem
1110
from .types import *
1211
from .validation_error import ValidationError
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,51 @@
11
from __future__ import annotations
22

3-
from dataclasses import astuple, dataclass
3+
from dataclasses import dataclass
44
from datetime import date, datetime
5-
from typing import Any, Dict, List, Optional, cast
5+
from typing import Any, Dict, List, cast
66

7-
from .a_list_of_enums import AListOfEnums
87
from .an_enum_value import AnEnumValue
9-
from .other_model import OtherModel
10-
from .types import *
8+
from .nested_list_of_enums_item_item import NestedListOfEnumsItemItem
119

1210

1311
@dataclass
1412
class AModel:
1513
""" A Model for testing all the ways custom objects can be used """
1614

1715
an_enum_value: AnEnumValue
18-
a_list_of_enums: List[AListOfEnums]
19-
a_list_of_strings: List[str]
20-
a_list_of_objects: List[OtherModel]
16+
nested_list_of_enums: List[List[NestedListOfEnumsItemItem]]
2117
a_camel_date_time: datetime
2218
a_date: date
2319

2420
def to_dict(self) -> Dict[str, Any]:
2521
return {
2622
"an_enum_value": self.an_enum_value.value,
27-
"a_list_of_enums": self.a_list_of_enums,
28-
"a_list_of_strings": self.a_list_of_strings,
29-
"a_list_of_objects": self.a_list_of_objects,
23+
"nested_list_of_enums": self.nested_list_of_enums,
3024
"aCamelDateTime": self.a_camel_date_time.isoformat(),
3125
"a_date": self.a_date.isoformat(),
3226
}
3327

3428
@staticmethod
3529
def from_dict(d: Dict[str, Any]) -> AModel:
36-
3730
an_enum_value = AnEnumValue(d["an_enum_value"])
3831

39-
a_list_of_enums = []
40-
for a_list_of_enums_item in d.get("a_list_of_enums", []):
41-
a_list_of_enums.append(AListOfEnums(a_list_of_enums_item))
32+
nested_list_of_enums = []
33+
for nested_list_of_enums_item_data in d["nested_list_of_enums"]:
34+
nested_list_of_enums_item = []
35+
for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data:
36+
nested_list_of_enums_item_item = NestedListOfEnumsItemItem(nested_list_of_enums_item_item_data)
4237

43-
a_list_of_strings = d.get("a_list_of_strings", [])
38+
nested_list_of_enums_item.append(nested_list_of_enums_item_item)
4439

45-
a_list_of_objects = []
46-
for a_list_of_objects_item in d.get("a_list_of_objects", []):
47-
a_list_of_objects.append(OtherModel.from_dict(a_list_of_objects_item))
40+
nested_list_of_enums.append(nested_list_of_enums_item)
4841

4942
a_camel_date_time = datetime.fromisoformat(d["aCamelDateTime"])
5043

5144
a_date = date.fromisoformat(d["a_date"])
5245

5346
return AModel(
5447
an_enum_value=an_enum_value,
55-
a_list_of_enums=a_list_of_enums,
56-
a_list_of_strings=a_list_of_strings,
57-
a_list_of_objects=a_list_of_objects,
48+
nested_list_of_enums=nested_list_of_enums,
5849
a_camel_date_time=a_camel_date_time,
5950
a_date=a_date,
6051
)

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from __future__ import annotations
22

3-
from dataclasses import astuple, dataclass
4-
from typing import Any, Dict, List, Optional, cast
5-
6-
from .types import *
3+
from dataclasses import dataclass
4+
from typing import Any, Dict
75

86

97
@dataclass
@@ -19,7 +17,6 @@ def to_dict(self) -> Dict[str, Any]:
1917

2018
@staticmethod
2119
def from_dict(d: Dict[str, Any]) -> ABCResponse:
22-
2320
success = d["success"]
2421

2522
return ABCResponse(success=success,)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
22

33

4-
class AListOfEnums(str, Enum):
4+
class AnEnumValueItem(str, Enum):
55
FIRST_VALUE = "FIRST_VALUE"
66
SECOND_VALUE = "SECOND_VALUE"

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

33
from dataclasses import astuple, dataclass
4-
from typing import Any, Dict, List, Optional, cast
4+
from typing import Any, Dict
55

6-
from .types import *
6+
from .types import File
77

88

99
@dataclass
@@ -19,7 +19,6 @@ def to_dict(self) -> Dict[str, Any]:
1919

2020
@staticmethod
2121
def from_dict(d: Dict[str, Any]) -> BodyUploadFileTestsUploadPost:
22-
2322
some_file = d["some_file"]
2423

2524
return BodyUploadFileTestsUploadPost(some_file=some_file,)

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from dataclasses import astuple, dataclass
3+
from dataclasses import dataclass
44
from typing import Any, Dict, List, Optional, cast
55

6-
from .types import *
76
from .validation_error import ValidationError
87

98

@@ -20,8 +19,10 @@ def to_dict(self) -> Dict[str, Any]:
2019

2120
@staticmethod
2221
def from_dict(d: Dict[str, Any]) -> HTTPValidationError:
23-
2422
detail = []
25-
for detail_item in d.get("detail", []):
26-
detail.append(ValidationError.from_dict(detail_item))
23+
for detail_item_data in d.get("detail") or []:
24+
detail_item = ValidationError.from_dict(detail_item_data)
25+
26+
detail.append(detail_item)
27+
2728
return HTTPValidationError(detail=detail,)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
22

33

4-
class Statuses(str, Enum):
4+
class NestedListOfEnumsItemItem(str, Enum):
55
FIRST_VALUE = "FIRST_VALUE"
66
SECOND_VALUE = "SECOND_VALUE"

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

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

0 commit comments

Comments
 (0)