jmcarp / flask-apispec

MIT License
655 stars 156 forks source link

Way to disable naively generated documentation when using with Flask_Restful #214

Open lslee714 opened 3 years ago

lslee714 commented 3 years ago

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.