OpenAPITools / OpenAPITools/openapi-generator

[BUG] [PythonFlask] TypeError traceback (petshop.yaml)

Open
#2,188 8 comments 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

New installation will not create a working Flask container from the generated Dockerfile when I generate python-flask server from the demo modules/openapi-generator/src/test/resources/3_0/petstore.yaml in this repo. I get TypeError: Failed to fetch within the v2/ui, and a different TypeError with stacktrace in the log.

openapi-generator version

Master or 3.3.4

OpenAPI declaration file content or url

The petstore.yaml contained in test directory of this repo.

Command line used for generation
generate -i openapi-generator/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g python-flask -o new

or
run the openapi-generator-online image from dockerhub at local fqdn as noted below.

Steps to reproduce
  1. create a vhost/ingress openapi-gen and launch the generator, e.g. docker run -p 80:8080 -d openapitools/openapi-generator-online:v3.3.4 (I did the equivalent with k8s)
  2. generate a python-flask petstore
GENERATOR_FQDN=openapi-gen.$MYDOMAIN
sudo apt install jq unzip
curl -o flask.zip \
  $(curl -s -X POST --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    -d '{"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"}' \
    http://$GENERATOR_FQDN/api/gen/servers/python-flask \
    | jq -r .link)
unzip flask.zip
cd python-flask-server
sed -i -e "s/petstore.swagger.io/$(hostname -f):8080/" openapi_server/openapi/*.yaml
docker build . -t  petshop
docker run -p 8080:8080 --name=petshop -d petshop
  1. Then try to invoke actions such as
curl -X POST "http://$(hostname -f):8080/v2/user" -H "accept: */*" -H "Content-Type: application/json" -d "{\"email\":\"email@foo.com\",\"firstName\":\"firstName\",\"id\":0,\"lastName\":\"lastName\",\"password\":\"password\",\"phone\":\"phone\",\"userStatus\":6,\"username\":\"myname\"}"

On backend I see logs that look like:

192.168.2.44 - - [19/Feb/2019 06:54:17] "OPTIONS /v2/user HTTP/1.1" 200 -
[2019-02-19 06:54:31,738] ERROR in app: Exception on /v2/user [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/connexion/decorators/decorator.py", line 73, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.7/site-packages/connexion/decorators/uri_parsing.py", line 132, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.7/site-packages/connexion/decorators/validation.py", line 165, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.7/site-packages/connexion/decorators/decorator.py", line 44, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.7/site-packages/connexion/decorators/parameter.py", line 126, in wrapper
    return function(**kwargs)
TypeError: create_user() missing 1 required positional argument: 'user'

I also tried the older resources/2_0/petstore.yaml and ran into TypeError: cannot convert dictionary update sequence element #0 instead of the positional-argument error.

Related issues/PRs

I cannot find one here or by googling the error messages, so that's why I'm here. Closest thing I can find is unresolved issue #1666.

Suggest a fix

I'm a newbie to this (though I do have some familiarity with swagger/flask/etc), and it looks to me like a getting-started.md with full examples (validated by the CI so they don't break) would help greatly.

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

Reproduce the issue with modules/openapi-generator/src/test/resources/3_0/petstore.yaml using the python-flask generator, then inspect the generated openapi_server and the create_user traceback. Compare the 3_0 and 2_0 petstore outputs and run the Docker build and POST /v2/user request. Done means the generated Flask container handles the request without a TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, flask, openapi, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.