Skip to content

Commit 9dc9e54

Browse files
committed
Merge remote-tracking branch 'origin/master' into 5.0.x
2 parents b691d95 + deab7c8 commit 9dc9e54

18 files changed

Lines changed: 752 additions & 148 deletions

.generator/templates/README.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# {{{projectName}}}
2-
{{#appDescription}}
3-
{{{appDescription}}}
4-
{{/appDescription}}
2+
{{#appDescriptionWithNewLines}}
3+
{{{appDescriptionWithNewLines}}}
4+
{{/appDescriptionWithNewLines}}
55

66
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
77

.generator/templates/api_client.mustache

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{>partial_header}}
33
from __future__ import absolute_import
44

5+
import atexit
56
import datetime
67
from dateutil.parser import parse
78
import json
@@ -75,18 +76,27 @@ class ApiClient(object):
7576
self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/python{{/httpUserAgent}}'
7677
self.client_side_validation = configuration.client_side_validation
7778

78-
def __del__(self):
79+
def __enter__(self):
80+
return self
81+
82+
def __exit__(self, exc_type, exc_value, traceback):
83+
self.close()
84+
85+
def close(self):
7986
if self._pool:
8087
self._pool.close()
8188
self._pool.join()
8289
self._pool = None
90+
if hasattr(atexit, 'unregister'):
91+
atexit.unregister(self.close)
8392

8493
@property
8594
def pool(self):
8695
"""Create thread pool on first request
8796
avoids instantiating unused threadpool for blocking clients.
8897
"""
8998
if self._pool is None:
99+
atexit.register(self.close)
90100
self._pool = ThreadPool(self.pool_threads)
91101
return self._pool
92102

.generator/templates/api_doc.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Method | HTTP request | Description
2222
{{#hasAuthMethods}}
2323
{{#authMethods}}
2424
{{#isBasic}}
25-
{{^isBasicBearer}}
25+
{{#isBasicBasic}}
2626
* Basic Authentication ({{name}}):
27-
{{/isBasicBearer}}
27+
{{/isBasicBasic}}
2828
{{#isBasicBearer}}
2929
* Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} Authentication ({{name}}):
3030
{{/isBasicBearer}}

.generator/templates/api_doc_example.mustache

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ from pprint import pprint
88
{{#hasAuthMethods}}
99
# Defining host is optional and default to {{{basePath}}}
1010
configuration.host = "{{{basePath}}}"
11-
# Create an instance of the API class
12-
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
13-
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
14-
{{/allParams}}
11+
# Enter a context with an instance of the API client
12+
with {{{packageName}}}.ApiClient(configuration) as api_client:
13+
# Create an instance of the API class
14+
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
15+
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
16+
{{/allParams}}
1517
{{/hasAuthMethods}}
1618
{{^hasAuthMethods}}
17-
# Create an instance of the API class
18-
api_instance = {{{packageName}}}.{{{classname}}}()
19-
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
20-
{{/allParams}}
19+
# Enter a context with an instance of the API client
20+
with {{{packageName}}}.ApiClient() as api_client:
21+
# Create an instance of the API class
22+
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
23+
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
24+
{{/allParams}}
2125
{{/hasAuthMethods}}
2226

23-
try:
24-
{{#summary}} # {{{.}}}
25-
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
26-
pprint(api_response){{/returnType}}
27-
except ApiException as e:
28-
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
27+
try:
28+
{{#summary}} # {{{.}}}
29+
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
30+
pprint(api_response){{/returnType}}
31+
except ApiException as e:
32+
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
2933
```

.generator/templates/common_README.mustache

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ from pprint import pprint
88
{{> python_doc_auth_partial}}
99
# Defining host is optional and default to {{{basePath}}}
1010
configuration.host = "{{{basePath}}}"
11-
# Create an instance of the API class
12-
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
13-
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
14-
{{/allParams}}
11+
# Enter a context with an instance of the API client
12+
with {{{packageName}}}.ApiClient(configuration) as api_client:
13+
# Create an instance of the API class
14+
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
15+
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
16+
{{/allParams}}
1517

16-
try:
17-
{{#summary}} # {{{.}}}
18-
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
19-
pprint(api_response){{/returnType}}
20-
except ApiException as e:
21-
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
22-
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
18+
try:
19+
{{#summary}} # {{{.}}}
20+
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
21+
pprint(api_response){{/returnType}}
22+
except ApiException as e:
23+
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
24+
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
2325
```
2426

2527
## Documentation for API Endpoints
@@ -51,9 +53,9 @@ Class | Method | HTTP request | Description
5153
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
5254
{{/isApiKey}}
5355
{{#isBasic}}
54-
{{^isBasicBearer}}
56+
{{#isBasicBasic}}
5557
- **Type**: HTTP basic authentication
56-
{{/isBasicBearer}}
58+
{{/isBasicBasic}}
5759
{{#isBasicBearer}}
5860
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
5961
{{/isBasicBearer}}

.generator/templates/configuration.mustache

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ class Configuration(object):
3131
The dict value is an API key prefix when generating the auth data.
3232
:param username: Username for HTTP basic authentication
3333
:param password: Password for HTTP basic authentication
34+
{{#hasHttpSignatureMethods}}
35+
:param signing_info: Configuration parameters for the HTTP signature security scheme.
36+
Must be an instance of {{{packageName}}}.signing.HttpSigningConfiguration
37+
{{/hasHttpSignatureMethods}}
3438

39+
{{#hasAuthMethods}}
3540
:Example:
41+
{{#hasApiKeyMethods}}
3642

43+
API Key Authentication Example.
3744
Given the following security scheme in the OpenAPI specification:
3845
components:
3946
securitySchemes:
@@ -49,11 +56,74 @@ class Configuration(object):
4956
)
5057
The following cookie will be added to the HTTP request:
5158
Cookie: JSESSIONID abc123
59+
{{/hasApiKeyMethods}}
60+
{{#hasHttpBasicMethods}}
61+
62+
HTTP Basic Authentication Example.
63+
Given the following security scheme in the OpenAPI specification:
64+
components:
65+
securitySchemes:
66+
http_basic_auth:
67+
type: http
68+
scheme: basic
69+
70+
Configure API client with HTTP basic authentication:
71+
conf = {{{packageName}}}.Configuration(
72+
username='the-user',
73+
password='the-password',
74+
)
75+
{{/hasHttpBasicMethods}}
76+
{{#hasHttpSignatureMethods}}
77+
78+
HTTP Signature Authentication Example.
79+
Given the following security scheme in the OpenAPI specification:
80+
components:
81+
securitySchemes:
82+
http_basic_auth:
83+
type: http
84+
scheme: signature
85+
86+
Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme,
87+
sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time
88+
of the signature to 5 minutes after the signature has been created.
89+
Note you can use the constants defined in the {{{packageName}}}.signing module, and you can
90+
also specify arbitrary HTTP headers to be included in the HTTP signature, except for the
91+
'Authorization' header, which is used to carry the signature.
92+
93+
One may be tempted to sign all headers by default, but in practice it rarely works.
94+
This is beccause explicit proxies, transparent proxies, TLS termination endpoints or
95+
load balancers may add/modify/remove headers. Include the HTTP headers that you know
96+
are not going to be modified in transit.
97+
98+
conf = {{{packageName}}}.Configuration(
99+
signing_info = {{{packageName}}}.signing.HttpSigningConfiguration(
100+
key_id = 'my-key-id',
101+
private_key_path = 'rsa.pem',
102+
signing_scheme = signing.SCHEME_HS2019,
103+
signing_algorithm = signing.ALGORITHM_RSASSA_PSS,
104+
signed_headers = [signing.HEADER_REQUEST_TARGET,
105+
signing.HEADER_CREATED,
106+
signing.HEADER_EXPIRES,
107+
signing.HEADER_HOST,
108+
signing.HEADER_DATE,
109+
signing.HEADER_DIGEST,
110+
'Content-Type',
111+
'User-Agent'
112+
],
113+
signature_max_validity = datetime.timedelta(minutes=5)
114+
)
115+
)
116+
{{/hasHttpSignatureMethods}}
117+
{{/hasAuthMethods}}
52118
"""
53119

54120
def __init__(self, host="{{{basePath}}}",
55121
api_key=None, api_key_prefix=None,
56-
username=None, password=None):
122+
username=None, password=None,
123+
{{#hasHttpSignatureMethods}}
124+
signing_info=None,
125+
{{/hasHttpSignatureMethods}}
126+
):
57127
"""Constructor
58128
"""
59129
self.host = host
@@ -82,14 +152,21 @@ class Configuration(object):
82152
self.password = password
83153
"""Password for HTTP basic authentication
84154
"""
155+
{{#hasHttpSignatureMethods}}
156+
if signing_info is not None:
157+
signing_info.host = host
158+
self.signing_info = signing_info
159+
"""The HTTP signing configuration
160+
"""
161+
{{/hasHttpSignatureMethods}}
85162
{{#hasOAuthMethods}}
86-
self.access_token = ""
163+
self.access_token = None
87164
"""access token for OAuth/Bearer
88165
"""
89166
{{/hasOAuthMethods}}
90167
{{^hasOAuthMethods}}
91168
{{#hasBearerMethods}}
92-
self.access_token = ""
169+
self.access_token = None
93170
"""access token for OAuth/Bearer
94171
"""
95172
{{/hasBearerMethods}}
@@ -297,15 +374,15 @@ class Configuration(object):
297374
}
298375
{{/isApiKey}}
299376
{{#isBasic}}
300-
{{^isBasicBearer}}
377+
{{#isBasicBasic}}
301378
if self.username is not None and self.password is not None:
302379
auth['{{name}}'] = {
303380
'type': 'basic',
304381
'in': 'header',
305382
'key': 'Authorization',
306383
'value': self.get_basic_auth_token()
307384
}
308-
{{/isBasicBearer}}
385+
{{/isBasicBasic}}
309386
{{#isBasicBearer}}
310387
if self.access_token is not None:
311388
auth['{{name}}'] = {
@@ -318,6 +395,15 @@ class Configuration(object):
318395
'value': 'Bearer ' + self.access_token
319396
}
320397
{{/isBasicBearer}}
398+
{{#isHttpSignature}}
399+
if self.signing_info is not None:
400+
auth['{{name}}'] = {
401+
'type': 'http-signature',
402+
'in': 'header',
403+
'key': 'Authorization',
404+
'value': None # Signature headers are calculated for every HTTP request
405+
}
406+
{{/isHttpSignature}}
321407
{{/isBasic}}
322408
{{#isOAuth}}
323409
if self.access_token is not None:

.generator/templates/model_test.mustache

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from __future__ import absolute_import
66

77
import unittest
8+
import datetime
89

910
{{#models}}
1011
{{#model}}
1112
import {{packageName}}
1213
from {{modelPackage}}.{{classFilename}} import {{classname}} # noqa: E501
1314
from {{packageName}}.rest import ApiException
1415

15-
1616
class Test{{classname}}(unittest.TestCase):
1717
"""{{classname}} unit test stubs"""
1818

@@ -22,11 +22,31 @@ class Test{{classname}}(unittest.TestCase):
2222
def tearDown(self):
2323
pass
2424

25+
def make_instance(self, include_optional):
26+
"""Test {{classname}}
27+
include_option is a boolean, when False only required
28+
params are included, when True both required and
29+
optional params are included """
30+
# model = {{packageName}}.models.{{classFilename}}.{{classname}}() # noqa: E501
31+
if include_optional :
32+
return {{classname}}(
33+
{{#vars}}
34+
{{name}} = {{#example}}{{{.}}}{{/example}}{{^example}}None{{/example}}{{#hasMore}}, {{/hasMore}}
35+
{{/vars}}
36+
)
37+
else :
38+
return {{classname}}(
39+
{{#vars}}
40+
{{#required}}
41+
{{name}} = {{#example}}{{{.}}}{{/example}}{{^example}}None{{/example}},
42+
{{/required}}
43+
{{/vars}}
44+
)
45+
2546
def test{{classname}}(self):
2647
"""Test {{classname}}"""
27-
# FIXME: construct object with mandatory attributes with example values
28-
# model = {{packageName}}.models.{{classFilename}}.{{classname}}() # noqa: E501
29-
pass
48+
inst_req_only = self.make_instance(include_optional=False)
49+
inst_req_and_optional = self.make_instance(include_optional=True)
3050

3151
{{/model}}
3252
{{/models}}

.generator/templates/python-experimental/README.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# {{{projectName}}}
2-
{{#appDescription}}
3-
{{{appDescription}}}
4-
{{/appDescription}}
2+
{{#appDescriptionWithNewLines}}
3+
{{{appDescriptionWithNewLines}}}
4+
{{/appDescriptionWithNewLines}}
55

66
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
77

0 commit comments

Comments
 (0)