Skip to content

Commit 45bb9df

Browse files
author
Joel Collins
committed
Remove reliance on OpenAPI spec for Thing Description
1 parent e80d880 commit 45bb9df

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/labthings/td.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@ def view_to_thing_action_forms(rules: list, view: View):
2626

2727
# Get input content_type
2828
content_type = getattr(view, "content_type", "application/json")
29-
30-
# See if the action has an unusual 200 response
31-
responses = view.get_apispec().get("post", {}).get("responses", {})
32-
response_content_type = "application/json" # Default assumed content_type
33-
34-
for response_code in (200, 201):
35-
if response_code in responses and responses[response_code].get(
36-
"content_type"
37-
):
38-
response_content_type = responses[response_code].get("content_type")
39-
break
29+
response_content_type = getattr(
30+
view, "response_content_type", "application/json"
31+
)
4032

4133
for url in prop_urls:
4234
form = {
@@ -46,7 +38,7 @@ def view_to_thing_action_forms(rules: list, view: View):
4638
"contentType": content_type,
4739
}
4840
if response_content_type != content_type:
49-
form["responses"] = {"contentType": response_content_type}
41+
form["response"] = {"contentType": response_content_type}
5042

5143
forms.append(form)
5244

@@ -74,14 +66,6 @@ def view_to_thing_property_forms(rules: list, view: View):
7466
# See if the property has an unusual 201 response
7567
# TODO: Do this per-method
7668
responses = view.get_apispec().get("get", {}).get("responses", {})
77-
response_content_type = "application/json" # Default assumed content_type
78-
79-
for response_code in (201, 200):
80-
if response_code in responses and responses[response_code].get("content_type"):
81-
response_content_type = responses[response_code].get("content_type")
82-
break
83-
84-
# TODO: Clean up repeated code
8569

8670
# HTTP readproperty requires GET method
8771
if hasattr(view, "get"):
@@ -91,10 +75,7 @@ def view_to_thing_property_forms(rules: list, view: View):
9175
"htv:methodName": "GET",
9276
"href": url,
9377
"contentType": content_type,
94-
"response": {"contentType": response_content_type},
9578
}
96-
if response_content_type != content_type:
97-
form["responses"] = {"contentType": response_content_type}
9879
forms.append(form)
9980

10081
# HTTP writeproperty requires PUT method
@@ -105,10 +86,7 @@ def view_to_thing_property_forms(rules: list, view: View):
10586
"htv:methodName": "PUT",
10687
"href": url,
10788
"contentType": content_type,
108-
"response": {"contentType": response_content_type},
10989
}
110-
if response_content_type != content_type:
111-
form["responses"] = {"contentType": response_content_type}
11290
forms.append(form)
11391

11492
# HTTP writeproperty may use POST method
@@ -119,10 +97,7 @@ def view_to_thing_property_forms(rules: list, view: View):
11997
"htv:methodName": "POST",
12098
"href": url,
12199
"contentType": content_type,
122-
"response": {"contentType": response_content_type},
123100
}
124-
if response_content_type != content_type:
125-
form["responses"] = {"contentType": response_content_type}
126101
forms.append(form)
127102

128103
return forms

0 commit comments

Comments
 (0)