🔗 Flask


Flasgger is a Flask extension to extract OpenAPI-Specification from all Flask views registered in your API.

Flasgger also comes with SwaggerUI embedded so you can access http://localhost:5000/apidocs and visualize and interact with your API resources.

Usage example: flask-restx-learn


Using Flasgger with external YAML files

  1. Install as described in docs.
  2. Init in the app:
    from flasgger import Swagger
     
    app = Flask(__name__)
    swagger = Swagger(app)
  3. Define API specs in external YAML files, see example in flask-restx-learn. Place YAML file in the same directory with endpoint code.
  4. Add docstrings to endpoints:
    @api.route("/")  
    class BookList(Resource):  
        def get(self):  
            """  
            file: books_get_list.yml
            """
            return get_all_books_json()
  5. API docs are available at http://127.0.0.1:5000/apidocs/.


📂 Flask | Последнее изменение: 25.02.2024 14:36