3

I have build a small service with flask and already wrote a swagger yaml file to describe it's API. How can I expose the swagger file through the flask app?

I didn't mean to expose the file itself (send_from_directory) but to create new endpoint that will show it as swagger-ui (interactive, if possible)

molivier
  • 2,054
  • 16
  • 18
eplaut
  • 684
  • 1
  • 7
  • 24

3 Answers3

3

OK, this is what I did.

I used flasgger to and wrap my app with flasgger.Swagger. than I added 2 endpoints:

  1. /_api serves the YAML file (with send_from_directory)
  2. /api redirects to the flasgger api /apidocs/index.html?url=/api I'm sure it can be done better, but I failed to find it.

github: https://github.com/eplaut/python-butler/blob/master/butler/butler.py#L119

eplaut
  • 684
  • 1
  • 7
  • 24
2

You can use Flasgger, a Flask extension that wraps Swagger UI for Flask http://github.com/rochacbruno/flasgger

0

There are three ways of doing it:

  • via Restful-Api (Api.doc)
  • via getting swagger templates
  • via registering blueprints (from flask-swagger-ui or smth).
Tomerikoo
  • 15,737
  • 15
  • 35
  • 52