3

I am using flask restful swagger for api documentation, but there are some api endpoints which i dont want to be showed on the UI offered by swagger. Is there a way to do so in the code?

Omair Shamshir
  • 2,126
  • 13
  • 23

3 Answers3

6

For anyone who's using flask-restplus, you're probably looking for a way to hide endpoints from the documentation.

# Hide the full resource
@api.route('/resource1/', doc=False)
class Resource1(Resource):
    def get(self):
        return {}

@api.route('/resource2/')
@api.doc(False)
class Resource2(Resource):
    def get(self):
        return {}

@api.route('/resource3/')
@api.hide
class Resource3(Resource):
    def get(self):
        return {}
André C. Andersen
  • 8,955
  • 3
  • 53
  • 79
Vito
  • 1,580
  • 1
  • 17
  • 32
0

Since you've not provided much information it's quite difficult to know what you mean but according to the docs:

# Operations not decorated with @swagger.operation do not get added to the swagger docs

class Todo(Resource):
    def options(self, todo_id):
        """
        I'm not visible in the swagger docs
        """
        pass

That is if you do not decorate your Resources they will not show up in the docs. More information here https://github.com/rantav/flask-restful-swagger

Andreas Klintberg
  • 440
  • 1
  • 11
  • 29
  • 1
    This does work, but IMO there are many reasons why you would like to have the decorators on, but still hide the endpoint form the documentation. One could be that you are testing out the endpoint, but aren't ready to show it to your API users just yet. Another is the marshaling mechanism, which handles API object model integrity. – André C. Andersen Jun 30 '19 at 13:08
-2

Try this

api = Api(app, doc=False)
zx485
  • 28,498
  • 28
  • 50
  • 59
MasterOfTheHouse
  • 1,164
  • 1
  • 14
  • 34
  • This answer is incorrect. It disables the API documentation route itself, it does not disable documentation for particular endpoints: `str doc: The documentation path. If set to a false value, documentation is disabled.` – André C. Andersen Jun 30 '19 at 12:38