Skip to content

Commit 833229f

Browse files
author
Joel Collins
committed
Removed uses of old __apispec__
1 parent 5eccd7c commit 833229f

File tree

6 files changed

+16
-406
lines changed

6 files changed

+16
-406
lines changed

src/labthings/server/spec/apispec.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from ..schema import Schema
66

7+
from labthings.core.utilities import get_docstring
8+
79
from werkzeug.routing import Rule
810
from http import HTTPStatus
911

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

45-
ops[op] = {}
47+
ops[op] = {
48+
"description": getattr(view, "description", None)
49+
or get_docstring(view),
50+
"summary": (getattr(view, "description", None) or get_docstring(view))
51+
.partition("\n")[0]
52+
.strip(),
53+
}
4654

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

59-
print(view.get_responses())
6067
for code, schema in view.get_responses().items():
6168
ops[op]["responses"][code] = {
6269
"description": HTTPStatus(code).phrase,

src/labthings/server/spec/td.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def view_to_thing_property(self, rules: list, view: View):
175175
# Basic description
176176
prop_description = {
177177
"title": getattr(view, "title", None) or view.__name__,
178-
"description": get_docstring(view),
178+
"description": getattr(view, "description", None) or get_docstring(view),
179179
"readOnly": not (
180180
hasattr(view, "post") or hasattr(view, "put") or hasattr(view, "delete")
181181
),
@@ -225,7 +225,7 @@ def view_to_thing_action(self, rules: list, view: View):
225225
# Basic description
226226
action_description = {
227227
"title": getattr(view, "title", None) or view.__name__,
228-
"description": get_docstring(view),
228+
"description": getattr(view, "description", None) or get_docstring(view),
229229
"links": [{"href": f"{url}"} for url in action_urls],
230230
"safe": getattr(view, "safe", False),
231231
"idempotent": getattr(view, "idempotent", False),
@@ -248,7 +248,6 @@ def view_to_thing_action(self, rules: list, view: View):
248248
if semtype:
249249
action_description["@type"] = semtype
250250

251-
252251
# Look for a _schema in the Action classes API Spec
253252
action_output_schema = getattr(view, "schema", None)
254253
if action_output_schema:

src/labthings/server/view/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ class View(MethodView):
3737
"""
3838

3939
endpoint = None
40-
__apispec__ = {}
4140

4241
schema: Schema = None
4342
args: dict = None
43+
semtype: str = None
4444
tags: list = []
4545
title: None
46-
semtype: str = None
46+
47+
# Content type of response, usually application/json
4748
content_type: str = "application/json"
4849

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

121122

122123
class ActionView(View):
123-
__apispec__ = {"tags": {"actions"}}
124-
125124
tags: list = ["actions"]
126125
safe: bool = False
127126
idempotent: bool = False
@@ -172,8 +171,6 @@ def dispatch_request(self, *args, **kwargs):
172171

173172

174173
class PropertyView(View):
175-
__apispec__ = {"tags": {"properties"}}
176-
177174
tags: list = ["properties"]
178175

179176
@classmethod

0 commit comments

Comments
 (0)