OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python-Flask] Unit tests: Missing snake_case vs. camelCase/PascalCase conversion on path parameters

Open
#1,856 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

We have an OpenAPI 3.0 spec file with parameterized paths. 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
  1. Generate the server code

    ./python-flask-pythonic-params.sh
    
  2. Run the unit test

    (cd python-flask-pythonic-params && python3 -m openapi_server.test.test_default_controller)

Related issues/PRs
  • #1671
Suggest a fix

Either:

  • (recommended) Change the path parameter to a pythonic equivalent (i.e. snake_case)
  • Change format() parameter name to camelCase

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the server from python-flask-pythonic-params.yaml with the documented command, then inspect openapi_server/test/test_default_controller.py and run its test module. The work is done when the generated path-parameter formatting handles the camelCase remoteId consistently and the reproduced unit test completes without a KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.