[BUG][Python-Flask] Unit tests: Missing snake_case vs. camelCase/PascalCase conversion on path parameters
Created by: tomghyselinck
Description
We have an OpenAPI 3.0 spec file with parameterized path
s. The path parameters are defined as camelCase
.
When generating Python unit tests (place-holders) for python-flask
:
the test_*.py
files format the request path as:
'/data/{remoteId}'.format(remote_id=56)
Execution of the tests gives us an error:
python3 -m openapi_server.test.test_default_controller
Returns:
E
======================================================================
ERROR: test_data_remote_id_get (__main__.TestDefaultController)
Test case for data_remote_id_get
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tom/issues/python-flask-pythonic-params/openapi_server/test/test_default_controller.py", line 21, in test_data_remote_id_get
'/data/{remoteId}'.format(remote_id=56),
KeyError: 'remoteId'
----------------------------------------------------------------------
Ran 1 test in 0.018s
FAILED (errors=1)
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
-
Run the unit test
(cd python-flask-pythonic-params && python3 -m openapi_server.test.test_default_controller)
Related issues/PRs
Suggest a fix
Either:
- (recommended) Change the path parameter to a pythonic equivalent (i.e.
snake_case
) - Change
format()
parameter name tocamelCase