Skip to content

Commit 48e34d9

Browse files
author
Joel Collins
committed
Tidied up view descriptions
1 parent cdf151c commit 48e34d9

File tree

5 files changed

+7
-42
lines changed

5 files changed

+7
-42
lines changed

src/labthings/server/labthing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
from .representations import LabThingsJSONEncoder
1717
from .spec.apispec import rule_to_apispec_path
1818
from .spec.apispec_plugins import MarshmallowPlugin
19-
from .spec.utilities import get_spec
2019
from .spec.td import ThingDescription
21-
from .decorators import tag
2220
from .sockets import Sockets
2321
from .event import Event
2422

@@ -225,7 +223,7 @@ def register_extension(self, extension_object):
225223

226224
# Add route to the extensions blueprint
227225
self.add_view(
228-
tag("extensions")(extension_view["view"]),
226+
extension_view["view"],
229227
*("/extensions" + url for url in extension_view["urls"]),
230228
endpoint=endpoint,
231229
**extension_view["kwargs"],

src/labthings/server/semantics/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .. import decorators
21
from .. import fields
32

43

src/labthings/server/spec/apispec.py

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

55
from ..schema import Schema
66

7-
from labthings.core.utilities import get_docstring
7+
from labthings.core.utilities import get_docstring, get_summary
88

99
from werkzeug.routing import Rule
1010
from http import HTTPStatus
@@ -47,9 +47,7 @@ def view_to_apispec_operations(view, apispec: APISpec):
4747
ops[op] = {
4848
"description": getattr(view, "description", None)
4949
or get_docstring(view),
50-
"summary": (getattr(view, "description", None) or get_docstring(view))
51-
.partition("\n")[0]
52-
.strip(),
50+
"summary": getattr(view, "summary", None) or get_summary(view),
5351
}
5452

5553
# Add arguments schema

src/labthings/server/spec/td.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..event import Event
77

88
from .utilities import (
9-
get_spec,
109
convert_to_schema_or_json,
1110
schema_to_json,
1211
)
@@ -17,37 +16,6 @@
1716
from labthings.core.utilities import get_docstring, snake_to_camel
1817

1918

20-
def find_schema_for_view(view: View):
21-
"""Find the broadest available data schema for a Flask view
22-
23-
Looks for GET, POST, and PUT methods depending on if the view is read/write only
24-
25-
Args:
26-
view (View): View to search for schema
27-
28-
Returns:
29-
Broadest available schema dictionary for the View. Returns empty dictionary
30-
if no schema is found
31-
"""
32-
prop_schema = {}
33-
# If prop is read-only
34-
if hasattr(view, "get") and not (hasattr(view, "post") or hasattr(view, "put")):
35-
# Use GET schema
36-
prop_schema = get_spec(view.get).get("_schema", {}).get(200)
37-
# If prop is write-only
38-
elif not hasattr(view, "get") and (hasattr(view, "post") or hasattr(view, "put")):
39-
if hasattr(view, "post"):
40-
# Use POST schema
41-
prop_schema = get_spec(view.post).get("_params")
42-
else:
43-
# Use PUT schema
44-
prop_schema = get_spec(view.put).get("_params")
45-
else:
46-
prop_schema = {}
47-
48-
return prop_schema
49-
50-
5119
def build_forms_for_view(rules: list, view: View, op: list):
5220
"""Build a W3C form description for a particular View
5321

src/labthings/server/view/builder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def _update(self, args):
6666
generated_class.schema = schema
6767

6868
if description:
69-
generated_class.docs = {"description": description, "summary": description}
69+
generated_class.description = description
70+
generated_class.summary = description.partition("\n")[0].strip()
7071

7172
# Apply semantic type last, to ensure this is always used
7273
if semtype:
@@ -114,7 +115,8 @@ def _post_with_args(self, args):
114115
generated_class.schema = schema
115116

116117
if description:
117-
generated_class.docs = {"description": description, "summary": description}
118+
generated_class.description = description
119+
generated_class.summary = description.partition("\n")[0].strip()
118120

119121
# Apply semantic type last, to ensure this is always used
120122
if semtype:

0 commit comments

Comments
 (0)