Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/flask_restx/apidoc.py: 71%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

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)