Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] bug cant run vanilla shipped Petstore python-flask generated code #12278

Open
rlinke opened this issue Nov 20, 2023 · 4 comments
Open

Comments

@rlinke
Copy link

rlinke commented Nov 20, 2023

Description

The default python-server generated code does not work out of the box.
When running the code against a fresh install environment, the server cannot be started, instead we get "ModuleNotFoundError: No module named 'connexion.apps.flask_app'". This happens to the default Petstore example.

Swagger-codegen version

default Petstore OAS 3.0 example from swagger editor website (see below)

Swagger declaration file content or url

default Petstore OAS 3.0 example from swagger editor website (see below)

Command line used for generation

generation through website

Steps to reproduce
> open swagger editor (https://editor.swagger.io/)
> Edit > Load pet store 3.0 OAS
> Generate Server
> python-flask (downlods python repository python-flask-server-generated.zip)
> extract zip file to ~/server
> create environment 
> conda create -n server python=3.11
> conda activate server
> pip install -r requirements.txt
> conda list

#
# Name                    Version                   Build  Channel
anyio                     4.0.0                    pypi_0    pypi
asgiref                   3.7.2                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
bzip2                     1.0.8                he774522_0    defaults
certifi                   2023.11.17               pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
connexion                 3.0.1                    pypi_0    pypi
h11                       0.14.0                   pypi_0    pypi
httpcore                  1.0.2                    pypi_0    pypi
httpx                     0.25.1                   pypi_0    pypi
idna                      3.4                      pypi_0    pypi
inflection                0.5.1                    pypi_0    pypi
jinja2                    3.1.2                    pypi_0    pypi
jsonschema                4.20.0                   pypi_0    pypi
jsonschema-specifications 2023.11.1                pypi_0    pypi
libffi                    3.4.4                hd77b12b_0    defaults
markupsafe                2.1.3                    pypi_0    pypi
openssl                   3.0.12               h2bbff1b_0    defaults
pip                       23.3            py311haa95532_0    defaults
python                    3.11.5               he1021f5_0    defaults
python-dateutil           2.6.0                    pypi_0    pypi
python-multipart          0.0.6                    pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
referencing               0.31.0                   pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
rpds-py                   0.13.0                   pypi_0    pypi
setuptools                68.0.0          py311haa95532_0    defaults
six                       1.16.0                   pypi_0    pypi
sniffio                   1.3.0                    pypi_0    pypi
sqlite                    3.41.2               h2bbff1b_0    defaults
starlette                 0.32.0.post1             pypi_0    pypi
swagger-ui-bundle         1.1.0                    pypi_0    pypi
tk                        8.6.12               h2bbff1b_0    defaults
typing-extensions         4.8.0                    pypi_0    pypi
tzdata                    2023c                h04d1e81_0    defaults
urllib3                   2.1.0                    pypi_0    pypi
vc                        14.2                 h21ff451_1    defaults
vs2015_runtime            14.27.29016          h5e58377_2    defaults
werkzeug                  3.0.1                    pypi_0    pypi
wheel                     0.41.2          py311haa95532_0    defaults
xz                        5.4.2                h8cc25b3_0    defaults
zlib                      1.2.13               h8cc25b3_0    defaults```

> python -m swagger_server

(server) C:\Users\myuser\Downloads\python-flask-server-generated>python -m swagger_server
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\myuser\Downloads\python-flask-server-generated\swagger_server\__main__.py", line 5, in <module>
    from swagger_server import encoder
  File "C:\Users\myuser\Downloads\python-flask-server-generated\swagger_server\encoder.py", line 1, in <module>
    from connexion.apps.flask_app import FlaskJSONEncoder
ModuleNotFoundError: No module named 'connexion.apps.flask_app'
Related issues/PRs

I checked through search but didnt find any related issues/PR.

Suggest a fix/enhancement

It seems there are breaking changes in connexion from 2 to 3, which are currently not considered by python-flask server generation.
Simple workaround is making sure to use version 2 instead of version 3 in the requirements.txt

requirements.txt, I think this here:

from:
connexion >= 2.6.0
connexion[swagger-ui] >= 2.6.0
to:
connexion>=2, <3
connexion[swagger-ui]>=2, <3

fixes the issue for me.

Here with python 3.9 and fixed requirements.txt

cat requirements.txt
connexion>=2, <3
connexion[swagger-ui]>=2, <3
python_dateutil == 2.6.0
setuptools >= 21.0.0
swagger-ui-bundle >= 0.0.2


(swagger39) C:\Users\myuser\Downloads\python-flask-server-generated>conda list
# packages in environment at C:\Users\myuser\.conda\envs\swagger39:
#
# Name                    Version                   Build  Channel
anyio                     4.0.0                    pypi_0    pypi
asgiref                   3.7.2                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
certifi                   2023.11.17               pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
clickclick                20.10.2                  pypi_0    pypi
colorama                  0.4.6                    pypi_0    pypi
connexion                 2.14.2                   pypi_0    pypi
exceptiongroup            1.1.3                    pypi_0    pypi
flask                     2.2.5                    pypi_0    pypi
h11                       0.14.0                   pypi_0    pypi
httpcore                  1.0.2                    pypi_0    pypi
httpx                     0.25.1                   pypi_0    pypi
idna                      3.4                      pypi_0    pypi
importlib-metadata        6.8.0                    pypi_0    pypi
inflection                0.5.1                    pypi_0    pypi
itsdangerous              2.1.2                    pypi_0    pypi
jinja2                    3.1.2                    pypi_0    pypi
jsonschema                4.20.0                   pypi_0    pypi
jsonschema-specifications 2023.11.1                pypi_0    pypi
markupsafe                2.1.3                    pypi_0    pypi
openssl                   3.0.12               h2bbff1b_0    defaults
packaging                 23.2                     pypi_0    pypi
pip                       23.3             py39haa95532_0    defaults
python                    3.9.18               h1aa4202_0    defaults
python-dateutil           2.6.0                    pypi_0    pypi
python-multipart          0.0.6                    pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
referencing               0.31.0                   pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
rpds-py                   0.13.0                   pypi_0    pypi
setuptools                68.0.0           py39haa95532_0    defaults
six                       1.16.0                   pypi_0    pypi
sniffio                   1.3.0                    pypi_0    pypi
sqlite                    3.41.2               h2bbff1b_0    defaults
starlette                 0.32.0.post1             pypi_0    pypi
swagger-ui-bundle         0.0.9                    pypi_0    pypi
typing-extensions         4.8.0                    pypi_0    pypi
tzdata                    2023c                h04d1e81_0    defaults
urllib3                   2.1.0                    pypi_0    pypi
vc                        14.2                 h21ff451_1    defaults
vs2015_runtime            14.27.29016          h5e58377_2    defaults
werkzeug                  2.2.3                    pypi_0    pypi
wheel                     0.41.2           py39haa95532_0    defaults
zipp                      3.17.0                   pypi_0    pypi
@vishnuagbly
Copy link

I am facing the same issue

@hehesky
Copy link

hehesky commented Dec 11, 2023

connexion 3.0+ no longer has connexion.apps.flask_app, and actually do we even need a JSONEncoder class at all with python3?

@EingeoelterBolt
Copy link

My workaround: OpenAPITools/openapi-generator#17063 (comment)

@ianfallon
Copy link

Still an issue on 13 Feb 2024. Thankyou so much for posting your suggested fix @rlinke !

tommanis1 added a commit to JorritHK/kb-indexer-cloud that referenced this issue Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants