OpenAPITools / OpenAPITools/openapi-generator
[BUG] [PYTHON-LEGACY] Configuration.access_token not set in constructor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using the generated python-legacy client targeting an OpenAPI 3 schema that supports both basicAuth, cookieAuth, and jwtAuth, the access_token attribute is not set in the constructor or a value to be passed in. As a result, when using basicAuth, the following stack trace is generated:
Traceback (most recent call last):
File "/openapi_client/api/api_api.py", line 3297, in api_import_partial_update
return self.api_import_with_http_info(id, **kwargs) # noqa: E501
File "/openapi_client/api/api_api.py", line 3398, in api_import_partial_update_with_http_info
return self.api_client.call_api(
File "/openapi_client/api_client.py", line 397, in call_api
return self.__call_api(
File "/openapi_client/api_client.py", line 176, in __call_api
self.update_params_for_auth(
File "/openapi_client/api_client.py", line 619, in update_params_for_auth
auth_setting = self.configuration.auth_settings().get(auth)
File "/openapi_client/configuration.py", line 435, in auth_settings
if self.access_token is not None:
AttributeError: 'Configuration' object has no attribute 'access_token'
In the generated openapi_client_README.md it says that the access_token can be passed in:
# Configure Bearer authorization (JWT): jwtAuth
configuration = openapi_client.Configuration(
access_token = 'YOUR_BEARER_TOKEN'
)
But it is not present in the generated Configuration constructor:
def __init__(
self,
host=None,
api_key=None,
api_key_prefix=None,
username=None,
password=None,
discard_unknown_keys=False,
disabled_client_side_validations="",
server_index=None,
server_variables=None,
server_operation_index=None,
server_operation_variables=None,
ssl_ca_cert=None,
):
Because of this, the generated auth_settings() method accesses self.access_token which is never set to None or a user supplied value in the constructor:
def auth_settings(self):
"""Gets Auth Settings dict for api client.
:return: The Auth Settings information dict.
"""
auth = {}
if self.username is not None and self.password is not None:
auth["basicAuth"] = {
"type": "basic",
"in": "header",
"key": "Authorization",
"value": self.get_basic_auth_token(),
}
if "cookieAuth" in self.api_key:
auth["cookieAuth"] = {
"type": "api_key",
"in": "cookie",
"key": "sessionid",
"value": self.get_api_key_with_prefix(
"cookieAuth",
),
}
if self.access_token is not None:
auth["jwtAuth"] = {
"type": "bearer",
"in": "header",
"format": "JWT",
"key": "Authorization",
"value": "Bearer " + self.access_token,
}
return auth
openapi-generator version
5.3.0 (also exists in 5.2.1)
OpenAPI declaration file content or url
Generation Details
npx @openapitools/openapi-generator-cli generate \
--input-spec http://localhost:8000/openapi \
--generator-name python-legacy --output . \
--additional-properties=generateSourceCodeOnly=true
Steps to reproduce
Related issues/PRs
Suggest a fix
When a Configuration object is created that uses access_token, add the following optional argumenet:
def __init__(
...
access_token=None,
):
...
self.access_token = access_token
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the generated openapi_client/configuration.py constructor with its auth_settings() method, using openapi_client/api_client.py and openapi_client_README.md for the reported call path and documented argument. Done means the generated Configuration accepts and initializes access_token consistently with the README, and the basicAuth reproduction no longer raises AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100