Habba
Habba

Reputation: 515

How to structure a Flask app generated with Swagger

I have a module that performs one function and would like to expose this function through an API specified with Swagger.

I used the Swagger codegen to generate a Flask application. I found the thing_controller.py file and know that I need to link the my backend in that file, where the codegen put the line return 'do some magic!

I was wondering how to best structure this application. I would like to have:

  1. flask-server-dir to keep all the code relevant to the API (so only the code generated by Swagger)
  2. src dir that contains all code of the backend.

I would like to be able to import src/thing in the thing_controller.py file. That way I can call return thing.func() to perform all operations needed.

Upvotes: 0

Views: 392

Answers (1)

Tohmaxxx
Tohmaxxx

Reputation: 434

I created a python module to create swagger + jsonapi services: https://github.com/thomaxxl/safrs

If you run the demo, it creates an example method (send_mail) that can be invoked from the swagger UI: https://github.com/thomaxxl/safrs/blob/master/examples/demo.py

If you make it a classmethod, you won't need object instances.

This solution may not fit your requirements thoug, but it's like 5min work to get it running

Upvotes: 1

Related Questions