Skip to content

Commit 6cb3082

Browse files
committed
update python templates
1 parent 9eb2000 commit 6cb3082

38 files changed

+148
-1333
lines changed

templates/python/README_onlypackage.mustache

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@ This python library package is generated without supporting files like setup.py
2626

2727
To be able to use it, you will need these dependencies in your own package that uses this library:
2828

29-
* urllib3 >= 1.25.3
30-
* python-dateutil
29+
* urllib3 >= 2.1.0, < 3.0.0
30+
* python-dateutil >= 2.8.2
3131
{{#asyncio}}
32-
* aiohttp
32+
* aiohttp >= 3.8.4
33+
* aiohttp-retry >= 2.8.3
3334
{{/asyncio}}
3435
{{#tornado}}
35-
* tornado>=4.2,<5
36+
* tornado >= 4.2, < 5
3637
{{/tornado}}
37-
* pydantic
38+
{{#hasHttpSignatureMethods}}
39+
* pem >= 19.3.0
40+
* pycryptodome >= 3.9.0
41+
{{/hasHttpSignatureMethods}}
42+
* pydantic >= 2
43+
* typing-extensions >= 4.7.1
3844

3945
## Getting Started
4046

templates/python/__init__.mustache

Whitespace-only changes.

templates/python/__init__api.mustache

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

templates/python/__init__model.mustache

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

templates/python/api.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class {{classname}}:
103103
_query_params: List[Tuple[str, str]] = []
104104
_header_params: Dict[str, Optional[str]] = _headers or {}
105105
_form_params: List[Tuple[str, str]] = []
106-
_files: Dict[str, Union[str, bytes]] = {}
106+
_files: Dict[
107+
str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
108+
] = {}
107109
_body_params: Optional[bytes] = None
108110

109111
# process the path parameters
@@ -167,6 +169,9 @@ class {{classname}}:
167169
if isinstance({{paramName}}, str):
168170
with open({{paramName}}, "rb") as _fp:
169171
_body_params = _fp.read()
172+
elif isinstance({{paramName}}, tuple):
173+
# drop the filename from the tuple
174+
_body_params = {{paramName}}[1]
170175
else:
171176
_body_params = {{paramName}}
172177
{{/isBinary}}

templates/python/api_client.mustache

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ from {{packageName}}.exceptions import (
3232

3333
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
3434

35-
3635
class ApiClient:
3736
"""Generic API client for OpenAPI client library builds.
3837

@@ -394,12 +393,12 @@ class ApiClient:
394393
data = json.loads(response_text)
395394
except ValueError:
396395
data = response_text
397-
elif content_type.startswith("application/json"):
396+
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
398397
if response_text == "":
399398
data = ""
400399
else:
401400
data = json.loads(response_text)
402-
elif content_type.startswith("text/plain"):
401+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
403402
data = response_text
404403
else:
405404
raise ApiException(
@@ -507,7 +506,7 @@ class ApiClient:
507506
if k in collection_formats:
508507
collection_format = collection_formats[k]
509508
if collection_format == 'multi':
510-
new_params.extend((k, str(value)) for value in v)
509+
new_params.extend((k, quote(str(value))) for value in v)
511510
else:
512511
if collection_format == 'ssv':
513512
delimiter = ' '
@@ -525,7 +524,10 @@ class ApiClient:
525524

526525
return "&".join(["=".join(map(str, item)) for item in new_params])
527526

528-
def files_parameters(self, files: Dict[str, Union[str, bytes]]):
527+
def files_parameters(
528+
self,
529+
files: Dict[str, Union[str, bytes, List[str], List[bytes], Tuple[str, bytes]]],
530+
):
529531
"""Builds form parameters.
530532

531533
:param files: File parameters.
@@ -540,6 +542,12 @@ class ApiClient:
540542
elif isinstance(v, bytes):
541543
filename = k
542544
filedata = v
545+
elif isinstance(v, tuple):
546+
filename, filedata = v
547+
elif isinstance(v, list):
548+
for file_param in v:
549+
params.extend(self.files_parameters({k: file_param}))
550+
continue
543551
else:
544552
raise ValueError("Unsupported file value")
545553
mimetype = (

templates/python/api_doc.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ Method | HTTP request | Description
1313
# **{{{operationId}}}**
1414
> {{#returnType}}{{{.}}} {{/returnType}}{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{/required}}{{^required}}{{{paramName}}}={{{paramName}}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
1515

16-
{{{summary}}}{{#notes}}
16+
{{#summary}}
17+
{{{summary}}}
1718

18-
{{{.}}}{{/notes}}
19+
{{/summary}}
20+
{{#unescapedNotes}}
21+
{{{.}}}
1922

23+
{{/unescapedNotes}}
2024
### Example
2125

2226
{{#hasAuthMethods}}

templates/python/api_doc_example.mustache

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

templates/python/api_response.mustache

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

templates/python/api_test.mustache

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,31 @@ import unittest
77
from {{apiPackage}}.{{classFilename}} import {{classname}}
88

99

10-
class {{#operations}}Test{{classname}}(unittest.TestCase):
10+
class {{#operations}}Test{{classname}}(unittest.{{#asyncio}}IsolatedAsyncio{{/asyncio}}TestCase):
1111
"""{{classname}} unit test stubs"""
1212

13+
{{#asyncio}}
14+
async def asyncSetUp(self) -> None:
15+
self.api = {{classname}}()
16+
17+
async def asyncTearDown(self) -> None:
18+
await self.api.api_client.close()
19+
{{/asyncio}}
20+
{{^asyncio}}
1321
def setUp(self) -> None:
1422
self.api = {{classname}}()
1523

1624
def tearDown(self) -> None:
1725
pass
26+
{{/asyncio}}
1827

19-
{{#operation}}
28+
{{#operation}}
29+
{{#asyncio}}
30+
async def test_{{operationId}}(self) -> None:
31+
{{/asyncio}}
32+
{{^asyncio}}
2033
def test_{{operationId}}(self) -> None:
34+
{{/asyncio}}
2135
"""Test case for {{{operationId}}}
2236

2337
{{#summary}}

0 commit comments

Comments
 (0)