From 8a11dbe2bf2cfb7a13cb9448298139e028a05ce5 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 10 Oct 2022 11:15:58 -0700 Subject: [PATCH 1/4] Updates requiremnts --- .../python/required_libraries.handlebars | 16 ++++++++++++++++ .../resources/python/requirements.handlebars | 6 +----- .../src/main/resources/python/setup.handlebars | 16 +--------------- .../3_0_3_unit_test/python/requirements.txt | 11 ++++++----- .../client/3_0_3_unit_test/python/setup.py | 11 ++++++----- .../python/requirements.txt | 11 ++++++----- .../python/setup.py | 11 ++++++----- .../client/petstore/python/requirements.txt | 13 ++++++++----- samples/openapi3/client/petstore/python/setup.py | 15 ++++++++------- 9 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars new file mode 100644 index 00000000000..2f48c0d4c05 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars @@ -0,0 +1,16 @@ +{{#if asyncio}} +{{#if quoted}}"{{/if}}aiohttp ~= 3.0.0{{#if quoted}}",{{/if}} +{{/if}} +{{#if quoted}}"{{/if}}certifi ~= 14.5.14{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}frozendict ~= 2.3.4{{#if quoted}}",{{/if}} +{{#if hasHttpSignatureMethods}} +{{#if quoted}}"{{/if}}pem ~= 19.3.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}pycryptodome ~= 3.9.0{{#if quoted}}",{{/if}} +{{/if}} +{{#if quoted}}"{{/if}}python-dateutil ~= 2.7.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}setuptools ~= 21.0.0{{#if quoted}}",{{/if}} +{{#if tornado}} +{{#if quoted}}"{{/if}}tornado ~= 4.2{{#if quoted}}",{{/if}} +{{/if}} +{{#if quoted}}"{{/if}}typing_extensions ~= 4.3.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}urllib3 ~= 1.26.12{{#if quoted}}",{{/if}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/requirements.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/requirements.handlebars index c9227e58a1b..b1f24de150a 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/requirements.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/requirements.handlebars @@ -1,5 +1 @@ -certifi >= 14.05.14 -frozendict >= 2.0.3 -python_dateutil >= 2.5.3 -setuptools >= 21.0.0 -urllib3 >= 1.15.1 +{{> required_libraries quoted=false }} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/setup.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/setup.handlebars index a346b23cb61..5cb64ff1e61 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/setup.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/setup.handlebars @@ -15,21 +15,7 @@ VERSION = "{{packageVersion}}" # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "urllib3 >= 1.15", - "certifi", - "python-dateutil", - "frozendict >= 2.0.3", -{{#if asyncio}} - "aiohttp >= 3.0.0", -{{/if}} -{{#if tornado}} - "tornado>=4.2,<5", -{{/if}} -{{#if hasHttpSignatureMethods}} - "pem>=19.3.0", - "pycryptodome>=3.9.0", -{{/if}} - "typing_extensions", + {{> required_libraries quoted=true }} ] setup( diff --git a/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt b/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt index c9227e58a1b..4769c7fb6fa 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt +++ b/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt @@ -1,5 +1,6 @@ -certifi >= 14.05.14 -frozendict >= 2.0.3 -python_dateutil >= 2.5.3 -setuptools >= 21.0.0 -urllib3 >= 1.15.1 +certifi ~= 14.5.14 +frozendict ~= 2.3.4 +python-dateutil ~= 2.7.0 +setuptools ~= 21.0.0 +typing_extensions ~= 4.3.0 +urllib3 ~= 1.26.12 diff --git a/samples/openapi3/client/3_0_3_unit_test/python/setup.py b/samples/openapi3/client/3_0_3_unit_test/python/setup.py index 5f2ac30e9fd..5b652f284f5 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/setup.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/setup.py @@ -21,11 +21,12 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "urllib3 >= 1.15", - "certifi", - "python-dateutil", - "frozendict >= 2.0.3", - "typing_extensions", + "certifi ~= 14.5.14", + "frozendict ~= 2.3.4", + "python-dateutil ~= 2.7.0", + "setuptools ~= 21.0.0", + "typing_extensions ~= 4.3.0", + "urllib3 ~= 1.26.12", ] setup( diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt index c9227e58a1b..4769c7fb6fa 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt @@ -1,5 +1,6 @@ -certifi >= 14.05.14 -frozendict >= 2.0.3 -python_dateutil >= 2.5.3 -setuptools >= 21.0.0 -urllib3 >= 1.15.1 +certifi ~= 14.5.14 +frozendict ~= 2.3.4 +python-dateutil ~= 2.7.0 +setuptools ~= 21.0.0 +typing_extensions ~= 4.3.0 +urllib3 ~= 1.26.12 diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py index 552e92cc277..fbb7f8de0eb 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py @@ -21,11 +21,12 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "urllib3 >= 1.15", - "certifi", - "python-dateutil", - "frozendict >= 2.0.3", - "typing_extensions", + "certifi ~= 14.5.14", + "frozendict ~= 2.3.4", + "python-dateutil ~= 2.7.0", + "setuptools ~= 21.0.0", + "typing_extensions ~= 4.3.0", + "urllib3 ~= 1.26.12", ] setup( diff --git a/samples/openapi3/client/petstore/python/requirements.txt b/samples/openapi3/client/petstore/python/requirements.txt index c9227e58a1b..feb0eb8372e 100644 --- a/samples/openapi3/client/petstore/python/requirements.txt +++ b/samples/openapi3/client/petstore/python/requirements.txt @@ -1,5 +1,8 @@ -certifi >= 14.05.14 -frozendict >= 2.0.3 -python_dateutil >= 2.5.3 -setuptools >= 21.0.0 -urllib3 >= 1.15.1 +certifi ~= 14.5.14 +frozendict ~= 2.3.4 +pem ~= 19.3.0 +pycryptodome ~= 3.9.0 +python-dateutil ~= 2.7.0 +setuptools ~= 21.0.0 +typing_extensions ~= 4.3.0 +urllib3 ~= 1.26.12 diff --git a/samples/openapi3/client/petstore/python/setup.py b/samples/openapi3/client/petstore/python/setup.py index 2acc6c1cf2b..bffb784a169 100644 --- a/samples/openapi3/client/petstore/python/setup.py +++ b/samples/openapi3/client/petstore/python/setup.py @@ -21,13 +21,14 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "urllib3 >= 1.15", - "certifi", - "python-dateutil", - "frozendict >= 2.0.3", - "pem>=19.3.0", - "pycryptodome>=3.9.0", - "typing_extensions", + "certifi ~= 14.5.14", + "frozendict ~= 2.3.4", + "pem ~= 19.3.0", + "pycryptodome ~= 3.9.0", + "python-dateutil ~= 2.7.0", + "setuptools ~= 21.0.0", + "typing_extensions ~= 4.3.0", + "urllib3 ~= 1.26.12", ] setup( From 688c7aa12015b283afc75914aa729ff45d854aab Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 10 Oct 2022 11:35:33 -0700 Subject: [PATCH 2/4] Samples updated --- .../resources/python/required_libraries.handlebars | 14 +++++++------- .../client/3_0_3_unit_test/python/requirements.txt | 6 +++--- .../client/3_0_3_unit_test/python/setup.py | 6 +++--- .../python/requirements.txt | 6 +++--- .../python/setup.py | 6 +++--- .../client/petstore/python/requirements.txt | 10 +++++----- samples/openapi3/client/petstore/python/setup.py | 10 +++++----- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars index 2f48c0d4c05..f8395307a86 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/required_libraries.handlebars @@ -1,16 +1,16 @@ {{#if asyncio}} -{{#if quoted}}"{{/if}}aiohttp ~= 3.0.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}aiohttp >= 3.0.0{{#if quoted}}",{{/if}} {{/if}} -{{#if quoted}}"{{/if}}certifi ~= 14.5.14{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}certifi >= 14.5.14{{#if quoted}}",{{/if}} {{#if quoted}}"{{/if}}frozendict ~= 2.3.4{{#if quoted}}",{{/if}} {{#if hasHttpSignatureMethods}} -{{#if quoted}}"{{/if}}pem ~= 19.3.0{{#if quoted}}",{{/if}} -{{#if quoted}}"{{/if}}pycryptodome ~= 3.9.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}pem >= 19.3.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}pycryptodome >= 3.9.0{{#if quoted}}",{{/if}} {{/if}} {{#if quoted}}"{{/if}}python-dateutil ~= 2.7.0{{#if quoted}}",{{/if}} -{{#if quoted}}"{{/if}}setuptools ~= 21.0.0{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}setuptools >= 21.0.0{{#if quoted}}",{{/if}} {{#if tornado}} -{{#if quoted}}"{{/if}}tornado ~= 4.2{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}tornado >= 4.2{{#if quoted}}",{{/if}} {{/if}} {{#if quoted}}"{{/if}}typing_extensions ~= 4.3.0{{#if quoted}}",{{/if}} -{{#if quoted}}"{{/if}}urllib3 ~= 1.26.12{{#if quoted}}",{{/if}} +{{#if quoted}}"{{/if}}urllib3 ~= 1.26.7{{#if quoted}}",{{/if}} diff --git a/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt b/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt index 4769c7fb6fa..3cb6612669d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt +++ b/samples/openapi3/client/3_0_3_unit_test/python/requirements.txt @@ -1,6 +1,6 @@ -certifi ~= 14.5.14 +certifi >= 14.5.14 frozendict ~= 2.3.4 python-dateutil ~= 2.7.0 -setuptools ~= 21.0.0 +setuptools >= 21.0.0 typing_extensions ~= 4.3.0 -urllib3 ~= 1.26.12 +urllib3 ~= 1.26.7 diff --git a/samples/openapi3/client/3_0_3_unit_test/python/setup.py b/samples/openapi3/client/3_0_3_unit_test/python/setup.py index 5b652f284f5..1fc837120cf 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/setup.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/setup.py @@ -21,12 +21,12 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "certifi ~= 14.5.14", + "certifi >= 14.5.14", "frozendict ~= 2.3.4", "python-dateutil ~= 2.7.0", - "setuptools ~= 21.0.0", + "setuptools >= 21.0.0", "typing_extensions ~= 4.3.0", - "urllib3 ~= 1.26.12", + "urllib3 ~= 1.26.7", ] setup( diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt index 4769c7fb6fa..3cb6612669d 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/requirements.txt @@ -1,6 +1,6 @@ -certifi ~= 14.5.14 +certifi >= 14.5.14 frozendict ~= 2.3.4 python-dateutil ~= 2.7.0 -setuptools ~= 21.0.0 +setuptools >= 21.0.0 typing_extensions ~= 4.3.0 -urllib3 ~= 1.26.12 +urllib3 ~= 1.26.7 diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py index fbb7f8de0eb..4356510d67a 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/setup.py @@ -21,12 +21,12 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "certifi ~= 14.5.14", + "certifi >= 14.5.14", "frozendict ~= 2.3.4", "python-dateutil ~= 2.7.0", - "setuptools ~= 21.0.0", + "setuptools >= 21.0.0", "typing_extensions ~= 4.3.0", - "urllib3 ~= 1.26.12", + "urllib3 ~= 1.26.7", ] setup( diff --git a/samples/openapi3/client/petstore/python/requirements.txt b/samples/openapi3/client/petstore/python/requirements.txt index feb0eb8372e..342f6630cb7 100644 --- a/samples/openapi3/client/petstore/python/requirements.txt +++ b/samples/openapi3/client/petstore/python/requirements.txt @@ -1,8 +1,8 @@ -certifi ~= 14.5.14 +certifi >= 14.5.14 frozendict ~= 2.3.4 -pem ~= 19.3.0 -pycryptodome ~= 3.9.0 +pem >= 19.3.0 +pycryptodome >= 3.9.0 python-dateutil ~= 2.7.0 -setuptools ~= 21.0.0 +setuptools >= 21.0.0 typing_extensions ~= 4.3.0 -urllib3 ~= 1.26.12 +urllib3 ~= 1.26.7 diff --git a/samples/openapi3/client/petstore/python/setup.py b/samples/openapi3/client/petstore/python/setup.py index bffb784a169..992aa9853b7 100644 --- a/samples/openapi3/client/petstore/python/setup.py +++ b/samples/openapi3/client/petstore/python/setup.py @@ -21,14 +21,14 @@ # http://pypi.python.org/pypi/setuptools REQUIRES = [ - "certifi ~= 14.5.14", + "certifi >= 14.5.14", "frozendict ~= 2.3.4", - "pem ~= 19.3.0", - "pycryptodome ~= 3.9.0", + "pem >= 19.3.0", + "pycryptodome >= 3.9.0", "python-dateutil ~= 2.7.0", - "setuptools ~= 21.0.0", + "setuptools >= 21.0.0", "typing_extensions ~= 4.3.0", - "urllib3 ~= 1.26.12", + "urllib3 ~= 1.26.7", ] setup( From b8f9e0155f93ef629e5eba6bc5d10b4a290d195c Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 10 Oct 2022 11:51:38 -0700 Subject: [PATCH 3/4] Samples regenerated --- .../src/main/resources/python/api_client.handlebars | 9 +++++---- .../3_0_3_unit_test/python/unit_test_api/api_client.py | 9 +++++---- .../python/this_package/api_client.py | 9 +++++---- .../client/petstore/python/petstore_api/api_client.py | 9 +++++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars index d8f31abf6a5..d081b34bbc4 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars @@ -994,7 +994,7 @@ class ApiClient: self.pool_threads = pool_threads self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + self.default_headers = HTTPHeaderDict() if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie @@ -1054,8 +1054,9 @@ class ApiClient: ) -> urllib3.HTTPResponse: # header parameters - headers = headers or HTTPHeaderDict() - headers.update(self.default_headers) + used_headers = HTTPHeaderDict(self.default_headers) + if headers: + used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie @@ -1074,7 +1075,7 @@ class ApiClient: response = {{#if asyncio}}await {{/if}}{{#if tornado}}yield {{/if}}self.request( method, url, - headers=headers, + headers=used_headers, fields=fields, body=body, stream=stream, diff --git a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py index 95f6bdcf986..20a79211027 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py @@ -998,7 +998,7 @@ def __init__( self.pool_threads = pool_threads self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + self.default_headers = HTTPHeaderDict() if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie @@ -1055,8 +1055,9 @@ def __call_api( ) -> urllib3.HTTPResponse: # header parameters - headers = headers or HTTPHeaderDict() - headers.update(self.default_headers) + used_headers = HTTPHeaderDict(self.default_headers) + if headers: + used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie @@ -1075,7 +1076,7 @@ def __call_api( response = self.request( method, url, - headers=headers, + headers=used_headers, fields=fields, body=body, stream=stream, diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py index 0a7cb973a3d..5ce8bde3068 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py @@ -998,7 +998,7 @@ def __init__( self.pool_threads = pool_threads self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + self.default_headers = HTTPHeaderDict() if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie @@ -1055,8 +1055,9 @@ def __call_api( ) -> urllib3.HTTPResponse: # header parameters - headers = headers or HTTPHeaderDict() - headers.update(self.default_headers) + used_headers = HTTPHeaderDict(self.default_headers) + if headers: + used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie @@ -1075,7 +1076,7 @@ def __call_api( response = self.request( method, url, - headers=headers, + headers=used_headers, fields=fields, body=body, stream=stream, diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index 7a8cd8c482f..836abbb84d8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -998,7 +998,7 @@ def __init__( self.pool_threads = pool_threads self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + self.default_headers = HTTPHeaderDict() if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie @@ -1055,8 +1055,9 @@ def __call_api( ) -> urllib3.HTTPResponse: # header parameters - headers = headers or HTTPHeaderDict() - headers.update(self.default_headers) + used_headers = HTTPHeaderDict(self.default_headers) + if headers: + used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie @@ -1075,7 +1076,7 @@ def __call_api( response = self.request( method, url, - headers=headers, + headers=used_headers, fields=fields, body=body, stream=stream, From 95e24de09ec731a0d2aa093187c66969ca2089e9 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 10 Oct 2022 13:00:24 -0700 Subject: [PATCH 4/4] Adds test_passed_in_header_overrides_default + test_default_header_used_when_no_header_params_input --- .../resources/python/api_client.handlebars | 8 +- .../python/unit_test_api/api_client.py | 8 +- .../python/this_package/api_client.py | 8 +- .../python/petstore_api/api_client.py | 8 +- .../test_paths/test_fake/__init__.py | 0 .../test_paths/test_fake/test_get.py | 73 +++++++++++++++++++ 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/__init__.py create mode 100644 samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_get.py diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars index d081b34bbc4..bdcd4519ff4 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars @@ -1055,15 +1055,17 @@ class ApiClient: # header parameters used_headers = HTTPHeaderDict(self.default_headers) - if headers: - used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie # auth setting - self.update_params_for_auth(headers, + self.update_params_for_auth(used_headers, auth_settings, resource_path, method, body) + # must happen after cookie setting and auth setting in case user is overriding those + if headers: + used_headers.update(headers) + # request url if host is None: url = self.configuration.host + resource_path diff --git a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py index 20a79211027..dfbf6822aa2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/api_client.py @@ -1056,15 +1056,17 @@ def __call_api( # header parameters used_headers = HTTPHeaderDict(self.default_headers) - if headers: - used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie # auth setting - self.update_params_for_auth(headers, + self.update_params_for_auth(used_headers, auth_settings, resource_path, method, body) + # must happen after cookie setting and auth setting in case user is overriding those + if headers: + used_headers.update(headers) + # request url if host is None: url = self.configuration.host + resource_path diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py index 5ce8bde3068..385e43821b8 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/api_client.py @@ -1056,15 +1056,17 @@ def __call_api( # header parameters used_headers = HTTPHeaderDict(self.default_headers) - if headers: - used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie # auth setting - self.update_params_for_auth(headers, + self.update_params_for_auth(used_headers, auth_settings, resource_path, method, body) + # must happen after cookie setting and auth setting in case user is overriding those + if headers: + used_headers.update(headers) + # request url if host is None: url = self.configuration.host + resource_path diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index 836abbb84d8..d1b93ab5a68 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -1056,15 +1056,17 @@ def __call_api( # header parameters used_headers = HTTPHeaderDict(self.default_headers) - if headers: - used_headers.extend(headers) if self.cookie: headers['Cookie'] = self.cookie # auth setting - self.update_params_for_auth(headers, + self.update_params_for_auth(used_headers, auth_settings, resource_path, method, body) + # must happen after cookie setting and auth setting in case user is overriding those + if headers: + used_headers.update(headers) + # request url if host is None: url = self.configuration.host + resource_path diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/__init__.py b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_get.py b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_get.py new file mode 100644 index 00000000000..042fe206c44 --- /dev/null +++ b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_get.py @@ -0,0 +1,73 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +import unittest +from unittest.mock import patch + +import urllib3 + +import petstore_api +from petstore_api.paths.fake import get # noqa: E501 +from petstore_api import configuration, schemas, api_client + +from ... import ApiTestMixin + + +class TestFake(ApiTestMixin, unittest.TestCase): + """ + Fake unit test stubs + To test enum parameters # noqa: E501 + """ + used_api_client = api_client.ApiClient( + header_name='enum_header_string', + header_value='_abc' + ) + api = get.ApiForget(api_client=used_api_client) + + @patch.object(urllib3.PoolManager, 'request') + def test_passed_in_header_overrides_default(self, mock_request): + mock_request.return_value = self.response(b'') + + api_response = self.api.get(header_params={'enum_header_string': '-efg'}) + self.assert_pool_manager_request_called_with( + mock_request, + f'http://petstore.swagger.io:80/v2/fake', + body=None, + method='GET', + content_type=None, + accept_content_type=None, + headers={'enum_header_string': '-efg'} + ) + + assert isinstance(api_response.response, urllib3.HTTPResponse) + assert isinstance(api_response.body, schemas.Unset) + assert isinstance(api_response.headers, schemas.Unset) + assert api_response.response.status == 200 + + @patch.object(urllib3.PoolManager, 'request') + def test_default_header_used_when_no_header_params_input(self, mock_request): + mock_request.return_value = self.response(b'') + + api_response = self.api.get() + self.assert_pool_manager_request_called_with( + mock_request, + f'http://petstore.swagger.io:80/v2/fake', + body=None, + method='GET', + content_type=None, + accept_content_type=None, + headers={'enum_header_string': '_abc'} + ) + + assert isinstance(api_response.response, urllib3.HTTPResponse) + assert isinstance(api_response.body, schemas.Unset) + assert isinstance(api_response.headers, schemas.Unset) + assert api_response.response.status == 200 + +if __name__ == '__main__': + unittest.main()