Skip to content

Commit

Permalink
Add YAML version of openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rwb27 committed Jul 21, 2021
1 parent a100fa9 commit 39d91e7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/labthings/default_views/docs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Blueprint, make_response, render_template
from flask import Blueprint, make_response, render_template, Response

from ...find import current_labthing
from ...views import View
Expand All @@ -7,10 +7,32 @@
class APISpecView(View):
"""OpenAPI v3 documentation"""

responses = {
"200": {
"description": "OpenAPI v3 description of this API",
"content": {"application/json": {}},
}
}

def get(self):
"""OpenAPI v3 documentation"""
return current_labthing().spec.to_dict()

class APISpecYAMLView(View):
"""OpenAPI v3 documentation
A YAML document containing an API description in OpenAPI format
"""

responses = {
"200": {
"description": "OpenAPI v3 description of this API",
"content": {"text/yaml": {}},
}
}

def get(self):
return Response(current_labthing().spec.to_yaml(), mimetype="text/yaml")

class SwaggerUIView(View):
"""Swagger UI documentation"""
Expand All @@ -25,6 +47,9 @@ def get(self):
)

docs_blueprint.add_url_rule("/swagger", view_func=APISpecView.as_view("swagger_json"))
docs_blueprint.add_url_rule("/openapi", view_func=APISpecView.as_view("swagger_json"))
docs_blueprint.add_url_rule("/swagger.yaml", view_func=APISpecYAMLView.as_view("swagger_yaml"))
docs_blueprint.add_url_rule("/openapi.yaml", view_func=APISpecYAMLView.as_view("swagger_yaml"))
docs_blueprint.add_url_rule(
"/swagger-ui", view_func=SwaggerUIView.as_view("swagger_ui")
)
Expand Down

0 comments on commit 39d91e7

Please sign in to comment.