1- from flask import Blueprint , make_response , render_template
1+ from flask import Blueprint , make_response , render_template , Response
22
33from ...find import current_labthing
44from ...views import View
77class APISpecView (View ):
88 """OpenAPI v3 documentation"""
99
10+ responses = {
11+ "200" : {
12+ "description" : "OpenAPI v3 description of this API" ,
13+ "content" : {"application/json" : {}},
14+ }
15+ }
16+
1017 def get (self ):
1118 """OpenAPI v3 documentation"""
1219 return current_labthing ().spec .to_dict ()
1320
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" )
1436
1537class SwaggerUIView (View ):
1638 """Swagger UI documentation"""
@@ -25,6 +47,9 @@ def get(self):
2547)
2648
2749docs_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" ))
2853docs_blueprint .add_url_rule (
2954 "/swagger-ui" , view_func = SwaggerUIView .as_view ("swagger_ui" )
3055)
0 commit comments