When generating documentation for a flask application that leverages flask_restful, it seems FlaskApiSpec naively generates all possible URL/Method combinations for the flask_restful Resource.
e.g.
from flask import Flask
from flask_apispec.views import MethodResource
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api()
api.init_app(app)
class Recipes(MethodResource, Resource):
def get(self, recipe_id=None):
"""Return all or a specific recipe"""
api.add_resource(Recipes, '/recipes/', '/recipes/<int:recipe_id>/')
# not shown - also configure FlaskApiSpec
In the resulting swagger ui, there will now be two documentation panels for the GET request, which makes sense since I said there are two URLs to connect to the Recipes resource class.
However, is there a way to disable one of the two documentations? The use case is if I subsequently defined a delete method on the Recipes we'd also see two DELETE documentation panels when in the deletion scenario, we always would have the recipe_id parameter passed into the URL so a delete call to /recipes/ would actually result in a 404
I understand I could alternatively make a class DeleteRecipe resource class and map it to the same url w/ a different endpoint, but I'm in the unfortunately position of trying and plug this into an existing application architecture that would make it a lot of work to separate out all the resource classes that already exist.
When generating documentation for a flask application that leverages
flask_restful
, it seems FlaskApiSpec naively generates all possible URL/Method combinations for theflask_restful
Resource.e.g.
In the resulting swagger ui, there will now be two documentation panels for the
GET
request, which makes sense since I said there are two URLs to connect to theRecipes
resource class.However, is there a way to disable one of the two documentations? The use case is if I subsequently defined a
delete
method on theRecipes
we'd also see twoDELETE
documentation panels when in the deletion scenario, we always would have therecipe_id
parameter passed into the URL so a delete call to/recipes/
would actually result in a 404I understand I could alternatively make a
class DeleteRecipe
resource class and map it to the same url w/ a different endpoint, but I'm in the unfortunately position of trying and plug this into an existing application architecture that would make it a lot of work to separate out all the resource classes that already exist.