Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1671
Closed
Open
Issue created Dec 14, 2018 by Administrator@rootContributor

[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
  1. Generate the server code

    ./python-flask-pythonic-params.sh
  2. Start the server

    (cd python-flask-pythonic-params && python3 -m openapi_server)
  3. 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
  • #1856
Suggest a fix

Some suggestions (feel free for other suggestions ;-)):

  1. Define **kwargs as argument in the controllers and get the (non-pythonic) argument via kwargs['remoteId'].

  2. 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
Assignee
Assign to
Time tracking