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,146
  • 1
  • 18
  • 20
eplaut
  • 666
  • 1
  • 7
  • 26

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
  • 666
  • 1
  • 7
  • 26
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
  • 18,379
  • 16
  • 47
  • 61