Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 90b32e1

Browse files
authored
Merge pull request #37 from openapi-json-schema-tools/fixes_headers_and_requirements
Fixes requirements.txt, applies default headers before header params
2 parents d3f89b7 + 95e24de commit 90b32e1

File tree

15 files changed

+160
-69
lines changed

15 files changed

+160
-69
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ class ApiClient:
994994
self.pool_threads = pool_threads
995995

996996
self.rest_client = rest.RESTClientObject(configuration)
997-
self.default_headers = {}
997+
self.default_headers = HTTPHeaderDict()
998998
if header_name is not None:
999999
self.default_headers[header_name] = header_value
10001000
self.cookie = cookie
@@ -1054,15 +1054,18 @@ class ApiClient:
10541054
) -> urllib3.HTTPResponse:
10551055

10561056
# header parameters
1057-
headers = headers or HTTPHeaderDict()
1058-
headers.update(self.default_headers)
1057+
used_headers = HTTPHeaderDict(self.default_headers)
10591058
if self.cookie:
10601059
headers['Cookie'] = self.cookie
10611060

10621061
# auth setting
1063-
self.update_params_for_auth(headers,
1062+
self.update_params_for_auth(used_headers,
10641063
auth_settings, resource_path, method, body)
10651064

1065+
# must happen after cookie setting and auth setting in case user is overriding those
1066+
if headers:
1067+
used_headers.update(headers)
1068+
10661069
# request url
10671070
if host is None:
10681071
url = self.configuration.host + resource_path
@@ -1074,7 +1077,7 @@ class ApiClient:
10741077
response = {{#if asyncio}}await {{/if}}{{#if tornado}}yield {{/if}}self.request(
10751078
method,
10761079
url,
1077-
headers=headers,
1080+
headers=used_headers,
10781081
fields=fields,
10791082
body=body,
10801083
stream=stream,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{#if asyncio}}
2+
{{#if quoted}}"{{/if}}aiohttp >= 3.0.0{{#if quoted}}",{{/if}}
3+
{{/if}}
4+
{{#if quoted}}"{{/if}}certifi >= 14.5.14{{#if quoted}}",{{/if}}
5+
{{#if quoted}}"{{/if}}frozendict ~= 2.3.4{{#if quoted}}",{{/if}}
6+
{{#if hasHttpSignatureMethods}}
7+
{{#if quoted}}"{{/if}}pem >= 19.3.0{{#if quoted}}",{{/if}}
8+
{{#if quoted}}"{{/if}}pycryptodome >= 3.9.0{{#if quoted}}",{{/if}}
9+
{{/if}}
10+
{{#if quoted}}"{{/if}}python-dateutil ~= 2.7.0{{#if quoted}}",{{/if}}
11+
{{#if quoted}}"{{/if}}setuptools >= 21.0.0{{#if quoted}}",{{/if}}
12+
{{#if tornado}}
13+
{{#if quoted}}"{{/if}}tornado >= 4.2{{#if quoted}}",{{/if}}
14+
{{/if}}
15+
{{#if quoted}}"{{/if}}typing_extensions ~= 4.3.0{{#if quoted}}",{{/if}}
16+
{{#if quoted}}"{{/if}}urllib3 ~= 1.26.7{{#if quoted}}",{{/if}}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
certifi >= 14.05.14
2-
frozendict >= 2.0.3
3-
python_dateutil >= 2.5.3
4-
setuptools >= 21.0.0
5-
urllib3 >= 1.15.1
1+
{{> required_libraries quoted=false }}

modules/openapi-json-schema-generator/src/main/resources/python/setup.handlebars

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,7 @@ VERSION = "{{packageVersion}}"
1515
# http://pypi.python.org/pypi/setuptools
1616

1717
REQUIRES = [
18-
"urllib3 >= 1.15",
19-
"certifi",
20-
"python-dateutil",
21-
"frozendict >= 2.0.3",
22-
{{#if asyncio}}
23-
"aiohttp >= 3.0.0",
24-
{{/if}}
25-
{{#if tornado}}
26-
"tornado>=4.2,<5",
27-
{{/if}}
28-
{{#if hasHttpSignatureMethods}}
29-
"pem>=19.3.0",
30-
"pycryptodome>=3.9.0",
31-
{{/if}}
32-
"typing_extensions",
18+
{{> required_libraries quoted=true }}
3319
]
3420

3521
setup(
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
certifi >= 14.05.14
2-
frozendict >= 2.0.3
3-
python_dateutil >= 2.5.3
1+
certifi >= 14.5.14
2+
frozendict ~= 2.3.4
3+
python-dateutil ~= 2.7.0
44
setuptools >= 21.0.0
5-
urllib3 >= 1.15.1
5+
typing_extensions ~= 4.3.0
6+
urllib3 ~= 1.26.7

samples/openapi3/client/3_0_3_unit_test/python/setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
# http://pypi.python.org/pypi/setuptools
2222

2323
REQUIRES = [
24-
"urllib3 >= 1.15",
25-
"certifi",
26-
"python-dateutil",
27-
"frozendict >= 2.0.3",
28-
"typing_extensions",
24+
"certifi >= 14.5.14",
25+
"frozendict ~= 2.3.4",
26+
"python-dateutil ~= 2.7.0",
27+
"setuptools >= 21.0.0",
28+
"typing_extensions ~= 4.3.0",
29+
"urllib3 ~= 1.26.7",
2930
]
3031

3132
setup(

samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def __init__(
998998
self.pool_threads = pool_threads
999999

10001000
self.rest_client = rest.RESTClientObject(configuration)
1001-
self.default_headers = {}
1001+
self.default_headers = HTTPHeaderDict()
10021002
if header_name is not None:
10031003
self.default_headers[header_name] = header_value
10041004
self.cookie = cookie
@@ -1055,15 +1055,18 @@ def __call_api(
10551055
) -> urllib3.HTTPResponse:
10561056

10571057
# header parameters
1058-
headers = headers or HTTPHeaderDict()
1059-
headers.update(self.default_headers)
1058+
used_headers = HTTPHeaderDict(self.default_headers)
10601059
if self.cookie:
10611060
headers['Cookie'] = self.cookie
10621061

10631062
# auth setting
1064-
self.update_params_for_auth(headers,
1063+
self.update_params_for_auth(used_headers,
10651064
auth_settings, resource_path, method, body)
10661065

1066+
# must happen after cookie setting and auth setting in case user is overriding those
1067+
if headers:
1068+
used_headers.update(headers)
1069+
10671070
# request url
10681071
if host is None:
10691072
url = self.configuration.host + resource_path
@@ -1075,7 +1078,7 @@ def __call_api(
10751078
response = self.request(
10761079
method,
10771080
url,
1078-
headers=headers,
1081+
headers=used_headers,
10791082
fields=fields,
10801083
body=body,
10811084
stream=stream,
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
certifi >= 14.05.14
2-
frozendict >= 2.0.3
3-
python_dateutil >= 2.5.3
1+
certifi >= 14.5.14
2+
frozendict ~= 2.3.4
3+
python-dateutil ~= 2.7.0
44
setuptools >= 21.0.0
5-
urllib3 >= 1.15.1
5+
typing_extensions ~= 4.3.0
6+
urllib3 ~= 1.26.7

samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
# http://pypi.python.org/pypi/setuptools
2222

2323
REQUIRES = [
24-
"urllib3 >= 1.15",
25-
"certifi",
26-
"python-dateutil",
27-
"frozendict >= 2.0.3",
28-
"typing_extensions",
24+
"certifi >= 14.5.14",
25+
"frozendict ~= 2.3.4",
26+
"python-dateutil ~= 2.7.0",
27+
"setuptools >= 21.0.0",
28+
"typing_extensions ~= 4.3.0",
29+
"urllib3 ~= 1.26.7",
2930
]
3031

3132
setup(

samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def __init__(
998998
self.pool_threads = pool_threads
999999

10001000
self.rest_client = rest.RESTClientObject(configuration)
1001-
self.default_headers = {}
1001+
self.default_headers = HTTPHeaderDict()
10021002
if header_name is not None:
10031003
self.default_headers[header_name] = header_value
10041004
self.cookie = cookie
@@ -1055,15 +1055,18 @@ def __call_api(
10551055
) -> urllib3.HTTPResponse:
10561056

10571057
# header parameters
1058-
headers = headers or HTTPHeaderDict()
1059-
headers.update(self.default_headers)
1058+
used_headers = HTTPHeaderDict(self.default_headers)
10601059
if self.cookie:
10611060
headers['Cookie'] = self.cookie
10621061

10631062
# auth setting
1064-
self.update_params_for_auth(headers,
1063+
self.update_params_for_auth(used_headers,
10651064
auth_settings, resource_path, method, body)
10661065

1066+
# must happen after cookie setting and auth setting in case user is overriding those
1067+
if headers:
1068+
used_headers.update(headers)
1069+
10671070
# request url
10681071
if host is None:
10691072
url = self.configuration.host + resource_path
@@ -1075,7 +1078,7 @@ def __call_api(
10751078
response = self.request(
10761079
method,
10771080
url,
1078-
headers=headers,
1081+
headers=used_headers,
10791082
fields=fields,
10801083
body=body,
10811084
stream=stream,

0 commit comments

Comments
 (0)