24 lines
646 B
Python
24 lines
646 B
Python
from flask import Blueprint, jsonify, send_file
|
|
from flask_swagger_ui import get_swaggerui_blueprint
|
|
import os
|
|
|
|
swagger_blueprint = Blueprint("swagger", __name__)
|
|
|
|
SWAGGER_URL = "/swagger"
|
|
API_URL = "http://127.0.0.1:5000/swagger/docs"
|
|
|
|
swagger_ui_blueprint = get_swaggerui_blueprint(
|
|
SWAGGER_URL,
|
|
API_URL,
|
|
config={"app_name": "Flask API"},
|
|
)
|
|
|
|
swagger_blueprint.register_blueprint(swagger_ui_blueprint)
|
|
|
|
|
|
@swagger_blueprint.route("/swagger/docs")
|
|
def serve_openapi():
|
|
"""Serve the OpenAPI spec from a file."""
|
|
docs_path = os.path.abspath("docs/rest_api_docs.yaml")
|
|
return send_file(docs_path, mimetype="application/yaml")
|