mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 10:07:08 +00:00
fix: use httpx in generated configuration.py (#22418)
* fix: use httpx in generated configuration.py * fix: add enum_values for httpx * chore: update petstore samples
This commit is contained in:
@@ -3,6 +3,9 @@
|
|||||||
{{>partial_header}}
|
{{>partial_header}}
|
||||||
|
|
||||||
|
|
||||||
|
{{#async}}
|
||||||
|
import base64
|
||||||
|
{{/async}}
|
||||||
import copy
|
import copy
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
import logging
|
import logging
|
||||||
@@ -14,7 +17,9 @@ import sys
|
|||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
|
{{^async}}
|
||||||
import urllib3
|
import urllib3
|
||||||
|
{{/async}}
|
||||||
|
|
||||||
{{#hasHttpSignatureMethods}}
|
{{#hasHttpSignatureMethods}}
|
||||||
from {{packageName}}.signing import HttpSigningConfiguration
|
from {{packageName}}.signing import HttpSigningConfiguration
|
||||||
@@ -353,7 +358,9 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
"""Logging Settings
|
"""Logging Settings
|
||||||
"""
|
"""
|
||||||
self.logger["package_logger"] = logging.getLogger("{{packageName}}")
|
self.logger["package_logger"] = logging.getLogger("{{packageName}}")
|
||||||
|
{{^async}}
|
||||||
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
||||||
|
{{/async}}
|
||||||
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
"""Log format
|
"""Log format
|
||||||
"""
|
"""
|
||||||
@@ -615,9 +622,17 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
|
|
||||||
|
{{#async}}
|
||||||
|
return "Basic " + base64.b64encode(
|
||||||
|
(username + ":" + password).encode('utf-8')
|
||||||
|
).decode('utf-8')
|
||||||
|
{{/async}}
|
||||||
|
{{^async}}
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=username + ':' + password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
{{/async}}
|
||||||
|
|
||||||
def auth_settings(self)-> AuthSettings:
|
def auth_settings(self)-> AuthSettings:
|
||||||
"""Gets Auth Settings dict for api client.
|
"""Gets Auth Settings dict for api client.
|
||||||
@@ -720,6 +735,11 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
]
|
]
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/enumValues}}
|
{{/enumValues}}
|
||||||
|
{{^enumValues}}
|
||||||
|
{{#async}}
|
||||||
|
'enum_values': []
|
||||||
|
{{/async}}
|
||||||
|
{{/enumValues}}
|
||||||
}{{^-last}},{{/-last}}
|
}{{^-last}},{{/-last}}
|
||||||
{{#-last}}
|
{{#-last}}
|
||||||
}
|
}
|
||||||
@@ -762,6 +782,7 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -504,6 +504,7 @@ conf = openapi_client.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
|
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=username + ':' + password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
@@ -587,6 +588,7 @@ conf = openapi_client.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -504,6 +504,7 @@ conf = openapi_client.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
|
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=username + ':' + password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
@@ -587,6 +588,7 @@ conf = openapi_client.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import base64
|
||||||
import copy
|
import copy
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
import logging
|
import logging
|
||||||
@@ -20,7 +21,6 @@ import sys
|
|||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
|
||||||
|
|
||||||
from petstore_api.signing import HttpSigningConfiguration
|
from petstore_api.signing import HttpSigningConfiguration
|
||||||
|
|
||||||
@@ -325,7 +325,6 @@ conf = petstore_api.Configuration(
|
|||||||
"""Logging Settings
|
"""Logging Settings
|
||||||
"""
|
"""
|
||||||
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
||||||
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
|
||||||
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
"""Log format
|
"""Log format
|
||||||
"""
|
"""
|
||||||
@@ -574,9 +573,10 @@ conf = petstore_api.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
|
||||||
basic_auth=username + ':' + password
|
return "Basic " + base64.b64encode(
|
||||||
).get('authorization')
|
(username + ":" + password).encode('utf-8')
|
||||||
|
).decode('utf-8')
|
||||||
|
|
||||||
def auth_settings(self)-> AuthSettings:
|
def auth_settings(self)-> AuthSettings:
|
||||||
"""Gets Auth Settings dict for api client.
|
"""Gets Auth Settings dict for api client.
|
||||||
@@ -727,6 +727,7 @@ conf = petstore_api.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
import base64
|
||||||
import copy
|
import copy
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
import logging
|
import logging
|
||||||
@@ -20,7 +21,6 @@ import sys
|
|||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
|
||||||
|
|
||||||
from petstore_api.signing import HttpSigningConfiguration
|
from petstore_api.signing import HttpSigningConfiguration
|
||||||
|
|
||||||
@@ -325,7 +325,6 @@ conf = petstore_api.Configuration(
|
|||||||
"""Logging Settings
|
"""Logging Settings
|
||||||
"""
|
"""
|
||||||
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
||||||
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
|
||||||
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
"""Log format
|
"""Log format
|
||||||
"""
|
"""
|
||||||
@@ -574,9 +573,10 @@ conf = petstore_api.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
|
||||||
basic_auth=username + ':' + password
|
return "Basic " + base64.b64encode(
|
||||||
).get('authorization')
|
(username + ":" + password).encode('utf-8')
|
||||||
|
).decode('utf-8')
|
||||||
|
|
||||||
def auth_settings(self)-> AuthSettings:
|
def auth_settings(self)-> AuthSettings:
|
||||||
"""Gets Auth Settings dict for api client.
|
"""Gets Auth Settings dict for api client.
|
||||||
@@ -727,6 +727,7 @@ conf = petstore_api.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -578,6 +578,7 @@ conf = petstore_api.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
|
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=username + ':' + password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
@@ -731,6 +732,7 @@ conf = petstore_api.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
@@ -578,6 +578,7 @@ conf = petstore_api.Configuration(
|
|||||||
password = ""
|
password = ""
|
||||||
if self.password is not None:
|
if self.password is not None:
|
||||||
password = self.password
|
password = self.password
|
||||||
|
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=username + ':' + password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
@@ -731,6 +732,7 @@ conf = petstore_api.Configuration(
|
|||||||
variable_name, variable['default_value'])
|
variable_name, variable['default_value'])
|
||||||
|
|
||||||
if 'enum_values' in variable \
|
if 'enum_values' in variable \
|
||||||
|
and variable['enum_values'] \
|
||||||
and used_value not in variable['enum_values']:
|
and used_value not in variable['enum_values']:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The variable `{0}` in the host URL has invalid value "
|
"The variable `{0}` in the host URL has invalid value "
|
||||||
|
|||||||
Reference in New Issue
Block a user