You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/libs/flask_restx/apidoc.py

39 lines
966 B

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from flask import url_for, Blueprint, render_template
class Apidoc(Blueprint):
"""
Allow to know if the blueprint has already been registered
until https://github.com/mitsuhiko/flask/pull/1301 is merged
"""
def __init__(self, *args, **kwargs):
self.registered = False
super(Apidoc, self).__init__(*args, **kwargs)
def register(self, *args, **kwargs):
super(Apidoc, self).register(*args, **kwargs)
self.registered = True
apidoc = Apidoc(
"restx_doc",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/swaggerui",
)
@apidoc.add_app_template_global
def swagger_static(filename):
return url_for("restx_doc.static", filename=filename)
def ui_for(api):
"""Render a SwaggerUI for a given API"""
return render_template("swagger-ui.html", title=api.title, specs_url=api.specs_url)