OpenAPITools / OpenAPITools/openapi-generator
[REQ] Python client will not allow request auth overrides in
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
Currently, if the openapi spec doesn't define auth for an endpoint, the users won't be able to set custom auth on individual requests via _request_auths.
This is due to this line:
openapi-generator version
v6.2.0
OpenAPI declaration file content or url
This is an endpoint from petstore.yaml that will have this issue. The only difference with the original endpoint is that security: keys are removed.
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
requestBody:
$ref: '#/components/requestBodies/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
requestBody:
$ref: '#/components/requestBodies/Pet'
Generation Details
This happens when python is used as the template, irrespective of the config.
Steps to reproduce
This line looks like it would respect the custom auth settings, judging by api_client.py:
api_response = api_instance.v3_my_endpoint(endpoint_body, _request_auths=[{'in':'header', 'type': 'bearer', 'key': 'Authorization', 'value': f"Bearer {TOKEN}"}])
However, the request will still be sent without any auth settings, no exceptions thrown.
Related issues/PRs
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 in modules/openapi-generator/src/main/resources/python/api_client.handlebars at the linked lines, then compare the generated api_client.py behavior with the endpoint methods that accept _request_auths. Reproduce with the provided petstore.yaml endpoint lacking security settings. Done means request-level authentication is honored for such endpoints, with regression coverage for the demonstrated call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100