[BUG][Python-Flask] camelCase path parameters are not converted to snake_case
Created by: tomghyselinck
Description
- We have parameterized
paths
in our OpenAPI v3.x definition file. - We generate a and start
python-flask
server. - When trying to obtain the data, we get an internal server error and the server logs:
[2018-12-14 10:20:05,725] ERROR in app: Exception on /data/123 [GET] Traceback (most recent call last): File "/home/tom/.local/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() ... File "/home/tom/.local/lib/python3.5/site-packages/connexion/decorators/decorator.py", line 44, in wrapper response = function(request) File "/home/tom/.local/lib/python3.5/site-packages/connexion/decorators/parameter.py", line 131, in wrapper return function(**kwargs) TypeError: data_remote_id_get() got an unexpected keyword argument 'remoteId' 127.0.0.1 - - [14/Dec/2018 10:20:05] "GET /data/123 HTTP/1.1" 500 -
The camelCase
path parameter is not converted to a snake_case
(== pythonic) function argument for the controller.
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-pythonic-params.yaml
in the attached zip-file:
python-flask-pythonic-params.zip
Command line used for generation
java -jar openapi-generator-cli-4.x.jar generate -i ./python-flask-pythonic-params.yaml -g python-flask -o ./python-flask-pythonic-params/
Steps to reproduce
-
Generate the server code
./python-flask-pythonic-params.sh
-
Start the server
(cd python-flask-pythonic-params && python3 -m openapi_server)
-
Perform a client request
curl -X GET "http://localhost:8080/data/123" -H "accept: application/json"
Returns:
{ "detail": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.", "status": 500, "title": "Internal Server Error", "type": "about:blank" }
Related issues/PRs
Suggest a fix
Some suggestions (feel free for other suggestions ;-)):
-
Define
**kwargs
as argument in the controllers and get the (non-pythonic) argument viakwargs['remoteId']
. -
Provide
pythonic_params=True
to the connexion/Flask app. I verified that this works.In our example this would be:
Replacing:
app.add_api('openapi.yaml', arguments={'title': 'Test REST API'})
by
app.add_api('openapi.yaml', arguments={'title': 'Test REST API'}, pythonic_params=True)
See also zalando/connexion:
- #687 - pythonic_params does not cover the path params