Openapi-generator: Add Python "aiohttp" server generator

Created on 26 Oct 2018  Â·  5Comments  Â·  Source: OpenAPITools/openapi-generator

Description

We would like to create a Python aiohttp server generator.

Similar to how some other generators (e.g. R, Lua, PowerShell) are created, we will use the reverse engineering process to create the Lisp client generator.

  • create Python aiohttp petstore server samples (implemented at least 2 endpoints to start with: getPetById, addPet)
  • reverse engineer the templates and the generator (Java class)
  • test the auto-generated code and revise the generator, templates
openapi-generator version

Latest master

Suggest a fix/enhancement

If anyone wants to work on this, please reply to let us know.

New generator Python help wanted

Most helpful comment

Thanks for the fix @Jyhess. Now it worked fine when using v2 specifications with a basePath.

However I ran into this connexion error when not specifying a basePath in a v2 specification or when using openapi v3 (which does not seem to have basePath):

connexion.exceptions.ConnexionException: aiohttp doesn't allow to set empty base_path ('/'), use non-empty instead, e.g /api

Realized that the reason for this is that in connexion self._only_one_api was false. When calling the connexion.AioHttpApp constructor in the generated server, the only_one_api=False argument should be set to True if there is only one API, to allow specifications with only one API to have an empty/no base path.

All 5 comments

Hmm, has this been completed by #1470 ?
I keep running into an error when starting the generated aiohttp Python server: :thinking:

~/s/o/s/s/p/python-aiohttp (master|✔) $ python3 -m openapi_server
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/gabori/src/openapi-generator/samples/server/petstore/python-aiohttp/openapi_server/__main__.py", line 3, in <module>
    from . import main
ImportError: cannot import name 'main'

Yes, should be completed by #1470

cc @Jyhess

@gaborigloi thanks for this report. I missed to generate __init__.py.
I will fix it asap.

@gaborigloi the issue has been fixed with #1933. Please give it another try with the latest master.

@Jyhess thanks for the quick turnaround in fixing the issue.

Thanks for the fix @Jyhess. Now it worked fine when using v2 specifications with a basePath.

However I ran into this connexion error when not specifying a basePath in a v2 specification or when using openapi v3 (which does not seem to have basePath):

connexion.exceptions.ConnexionException: aiohttp doesn't allow to set empty base_path ('/'), use non-empty instead, e.g /api

Realized that the reason for this is that in connexion self._only_one_api was false. When calling the connexion.AioHttpApp constructor in the generated server, the only_one_api=False argument should be set to True if there is only one API, to allow specifications with only one API to have an empty/no base path.

Was this page helpful?
0 / 5 - 0 ratings