Working with the OpenTripModel OpenAPI yaml and generating a server using openapi-generator (v4.0.0) does not seem to work and gives a connexion error.
Trying to run the server gives the following error:
Traceback (most recent call last):
File "c:\python37\Lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python37\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Julian\Downloads\server\openapi_server\__main__.py", line 18, in <module>
main()
File "C:\Users\Julian\Downloads\server\openapi_server\__main__.py", line 13, in main
pythonic_params=True)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\apps\flask_app.py", line 54, in add_api
api = super(FlaskApp, self).add_api(specification, **kwargs)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\apps\abstract.py", line 155, in add_api
options=api_options.as_dict())
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\apis\abstract.py", line 72, in __init__
self.specification = Specification.load(specification, arguments=arguments)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\spec.py", line 151, in load
return cls.from_file(spec, arguments=arguments)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\spec.py", line 108, in from_file
return cls.from_dict(spec)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\spec.py", line 146, in from_dict
return OpenAPISpecification(spec)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\spec.py", line 39, in __init__
self._validate_spec(raw_spec)
File "C:\Users\Julian\.virtualenvs\server-Cq-s3KBS\lib\site-packages\connexion\spec.py", line 232, in _validate_spec
raise InvalidSpecification.create_from(e)
connexion.exceptions.InvalidSpecification: Required list has not defined properties: ['type']
The server should run, but it doesn't. The SwaggerHub editor says the code is valid.
Running openapi-spec-validator also gives the same error. However, other validators say it is valid. And neither openapi-spec-validator nor connexion give the exact location of the error, so I don't know where it is and how to fix it.
Generating the server seems to work fine, although running it gives the error
connexion.exceptions.InvalidSpecification: Required list has not defined properties: ['type']
Download the OpenTripModel openapi spec: https://raw.githubusercontent.com/opentripmodel/opentripmodel/master/api/swagger.yaml
Install generator using NPM
npm install @openapitools/openapi-generator-cli -g
Run the generator on the swagger.yaml file into ./server/ dir
openapi-generator generate -i .\swagger.yaml -g python-flask -o .\server
Move into new server dir
cd server
Install requirements
pip3 install -r requirements.txt
Run server
python3 -m openapi_server
And it should give the error.
Output of the commands:
python --versionpip show connexion | grep "^Version\:"Turns out the swagger.yaml file had a lot of errors which did not show up in a lot of the validators.
https://github.com/IBM/openapi-validator shows them correctly to be fixed.
Turns out the swagger.yaml file had a lot of errors which did not show up in a lot of the validators.
https://github.com/IBM/openapi-validator shows them correctly to be fixed.
Wow, this hint just saved me so much time. Thanks @julianflapper 馃檶
Most helpful comment
Turns out the swagger.yaml file had a lot of errors which did not show up in a lot of the validators.
https://github.com/IBM/openapi-validator shows them correctly to be fixed.