I want to generate a Python Flask server providing a certain OpenAPI spec as input - let's say foo.yaml - running the following command:
java -jar openapi-generator-cli.jar generate -i foo.yaml -g python-flask -o python-flask_api_server
However, this generates a server stub containing a file called foo_controller.py under \python-flask_api_server\openapi_server\controllers and each method defined in this file returns the same template string:
'do some magic!'
foo_controller.py
def foo_post(inline_object=None): # noqa: E501
"""Create a foo
# noqa: E501
:param inline_object:
:type inline_object: dict | bytes
:rtype: str
"""
if connexion.request.is_json:
inline_object = InlineObject.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
What I'm trying to do with OpenAPI Generator is to generate a server stub whose foo_controller.py references my own implementation of this file, like this for example:
foo_controller.py (generated file)
import foo_controller_impl
def foo_post(inline_object=None): # noqa: E501
"""Create a foo
# noqa: E501
:param inline_object:
:type inline_object: dict | bytes
:rtype: str
"""
foo_controller_impl.foo_post_impl(inline_object)
foo_controller_impl.py (my implementation of foo_controller.py)
def foo_post_impl(inline_object=None): # noqa: E501
if connexion.request.is_json:
inline_object = InlineObject.from_dict(connexion.request.get_json()) # noqa: E501
print("Request body is:\n" + str(inline_object))
response = "/foo/1"
return response
I ran the following command to generate a new template set:
java -jar openapi-generator-cli.jar meta -o my-codegen -n myCodegen -p org.openapitools.codegen
But after reading the generated README.md and inspecting MycodegenGenerator.java it still isn't very clear to me how I could achieve this.
Any help would be greatly appreciated.