Skip to content

Commit f161213

Browse files
committed
Better response descriptions for builtin endpoints
1 parent f49aedb commit f161213

File tree

4 files changed

+85
-32
lines changed

4 files changed

+85
-32
lines changed

src/labthings/default_views/actions.py

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,29 @@
77
from ..views import View
88

99

10+
1011
class ActionQueueView(View):
1112
"""List of all actions from the session"""
1213

1314
def get(self):
1415
"""Action queue
15-
---
16-
description: Queue of most recent actions in the session
17-
summary: Queue of most recent actions in the session
18-
responses:
19-
200:
20-
content:
21-
application/json:
22-
schema: ActionSchema
16+
17+
This endpoint returns a list of all actions that have run since
18+
the server was started, including ones that have completed and
19+
actions that are still running. Each entry includes links to
20+
manage and inspect that action.
2321
"""
2422
return ActionSchema(many=True).dump(current_labthing().actions.threads)
23+
get.responses = {
24+
"200": {
25+
"description": "List of Action objects",
26+
"content": {
27+
"application/json": {
28+
"schema": ActionSchema(many=True)
29+
}
30+
}
31+
}
32+
}
2533

2634

2735
class ActionObjectView(View):
@@ -35,14 +43,10 @@ class ActionObjectView(View):
3543

3644
def get(self, task_id):
3745
"""Show the status of an Action
38-
---
39-
description: Status of an Action
40-
summary: Status of an Action
41-
responses:
42-
200:
43-
content:
44-
application/json:
45-
schema: ActionSchema
46+
47+
A `GET` request will return the current status
48+
of an action, including logs. For completed
49+
actions, it will include the return value.
4650
"""
4751
task_dict = current_labthing().actions.to_dict()
4852

@@ -52,18 +56,25 @@ def get(self, task_id):
5256
task = task_dict.get(task_id)
5357

5458
return ActionSchema().dump(task)
59+
get.responses = {
60+
"200": {
61+
"description": "Action object",
62+
"content": {
63+
"application/json": {
64+
"schema": ActionSchema
65+
}
66+
}
67+
},
68+
"404": {
69+
"description": "Action not found"
70+
}
71+
}
5572

5673
@use_args({"timeout": fields.Int()})
5774
def delete(self, args, task_id):
5875
"""Cancel a running Action
59-
---
60-
description: Cancel an Action
61-
summary: Cancel an Action
62-
responses:
63-
200:
64-
content:
65-
application/json:
66-
schema: ActionSchema
76+
77+
A `DELETE` request will stop a running action.
6778
"""
6879
timeout = args.get("timeout", None)
6980
task_dict = current_labthing().actions.to_dict()
@@ -74,3 +85,16 @@ def delete(self, args, task_id):
7485
task = task_dict.get(task_id)
7586
task.stop(timeout=timeout)
7687
return ActionSchema().dump(task)
88+
delete.responses = {
89+
"200": {
90+
"description": "Action object that was cancelled",
91+
"content": {
92+
"application/json": {
93+
"schema": ActionSchema
94+
}
95+
}
96+
},
97+
"404": {
98+
"description": "Action not found"
99+
}
100+
}

src/labthings/default_views/extensions.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ def get(self):
1414
1515
Returns a list of Extension representations, including basic documentation.
1616
Describes server methods, web views, and other relevant Lab Things metadata.
17-
---
18-
description: Extensions list
19-
summary: Extensions list
20-
responses:
21-
200:
22-
content:
23-
application/json:
24-
schema: ExtensionSchema
2517
"""
2618
return ExtensionSchema(many=True).dump(registered_extensions().values() or [])
19+
20+
get.responses = {
21+
"200": {
22+
"description": "A list of available extensions and their properties",
23+
"content": {
24+
"application/json":{
25+
"schema": ExtensionSchema
26+
}
27+
}
28+
}
29+
}

src/labthings/default_views/root.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@ def get(self):
1212
summary: Thing Description
1313
"""
1414
return current_labthing().thing_description.to_dict()
15+
16+
get.summary = "Thing Description"
17+
get.description = (
18+
"A W3C compliant Thing Description is a JSON representation\n"
19+
"of the API, including links to different endpoints.\n"
20+
"You can browse it directly (e.g. in Firefox), though for \n"
21+
"interactive API documentation you should try the swagger-ui \n"
22+
"docs, at `docs/swagger-ui/`"
23+
)
24+
get.responses = {
25+
"200": {
26+
"description": "W3C Thing Description",
27+
"content": {"application/json":{}},
28+
}
29+
}

src/labthings/views/builder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ def _get(_, path=""):
3636
return abort(404)
3737
return send_file(indexes[0])
3838

39+
_get.summary = "Serve static files"
40+
_get.description = "Files and folders within this path will be served from a static directory."
41+
_get.responses = {
42+
"200": {
43+
"description": "Static file",
44+
},
45+
"404": {
46+
"description": "Static file not found",
47+
},
48+
}
49+
3950
# Generate a basic property class
4051
generated_class = type(name, (View, object), {"get": _get})
4152

0 commit comments

Comments
 (0)