Skip to content

Commit d19ffb2

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

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

+616
-278
lines changed

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-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
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
66

77
from ...client import AuthenticatedClient, Client
88
from ...models.an_enum import AnEnum
99
from ...models.http_validation_error import HTTPValidationError
10-
from ...types import Response
10+
from ...types import Response, parse_datetime
1111

1212

1313
def _get_kwargs(
1414
*,
1515
client: Client,
1616
json_body: Dict[Any, Any],
1717
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),
18+
datetime_prop: Optional[datetime.datetime] = parse_datetime("1010-10-10T00:00:00"),
19+
date_prop: Optional[datetime.date] = parse_datetime("1010-10-10").date(),
2020
float_prop: Optional[float] = 3.14,
2121
int_prop: Optional[int] = 7,
2222
boolean_prop: Optional[bool] = False,
@@ -104,8 +104,8 @@ def sync_detailed(
104104
client: Client,
105105
json_body: Dict[Any, Any],
106106
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),
107+
datetime_prop: Optional[datetime.datetime] = parse_datetime("1010-10-10T00:00:00"),
108+
date_prop: Optional[datetime.date] = parse_datetime("1010-10-10").date(),
109109
float_prop: Optional[float] = 3.14,
110110
int_prop: Optional[int] = 7,
111111
boolean_prop: Optional[bool] = False,
@@ -139,8 +139,8 @@ def sync(
139139
client: Client,
140140
json_body: Dict[Any, Any],
141141
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),
142+
datetime_prop: Optional[datetime.datetime] = parse_datetime("1010-10-10T00:00:00"),
143+
date_prop: Optional[datetime.date] = parse_datetime("1010-10-10").date(),
144144
float_prop: Optional[float] = 3.14,
145145
int_prop: Optional[int] = 7,
146146
boolean_prop: Optional[bool] = False,
@@ -170,8 +170,8 @@ async def asyncio_detailed(
170170
client: Client,
171171
json_body: Dict[Any, Any],
172172
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),
173+
datetime_prop: Optional[datetime.datetime] = parse_datetime("1010-10-10T00:00:00"),
174+
date_prop: Optional[datetime.date] = parse_datetime("1010-10-10").date(),
175175
float_prop: Optional[float] = 3.14,
176176
int_prop: Optional[int] = 7,
177177
boolean_prop: Optional[bool] = False,
@@ -204,8 +204,8 @@ async def asyncio(
204204
client: Client,
205205
json_body: Dict[Any, Any],
206206
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),
207+
datetime_prop: Optional[datetime.datetime] = parse_datetime("1010-10-10T00:00:00"),
208+
date_prop: Optional[datetime.date] = parse_datetime("1010-10-10").date(),
209209
float_prop: Optional[float] = 3.14,
210210
int_prop: Optional[int] = 7,
211211
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-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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
66

77
from ...client import AuthenticatedClient, Client
88
from ...models.a_model import AModel
99
from ...models.an_enum import AnEnum
1010
from ...models.http_validation_error import HTTPValidationError
11-
from ...types import Response
11+
from ...types import Response, parse_datetime
1212

1313

1414
def _get_kwargs(
1515
*,
1616
client: Client,
1717
an_enum_value: List[AnEnum],
18-
some_date: Union[datetime.date, datetime.datetime],
18+
some_date: datetime.date,
1919
) -> Dict[str, Any]:
2020
url = "{}/tests/".format(client.base_url)
2121

@@ -27,11 +27,7 @@ def _get_kwargs(
2727

2828
json_an_enum_value.append(an_enum_value_item)
2929

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

3632
params: Dict[str, Any] = {
3733
"an_enum_value": json_an_enum_value,
@@ -68,7 +64,7 @@ def sync_detailed(
6864
*,
6965
client: Client,
7066
an_enum_value: List[AnEnum],
71-
some_date: Union[datetime.date, datetime.datetime],
67+
some_date: datetime.date,
7268
) -> Response[Union[List[AModel], HTTPValidationError]]:
7369
kwargs = _get_kwargs(
7470
client=client,
@@ -87,7 +83,7 @@ def sync(
8783
*,
8884
client: Client,
8985
an_enum_value: List[AnEnum],
90-
some_date: Union[datetime.date, datetime.datetime],
86+
some_date: datetime.date,
9187
) -> Optional[Union[List[AModel], HTTPValidationError]]:
9288
""" Get a list of things """
9389

@@ -102,7 +98,7 @@ async def asyncio_detailed(
10298
*,
10399
client: Client,
104100
an_enum_value: List[AnEnum],
105-
some_date: Union[datetime.date, datetime.datetime],
101+
some_date: datetime.date,
106102
) -> Response[Union[List[AModel], HTTPValidationError]]:
107103
kwargs = _get_kwargs(
108104
client=client,
@@ -120,7 +116,7 @@ async def asyncio(
120116
*,
121117
client: Client,
122118
an_enum_value: List[AnEnum],
123-
some_date: Union[datetime.date, datetime.datetime],
119+
some_date: datetime.date,
124120
) -> Optional[Union[List[AModel], HTTPValidationError]]:
125121
""" Get a list of things """
126122

0 commit comments

Comments
 (0)