Openapi-generator: Error running python-flask server generated with openapi-generator-cli-3.0.0.jar.

Created on 15 Jun 2018  路  10Comments  路  Source: OpenAPITools/openapi-generator

I've generated python-flask SDK from petstore.yaml and hit the run time error summarized below. This worked fine with the swager-codegen and it seems "openapi" components is not found. It used to be "swagger". Maybe I'm missing some plugin or need a newer python? Any suggestions?

I've attached the complete backtrace.

Thanks
Frank

Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/swagger_spec_validator/common.py", line 24, in wrapper
return method(args, *kwargs)
File "/usr/lib/python3.5/site-packages/swagger_spec_validator/validator20.py", line 141, in validate_json
cls=Draft4Validator,
File "/usr/lib/python3.5/site-packages/swagger_spec_validator/ref_validators.py", line 53, in validate
instance_cls(schema, args, *kwargs).validate(instance)
File "/usr/lib/python3.5/site-packages/jsonschema/validators.py", line 130, in validate
raise error
jsonschema.exceptions.ValidationError: 'components', 'openapi', 'servers' do not match any of the regexes: '^x-'

Suggest a fix/enhancement

petstore_flask.txt

Bug Python

Most helpful comment

The PR has been merged and will be part of connexion 2.0 : https://github.com/zalando/connexion/milestone/10

All 10 comments

@fjd1234 Thanks for reporting this issue.

I've also tried to run python-flask stub (latest master) and got similar errors you reported.

$ cd openapi-generator
$ bin/python-flask-petstore-python2.sh
$ cd samples/server/petstore/flaskConnexion-python2/
$ pip install -r requirements.txt
$ python -m openapi_server

Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)

...
...
...

<ValidationError: "'swagger' is a required property">)

It may caused by the two stuff below:

cc Technical committee: @taxpon @frol @mbohlool @cbornet @kenjones-cisco

Indeed, we generate an OAIv3 yaml but flask-connexion doesn't support it yet.
A solution would be to have a mustache tag that contains a v2 version of the spec.

So the issue seems to be that connexion doesn't support openapi v3 and a suggested solution would be to use a mustache tag that conatains v2 version. How would I do this? I'd like to use this codegen to generate python-flask code for v3 specs.

Thanks
Frank

Still the same error with 3.2.2 of the generator. I couldn't find any documentation on how to make openapi generator work with python-flask with any version of the spec.

To avoid confusion, I would propose to remove "python-flask" from the list of the generators on the home page.

I would also like the ability to generate a OAIv2/Swagger v2 spec until such a time as connexion can fully support v3

Here is the PR to support OpenAPI spec v3 in connexion: https://github.com/zalando/connexion/pull/621

The PR has been merged and will be part of connexion 2.0 : https://github.com/zalando/connexion/milestone/10

UPDATE: @cbornet has made a fix (workaround) to the Python Flask generator before connexion 2.0 is officially released.

Please give it a try by using the SNAPSHOT version or the docker image.

We'll close this issue once we update Python Flask generator to use connexion 2.0 stable release.

The Python flask generator has been updated to use flask-connexion 2.0.0 stable version. Please pull the latest master to give it a try.

Was this page helpful?
0 / 5 - 0 ratings