1
- from flask import Blueprint , make_response , render_template
1
+ from flask import Blueprint , make_response , render_template , Response
2
2
3
3
from ...find import current_labthing
4
4
from ...views import View
7
7
class APISpecView (View ):
8
8
"""OpenAPI v3 documentation"""
9
9
10
+ responses = {
11
+ "200" : {
12
+ "description" : "OpenAPI v3 description of this API" ,
13
+ "content" : {"application/json" : {}},
14
+ }
15
+ }
16
+
10
17
def get (self ):
11
18
"""OpenAPI v3 documentation"""
12
19
return current_labthing ().spec .to_dict ()
13
20
21
+ class APISpecYAMLView (View ):
22
+ """OpenAPI v3 documentation
23
+
24
+ A YAML document containing an API description in OpenAPI format
25
+ """
26
+
27
+ responses = {
28
+ "200" : {
29
+ "description" : "OpenAPI v3 description of this API" ,
30
+ "content" : {"text/yaml" : {}},
31
+ }
32
+ }
33
+
34
+ def get (self ):
35
+ return Response (current_labthing ().spec .to_yaml (), mimetype = "text/yaml" )
14
36
15
37
class SwaggerUIView (View ):
16
38
"""Swagger UI documentation"""
@@ -25,6 +47,9 @@ def get(self):
25
47
)
26
48
27
49
docs_blueprint .add_url_rule ("/swagger" , view_func = APISpecView .as_view ("swagger_json" ))
50
+ docs_blueprint .add_url_rule ("/openapi" , view_func = APISpecView .as_view ("swagger_json" ))
51
+ docs_blueprint .add_url_rule ("/swagger.yaml" , view_func = APISpecYAMLView .as_view ("swagger_yaml" ))
52
+ docs_blueprint .add_url_rule ("/openapi.yaml" , view_func = APISpecYAMLView .as_view ("swagger_yaml" ))
28
53
docs_blueprint .add_url_rule (
29
54
"/swagger-ui" , view_func = SwaggerUIView .as_view ("swagger_ui" )
30
55
)
0 commit comments