1

I've created YAML file at Swaggerhub and I generated Python Flask code like this:

java -jar swagger-codegen-cli.jar generate -l python-flask -i swagger.yaml -o mycode/

So far everything works fine. Now I want to implement my own functionality for each API call. There is a generated file named developers_controller.py which contains getters for my API get methods returning "do some magic!" only. I want to replace them with my functionality (i.e. return data from database). How should I do it?

I've found something about Swagger templates. I am not really sure if it's what I want. I am also not sure how to add/modify the templates. I've found https://github.com/swagger-api/swagger-codegen/wiki/Building-your-own-Templates and according to it I think I'll have to copy whole https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java file and use it as a template? From another sources I think I have to copy whole Isn't it possible just to create a simple file containing: get_my_swagger_generated_method = file.my_own_method ? Do I need to know Java to create Python templates? Or is the only way to edit the generated file afterwards (with sed, awk, bash etc.)?

In short: basically I don't know where to start, I didn't found any step-by-step example how to create python-flask template containing my own functionality.

Michal Špondr
  • 1,337
  • 2
  • 21
  • 44
  • Possible duplicate of [cleanest way to glue generated Flask app code (Swagger-Codegen) to backend implementation](https://stackoverflow.com/questions/45680298/cleanest-way-to-glue-generated-flask-app-code-swagger-codegen-to-backend-imple) – Michal Špondr May 10 '18 at 08:35
  • http://michal.karzynski.pl/blog/2016/06/19/building-beautiful-restful-apis-using-flask-swagger-ui-flask-restplus/ – Michal Špondr May 10 '18 at 08:36

0 Answers0