Skip to content

Commit

Permalink
Add swaagger UI
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jun 7, 2024
1 parent bdeaf8a commit adee146
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions IM/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import yaml

from flask_swagger_ui import get_swaggerui_blueprint
from cheroot.wsgi import Server as WSGIServer, PathInfoDispatcher
from cheroot.ssl.builtin import BuiltinSSLAdapter
from werkzeug.middleware.proxy_fix import ProxyFix
Expand Down Expand Up @@ -62,6 +63,13 @@
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1, x_prefix=1)
flask_server = None

# Add the swagger UI
swaggerui_blueprint = get_swaggerui_blueprint(
'/api/docs', # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
'/swagger.json'
)
app.register_blueprint(swaggerui_blueprint)


def run_in_thread(host, port):
flask_thr = threading.Thread(target=run, args=(host, port))
Expand Down Expand Up @@ -943,6 +951,11 @@ def RESTGetVersion():

@app.route('/')
def RESTIndex():
return flask.redirect('/api/docs')


@app.route('/swagger.json')
def RESTSwagger():
rest_path = os.path.dirname(os.path.abspath(__file__))
abs_file_path = os.path.join(rest_path, 'swagger_api.yaml')
api_docs = yaml.safe_load(open(abs_file_path, 'r'))
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ dependencies = [
"requests-cache >= 1.0.0",
"packaging",
"werkzeug",
"xmltodict"
"xmltodict",
"flask-swagger-ui"
]
license = {text = "GPL version 3, http://www.gnu.org/licenses/gpl-3.0.txt"}
dynamic = ["version", "readme"]
Expand Down

0 comments on commit adee146

Please sign in to comment.