1from flask import url_for, Blueprint, render_template
2
3
4class Apidoc(Blueprint):
5 """
6 Allow to know if the blueprint has already been registered
7 until https://github.com/mitsuhiko/flask/pull/1301 is merged
8 """
9
10 def __init__(self, *args, **kwargs):
11 self.registered = False
12 super(Apidoc, self).__init__(*args, **kwargs)
13
14 def register(self, *args, **kwargs):
15 super(Apidoc, self).register(*args, **kwargs)
16 self.registered = True
17
18
19apidoc = Apidoc(
20 "restx_doc",
21 __name__,
22 template_folder="templates",
23 static_folder="static",
24 static_url_path="/swaggerui",
25)
26
27
28@apidoc.add_app_template_global
29def swagger_static(filename):
30 return url_for("restx_doc.static", filename=filename)
31
32
33def ui_for(api):
34 """Render a SwaggerUI for a given API"""
35 return render_template("swagger-ui.html", title=api.title, specs_url=api.specs_url)