OpenAPITools / OpenAPITools/openapi-generator
[BUG][Python-Flask] securitySchemes: Endpoint module/function is not generated
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
- We define a (
securitySchemes)type: apiKeyforin: headerin our OpenAPI v3.0.1 yaml file. - We generate the
python-flaskcode.
When we start the server, it shows a warning: ... x-apikeyInfoFunc missing.
This definition is required by connexion to identify the module/function which performs the apiKey authorization/authentication. See also what changed in #546 - Rework security flow.
It looks like openapi-generator(-cli) does not generate this key in the scheme.
Is this intended?
The result is that authentication always fails and the server returns 401 - Unauthorized (No authorization token provided). See also release notes for Connexion 2.0:
If unsupported security requirements are defined or x-tokenInfoFunc/x-tokenInfoUrl is missing, connexion now denies requests instead of allowing access without security-check.
When we add the x-apikeyInfoFunc ourselves, and implement the endpoint, it works fine.
The same issue may probably occur with x-basicInfoFunc, x-bearerInfoFunc, etc.
See also Security - Connexion 2.0 documentation
openapi-generator version
I used OpenAPI generator CLI version 4.0.0-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar
OpenAPI declaration file content or url
See python-flask-security-endpoint.yaml in the attached zip-file:
python-flask-security-endpoint.zip
Command line used for generation
java -jar openapi-generator-cli-4.x.jar generate -i ./python-flask-security-endpoint.yaml -g python-flask -o ./python-flask-security-endpoint/
Steps to reproduce
-
Generate the server code
./python-flask-security-endpoint.sh -
Start the server
(cd ./python-flask-security-endpoint && python3 -m openapi_server) -
Perform a client request
curl -X GET "http://localhost:8080/data" -H "accept: application/json" -H "X-Full-Access-Token: 123"Returns:
{ "detail": "No authorization token provided", "status": 401, "title": "Unauthorized", "type": "about:blank" }
Related issues/PRs
I have not found any.
Suggest a fix
- If the
x-apikeyInfoFunc(or any of the others mentioned) is not defined by the user, theopenapi-generator-clishould generate the endpoint. I expect similar behavior like is done for the path operation endpoints. - The endpoint module/function itself should also be generated.
Note: there may also be need for backward-compatibility with the deprecated x-tokenInfoUrl.
See also Security - Connexion 2.0 documentation
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 reproducing the report with python-flask-security-endpoint.yaml and the shown openapi-generator CLI command, then inspect the generated server and its Connexion security setup. Compare the generated result with the x-apikeyInfoFunc behavior described in the issue, including the related security hook names. Done means the generated server exposes the required authorization endpoint configuration and the curl request no longer fails solely because that configuration is missing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, authentication, backend, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100