Load swagger from disk

ogrepository-integration
Vadim vtroshchinskiy 2025-03-31 12:24:33 +02:00
parent 13257ce085
commit ec2fd05fdf
2 changed files with 1894 additions and 1 deletions

View File

@ -9,9 +9,11 @@ import importlib
import logging
import uuid
import argparse
import yaml
from flask import Flask, request
from flask_executor import Executor
from flask_restx import Api
from flasgger import Swagger
from werkzeug.exceptions import HTTPException
from systemd.journal import JournalHandler
@ -71,7 +73,7 @@ api = Api(app,
version='0.50',
title = "OpenGnsys Git API",
description = "API for managing disk images stored in Git",
doc = "/swagger/")
doc = "/apidocs/")
executor = Executor(app)
@ -85,6 +87,7 @@ for filename in os.listdir(blueprints_dir):
log.info("Loading %s/%s", blueprints_dir, filename)
module_name = filename.replace(".py", "")
swagger_file = os.path.join(blueprints_dir, filename.replace(".py", ".yaml"))
log.info("Importing %s", module_name)
importlib.invalidate_caches()
@ -93,6 +96,17 @@ for filename in os.listdir(blueprints_dir):
app.register_blueprint(module.blueprint)
if os.path.exists(swagger_file):
log.info("Loading Swagger documentation from %s...", swagger_file)
with open(swagger_file, "r", encoding='utf-8') as file:
swagger_template = yaml.safe_load(file)
swagger = Swagger(app, template=swagger_template)
else:
log.warning("Swagger not found for this module, looked in %s", swagger_file)
@app.errorhandler(HTTPException)
def handle_exception(e):

File diff suppressed because it is too large Load Diff