Reputation: 139
Is there a way to create Swagger-API UI documentation for a flask-potion based application? I've tried using "flasgger", but it doesn't work for routes that are written with potion-type routes.
Flask-potion has a route specified in following manner-
@Route.GET('/num_products')
But "flasgger" expects a route in following manner-
@app.route('/num_products', methods=['GET'])
Upvotes: 2
Views: 441
Reputation: 139
There is no clean way to do this. However, a hackish solution for the same exists-
Flasgger works for default flask routes. We can re-define the routes that were defined earlier using flask-potion, as default flask routes and make calls to the earlier flask-potion functions from the newly created functions. Note- Changing the existing routes to the new routes didn't work for me. I had to mask the old calls with new ones and call the old function from the new ones.
Note- This only works for custom routes that are written by the user and doesn't work for default routes that are generated from data model by flask potion.
Existing code-
class ProductResource(BaseModelResource):
@Route.GET('/num_products')
def product_count():
return product.query(...)
Refactored Code -
class ProductResource(BaseModelResource):
def product_count():
return product.query(...)
@app.route('/num_products', methods=['GET'])
def product_count_main():
output = product_count()
Response(str(output), content_type='application/json')
Upvotes: 1