🔗 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
- Install as described in docs.
- Init in the app:
from flasgger import Swagger app = Flask(__name__) swagger = Swagger(app)
- Define API specs in external YAML files, see example in flask-restx-learn. Place YAML file in the same directory with endpoint code.
- Add docstrings to endpoints:
@api.route("/") class BookList(Resource): def get(self): """ file: books_get_list.yml """ return get_all_books_json()
- API docs are available at
http://127.0.0.1:5000/apidocs/
.
📂 Flask | Последнее изменение: 25.02.2024 14:36