Skip to content

Commit

Permalink
Removed uses of old __apispec__
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jun 22, 2020
1 parent 5eccd7c commit 833229f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 406 deletions.
11 changes: 9 additions & 2 deletions src/labthings/server/spec/apispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ..schema import Schema

from labthings.core.utilities import get_docstring

from werkzeug.routing import Rule
from http import HTTPStatus

Expand Down Expand Up @@ -42,7 +44,13 @@ def view_to_apispec_operations(view, apispec: APISpec):
for op in ("get", "post", "put", "delete"):
if hasattr(view, op):

ops[op] = {}
ops[op] = {
"description": getattr(view, "description", None)
or get_docstring(view),
"summary": (getattr(view, "description", None) or get_docstring(view))
.partition("\n")[0]
.strip(),
}

# Add arguments schema
if (op in (("post", "put", "delete"))) and hasattr(view, "get_args"):
Expand All @@ -56,7 +64,6 @@ def view_to_apispec_operations(view, apispec: APISpec):
if hasattr(view, "get_responses"):
ops[op]["responses"] = {}

print(view.get_responses())
for code, schema in view.get_responses().items():
ops[op]["responses"][code] = {
"description": HTTPStatus(code).phrase,
Expand Down
5 changes: 2 additions & 3 deletions src/labthings/server/spec/td.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def view_to_thing_property(self, rules: list, view: View):
# Basic description
prop_description = {
"title": getattr(view, "title", None) or view.__name__,
"description": get_docstring(view),
"description": getattr(view, "description", None) or get_docstring(view),
"readOnly": not (
hasattr(view, "post") or hasattr(view, "put") or hasattr(view, "delete")
),
Expand Down Expand Up @@ -225,7 +225,7 @@ def view_to_thing_action(self, rules: list, view: View):
# Basic description
action_description = {
"title": getattr(view, "title", None) or view.__name__,
"description": get_docstring(view),
"description": getattr(view, "description", None) or get_docstring(view),
"links": [{"href": f"{url}"} for url in action_urls],
"safe": getattr(view, "safe", False),
"idempotent": getattr(view, "idempotent", False),
Expand All @@ -248,7 +248,6 @@ def view_to_thing_action(self, rules: list, view: View):
if semtype:
action_description["@type"] = semtype


# Look for a _schema in the Action classes API Spec
action_output_schema = getattr(view, "schema", None)
if action_output_schema:
Expand Down
9 changes: 3 additions & 6 deletions src/labthings/server/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class View(MethodView):
"""

endpoint = None
__apispec__ = {}

schema: Schema = None
args: dict = None
semtype: str = None
tags: list = []
title: None
semtype: str = None

# Content type of response, usually application/json
content_type: str = "application/json"

responses: dict = {}
Expand Down Expand Up @@ -120,8 +121,6 @@ def represent_response(self, response):


class ActionView(View):
__apispec__ = {"tags": {"actions"}}

tags: list = ["actions"]
safe: bool = False
idempotent: bool = False
Expand Down Expand Up @@ -172,8 +171,6 @@ def dispatch_request(self, *args, **kwargs):


class PropertyView(View):
__apispec__ = {"tags": {"properties"}}

tags: list = ["properties"]

@classmethod
Expand Down
Loading

0 comments on commit 833229f

Please sign in to comment.