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)

0

3 Answers 3

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/ad55292eb7c2b76c6554fa8becab9d0c1c7b5862/butler/butler.py#L119

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.