Skip to content

Commit a0ba0e7

Browse files
committed
Add support for Python 3.6 (fixes #154 & #137). Also add support for IntEnum properties.
1 parent 03bc946 commit a0ba0e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+576
-277
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ workflows:
7878
- test:
7979
matrix:
8080
parameters:
81-
python-version: ["3.7", "3.8"]
81+
python-version: ["3.6", "3.7", "3.8"]

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
the `sync()` and `asyncio()` functions for a path operation will return `None`. This means all return types are now
2020
`Optional`, so mypy will require you to handle potential errors (or explicitly ignore them).
2121
- Moved `models.types` generated module up a level, so just `types`.
22-
- `Client` and `AuthenticatedClient` are now declared using the `attrs` package instead of builtin `dataclass`
22+
- All generated classes that were `dataclass` now use the `attrs` package instead
2323

2424
### Additions
2525

@@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Unsupported content types or no responses at all will no longer result in an endpoint being completely skipped. Instead,
3434
only the `detailed` versions of the endpoint will be generated, where the resulting `Response.parsed` is always `None`.
3535
(#141)
36+
- Support for Python 3.6 (#137 & #154)
37+
- Support for enums with integer values
3638

3739
### Changes
3840

end_to_end_tests/fastapi_app/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" A FastAPI app used to create an OpenAPI document for end-to-end testing """
22
import json
33
from datetime import date, datetime
4-
from enum import Enum
4+
from enum import Enum, IntEnum
55
from pathlib import Path
66
from typing import Dict, List, Union
77

@@ -136,6 +136,16 @@ def unsupported_content():
136136
pass
137137

138138

139+
class AnIntEnum(IntEnum):
140+
FIRST = 1
141+
SECOND = 2
142+
143+
144+
@test_router.post("/int_enum")
145+
def int_enum(int_enum: AnIntEnum):
146+
pass
147+
148+
139149
app.include_router(test_router, prefix="/tests", tags=["tests"])
140150

141151

end_to_end_tests/fastapi_app/openapi.json

+52-20
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,8 @@
5151
"required": true,
5252
"schema": {
5353
"title": "Some Date",
54-
"anyOf": [
55-
{
56-
"type": "string",
57-
"format": "date"
58-
},
59-
{
60-
"type": "string",
61-
"format": "date-time"
62-
}
63-
]
54+
"type": "string",
55+
"format": "date"
6456
},
6557
"name": "some_date",
6658
"in": "query"
@@ -504,6 +496,45 @@
504496
}
505497
}
506498
}
499+
},
500+
"/tests/int_enum": {
501+
"post": {
502+
"tags": [
503+
"tests"
504+
],
505+
"summary": "Int Enum",
506+
"operationId": "int_enum_tests_int_enum_post",
507+
"parameters": [
508+
{
509+
"required": true,
510+
"schema": {
511+
"$ref": "#/components/schemas/AnIntEnum"
512+
},
513+
"name": "int_enum",
514+
"in": "query"
515+
}
516+
],
517+
"responses": {
518+
"200": {
519+
"description": "Successful Response",
520+
"content": {
521+
"application/json": {
522+
"schema": {}
523+
}
524+
}
525+
},
526+
"422": {
527+
"description": "Validation Error",
528+
"content": {
529+
"application/json": {
530+
"schema": {
531+
"$ref": "#/components/schemas/HTTPValidationError"
532+
}
533+
}
534+
}
535+
}
536+
}
537+
}
507538
}
508539
},
509540
"components": {
@@ -542,16 +573,8 @@
542573
},
543574
"aCamelDateTime": {
544575
"title": "Acameldatetime",
545-
"anyOf": [
546-
{
547-
"type": "string",
548-
"format": "date-time"
549-
},
550-
{
551-
"type": "string",
552-
"format": "date"
553-
}
554-
]
576+
"type": "string",
577+
"format": "date"
555578
},
556579
"a_date": {
557580
"title": "A Date",
@@ -569,6 +592,15 @@
569592
],
570593
"description": "For testing Enums in all the ways they can be used "
571594
},
595+
"AnIntEnum": {
596+
"title": "AnIntEnum",
597+
"enum": [
598+
1,
599+
2
600+
],
601+
"type": "integer",
602+
"description": "An enumeration."
603+
},
572604
"Body_upload_file_tests_upload_post": {
573605
"title": "Body_upload_file_tests_upload_post",
574606
"required": [

end_to_end_tests/golden-record/my_test_api_client/api/default/ping_ping_get.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from dataclasses import asdict
21
from typing import Any, Dict, List, Optional, Union, cast
32

43
import httpx
4+
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
77
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import datetime
2-
from dataclasses import asdict
32
from typing import Any, Dict, List, Optional, Union, cast
43

54
import httpx
5+
from attr import asdict
6+
from dateutil.parser import isoparse
67

78
from ...client import AuthenticatedClient, Client
89
from ...models.an_enum import AnEnum
@@ -15,8 +16,8 @@ def _get_kwargs(
1516
client: Client,
1617
json_body: Dict[Any, Any],
1718
string_prop: Optional[str] = "the default string",
18-
datetime_prop: Optional[datetime.datetime] = datetime.datetime(1010, 10, 10, 0, 0),
19-
date_prop: Optional[datetime.date] = datetime.date(1010, 10, 10),
19+
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"),
20+
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(),
2021
float_prop: Optional[float] = 3.14,
2122
int_prop: Optional[int] = 7,
2223
boolean_prop: Optional[bool] = False,
@@ -104,8 +105,8 @@ def sync_detailed(
104105
client: Client,
105106
json_body: Dict[Any, Any],
106107
string_prop: Optional[str] = "the default string",
107-
datetime_prop: Optional[datetime.datetime] = datetime.datetime(1010, 10, 10, 0, 0),
108-
date_prop: Optional[datetime.date] = datetime.date(1010, 10, 10),
108+
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"),
109+
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(),
109110
float_prop: Optional[float] = 3.14,
110111
int_prop: Optional[int] = 7,
111112
boolean_prop: Optional[bool] = False,
@@ -139,8 +140,8 @@ def sync(
139140
client: Client,
140141
json_body: Dict[Any, Any],
141142
string_prop: Optional[str] = "the default string",
142-
datetime_prop: Optional[datetime.datetime] = datetime.datetime(1010, 10, 10, 0, 0),
143-
date_prop: Optional[datetime.date] = datetime.date(1010, 10, 10),
143+
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"),
144+
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(),
144145
float_prop: Optional[float] = 3.14,
145146
int_prop: Optional[int] = 7,
146147
boolean_prop: Optional[bool] = False,
@@ -170,8 +171,8 @@ async def asyncio_detailed(
170171
client: Client,
171172
json_body: Dict[Any, Any],
172173
string_prop: Optional[str] = "the default string",
173-
datetime_prop: Optional[datetime.datetime] = datetime.datetime(1010, 10, 10, 0, 0),
174-
date_prop: Optional[datetime.date] = datetime.date(1010, 10, 10),
174+
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"),
175+
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(),
175176
float_prop: Optional[float] = 3.14,
176177
int_prop: Optional[int] = 7,
177178
boolean_prop: Optional[bool] = False,
@@ -204,8 +205,8 @@ async def asyncio(
204205
client: Client,
205206
json_body: Dict[Any, Any],
206207
string_prop: Optional[str] = "the default string",
207-
datetime_prop: Optional[datetime.datetime] = datetime.datetime(1010, 10, 10, 0, 0),
208-
date_prop: Optional[datetime.date] = datetime.date(1010, 10, 10),
208+
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"),
209+
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(),
209210
float_prop: Optional[float] = 3.14,
210211
int_prop: Optional[int] = 7,
211212
boolean_prop: Optional[bool] = False,

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from dataclasses import asdict
21
from typing import Any, Dict, List, Optional, Union, cast
32

43
import httpx
4+
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
77
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from dataclasses import asdict
21
from typing import Any, Dict, List, Optional, Union, cast
32

43
import httpx
4+
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
77
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from dataclasses import asdict
21
from typing import Any, Dict, List, Optional, Union, cast
32

43
import httpx
4+
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
77
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from dataclasses import asdict
21
from typing import Any, Dict, List, Optional, Union, cast
32

43
import httpx
4+
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
77
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import datetime
2-
from dataclasses import asdict
32
from typing import Any, Dict, List, Optional, Union, cast
43

54
import httpx
5+
from attr import asdict
6+
from dateutil.parser import isoparse
67

78
from ...client import AuthenticatedClient, Client
89
from ...models.a_model import AModel
@@ -15,7 +16,7 @@ def _get_kwargs(
1516
*,
1617
client: Client,
1718
an_enum_value: List[AnEnum],
18-
some_date: Union[datetime.date, datetime.datetime],
19+
some_date: datetime.date,
1920
) -> Dict[str, Any]:
2021
url = "{}/tests/".format(client.base_url)
2122

@@ -27,11 +28,7 @@ def _get_kwargs(
2728

2829
json_an_enum_value.append(an_enum_value_item)
2930

30-
if isinstance(some_date, datetime.date):
31-
json_some_date = some_date.isoformat()
32-
33-
else:
34-
json_some_date = some_date.isoformat()
31+
json_some_date = some_date.isoformat()
3532

3633
params: Dict[str, Any] = {
3734
"an_enum_value": json_an_enum_value,
@@ -68,7 +65,7 @@ def sync_detailed(
6865
*,
6966
client: Client,
7067
an_enum_value: List[AnEnum],
71-
some_date: Union[datetime.date, datetime.datetime],
68+
some_date: datetime.date,
7269
) -> Response[Union[List[AModel], HTTPValidationError]]:
7370
kwargs = _get_kwargs(
7471
client=client,
@@ -87,7 +84,7 @@ def sync(
8784
*,
8885
client: Client,
8986
an_enum_value: List[AnEnum],
90-
some_date: Union[datetime.date, datetime.datetime],
87+
some_date: datetime.date,
9188
) -> Optional[Union[List[AModel], HTTPValidationError]]:
9289
""" Get a list of things """
9390

@@ -102,7 +99,7 @@ async def asyncio_detailed(
10299
*,
103100
client: Client,
104101
an_enum_value: List[AnEnum],
105-
some_date: Union[datetime.date, datetime.datetime],
102+
some_date: datetime.date,
106103
) -> Response[Union[List[AModel], HTTPValidationError]]:
107104
kwargs = _get_kwargs(
108105
client=client,
@@ -120,7 +117,7 @@ async def asyncio(
120117
*,
121118
client: Client,
122119
an_enum_value: List[AnEnum],
123-
some_date: Union[datetime.date, datetime.datetime],
120+
some_date: datetime.date,
124121
) -> Optional[Union[List[AModel], HTTPValidationError]]:
125122
""" Get a list of things """
126123

0 commit comments

Comments
 (0)