diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index 71392d82e126..f742cffb87c8 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -840,11 +840,8 @@ https://github.com/OpenAPITools/openapi-generator/blob/c84b949df1a9ec04ba75989cb headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py index 594ec0e5a703..237696870257 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py @@ -683,11 +683,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/client/echo_api/python/openapi_client/api_client.py b/samples/client/echo_api/python/openapi_client/api_client.py index 594ec0e5a703..237696870257 100644 --- a/samples/client/echo_api/python/openapi_client/api_client.py +++ b/samples/client/echo_api/python/openapi_client/api_client.py @@ -683,11 +683,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py b/samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py index 37ab9efc5d92..97d4d8f203ef 100644 --- a/samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py +++ b/samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py @@ -791,11 +791,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py index f90151f6105b..f37d3564026a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py @@ -682,11 +682,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py index 5fb082d86bc9..a82e242f5afe 100644 --- a/samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py @@ -685,11 +685,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py index 5fb082d86bc9..a82e242f5afe 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py @@ -685,11 +685,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py index a26ad3c644a2..21489d50fb24 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py @@ -682,11 +682,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature': 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 4a91fbc24248..03370346fde2 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -682,11 +682,8 @@ def _apply_auth_params( headers['Cookie'] = "" else: headers['Cookie'] += "; " - # Account for cookie value containing spaces and special characters - cookie_value = str(auth_setting['value']) - if not re.match("^\".*\"$", cookie_value): - cookie_value = cookie_value.replace("\"", "\\\"") - cookie_value = f"\"{cookie_value}\"" + # Account for cookie value containing spaces and special characters, excluding base64 delimiters + cookie_value = quote(str(auth_setting['value']), safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" elif auth_setting['in'] == 'header': if auth_setting['type'] != 'http-signature':