Skip to content

Commit 39d91e7

Browse files
committed
Add YAML version of openapi docs
1 parent a100fa9 commit 39d91e7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/labthings/default_views/docs/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Blueprint, make_response, render_template
1+
from flask import Blueprint, make_response, render_template, Response
22

33
from ...find import current_labthing
44
from ...views import View
@@ -7,10 +7,32 @@
77
class 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

1537
class SwaggerUIView(View):
1638
"""Swagger UI documentation"""
@@ -25,6 +47,9 @@ def get(self):
2547
)
2648

2749
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"))
2853
docs_blueprint.add_url_rule(
2954
"/swagger-ui", view_func=SwaggerUIView.as_view("swagger_ui")
3055
)

0 commit comments

Comments
 (0)