Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lslee714 opened this issue Mar 8, 2021 · 0 comments

Comments

@lslee714
Copy link

lslee714 commented Mar 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant