From e980d785749359f1af0d534980967322bddf4b0a Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 26 Nov 2024 10:47:56 +0100 Subject: [PATCH 1/5] fix!: use correct action names in TDD Thing Description --- tdd/data/tdd-description.json | 6 +++--- tdd/tests/data/tdd-description.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tdd/data/tdd-description.json b/tdd/data/tdd-description.json index 2334c15..42450ad 100644 --- a/tdd/data/tdd-description.json +++ b/tdd/data/tdd-description.json @@ -10,7 +10,7 @@ "security": "no_sec", "base": "{{TD_REPO_URL}}", "actions": { - "createTD": { + "createThing": { "description": "Create a Thing Description", "uriVariables": { "id": { @@ -63,7 +63,7 @@ } ] }, - "updateTD": { + "updateThing": { "description": "Update a Thing Description", "uriVariables": { "id": { @@ -109,7 +109,7 @@ } ] }, - "deleteTD": { + "deleteThing": { "description": "Delete a Thing Description", "uriVariables": { "id": { diff --git a/tdd/tests/data/tdd-description.json b/tdd/tests/data/tdd-description.json index f5db1e0..b8e3902 100644 --- a/tdd/tests/data/tdd-description.json +++ b/tdd/tests/data/tdd-description.json @@ -10,7 +10,7 @@ "security": "no_sec", "base": "http://localhost:5050", "actions": { - "createTD": { + "createThing": { "description": "Create a Thing Description", "uriVariables": { "id": { @@ -63,7 +63,7 @@ } ] }, - "updateTD": { + "updateThing": { "description": "Update a Thing Description", "uriVariables": { "id": { @@ -109,7 +109,7 @@ } ] }, - "deleteTD": { + "deleteThing": { "description": "Delete a Thing Description", "uriVariables": { "id": { From 7b55dcf7a9905c092f966127a8b708e7260767a5 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 26 Nov 2024 10:59:21 +0100 Subject: [PATCH 2/5] fix!: use correct property names in TDD Thing Description --- tdd/data/tdd-description.json | 4 ++-- tdd/tests/data/tdd-description.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tdd/data/tdd-description.json b/tdd/data/tdd-description.json index 42450ad..9208e7e 100644 --- a/tdd/data/tdd-description.json +++ b/tdd/data/tdd-description.json @@ -139,7 +139,7 @@ } }, "properties": { - "retrieveTD": { + "retrieveThing": { "description": "Retrieve a Thing Description", "uriVariables": { "id": { @@ -168,7 +168,7 @@ } ] }, - "retrieveTDs": { + "things": { "description": "Retrieve Thing Descriptions in batch", "uriVariables": { "format": { diff --git a/tdd/tests/data/tdd-description.json b/tdd/tests/data/tdd-description.json index b8e3902..5b66150 100644 --- a/tdd/tests/data/tdd-description.json +++ b/tdd/tests/data/tdd-description.json @@ -139,7 +139,7 @@ } }, "properties": { - "retrieveTD": { + "retrieveThing": { "description": "Retrieve a Thing Description", "uriVariables": { "id": { @@ -168,7 +168,7 @@ } ] }, - "retrieveTDs": { + "things": { "description": "Retrieve Thing Descriptions in batch", "uriVariables": { "format": { From f197ae74a0f4ae82149a61952807c0c802a56328 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 26 Nov 2024 11:07:37 +0100 Subject: [PATCH 3/5] fix!: add workaround for invalid Content-Type in response objects --- tdd/__init__.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tdd/__init__.py b/tdd/__init__.py index f5240da..f626852 100644 --- a/tdd/__init__.py +++ b/tdd/__init__.py @@ -68,6 +68,36 @@ TD_TRANSFORMERS = [] +def apply_response_content_type_fix(thing_description): + """ + This function applies the workaround described in WoT Discovery issue + https://github.com/w3c/wot-discovery/issues/465 to let the TD exposed + by the TDD pass JSON Schema validation. + + The workaround is needed since in the TD specification the contentType field + in the "response" objects has been defined as mandatory without providing a + default, making the TD for TDDs included in the Discovery Recommendation + invalid (also see https://github.com/w3c/wot-thing-description/issues/1780). + This issue should probably be fixed in the 2.0 version of the TD + specification, which render this workaround obsolete. + """ + actionsToFix = ["createThing", "updateThing", "deleteThing"] + + print(thing_description["actions"].keys()) + for key in actionsToFix: + + forms = thing_description["actions"].get(key, {}).get("forms", []) + + for form in forms: + response = form.get("response") + + if response is None: + continue + + if response.get("contentType") is None: + response["contentType"] = "application/x-empty" + + def wait_for_sparqlendpoint(): test_num = 0 while test_num < LIMIT_SPARQLENDPOINT_TEST: @@ -171,6 +201,7 @@ def directory_description(): with files(__package__).joinpath("data/tdd-description.json").open() as strm: tdd_description = json.load(strm) tdd_description["base"] = CONFIG["TD_REPO_URL"] + apply_response_content_type_fix(tdd_description) return Response( json.dumps(tdd_description), content_type="application/td+json" ) From e51b12d0fda49ef93f23705ac612ebc8e749d186 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 26 Nov 2024 11:29:26 +0100 Subject: [PATCH 4/5] test: fix coffee machine file names --- tdd/tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tdd/tests/conftest.py b/tdd/tests/conftest.py index 577da15..c7a1a1a 100644 --- a/tdd/tests/conftest.py +++ b/tdd/tests/conftest.py @@ -98,13 +98,13 @@ def custom(self, request, **kwargs): @pytest.fixture def mock_sparql_with_one_td(httpx_mock): - graph = SparqlGraph("smart_coffe_machine_init.nquads") + graph = SparqlGraph("smart_coffee_machine_init.nquads") httpx_mock.add_callback(graph.custom) @pytest.fixture def mock_sparql_with_one_expired_td(httpx_mock): - graph = SparqlGraph("smart_coffe_machine_expired.nquads") + graph = SparqlGraph("smart_coffee_machine_expired.nquads") httpx_mock.add_callback(graph.custom) From 48ddc1c56afc681061dfdd7770175c7058025573 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 26 Nov 2024 13:01:14 +0100 Subject: [PATCH 5/5] fix: make /things URI query parameters optional --- tdd/data/tdd-description.json | 2 +- tdd/tests/data/tdd-description.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tdd/data/tdd-description.json b/tdd/data/tdd-description.json index 9208e7e..e449407 100644 --- a/tdd/data/tdd-description.json +++ b/tdd/data/tdd-description.json @@ -187,7 +187,7 @@ }, "forms": [ { - "href": "/things?format={format}&offset={offset}&limit={limit}", + "href": "/things{?offset,limit,format}", "htv:methodName": "GET", "response": { "description": "Success response", diff --git a/tdd/tests/data/tdd-description.json b/tdd/tests/data/tdd-description.json index 5b66150..4ef0259 100644 --- a/tdd/tests/data/tdd-description.json +++ b/tdd/tests/data/tdd-description.json @@ -187,7 +187,7 @@ }, "forms": [ { - "href": "/things?format={format}&offset={offset}&limit={limit}", + "href": "/things{?offset,limit,format}", "htv:methodName": "GET", "response": { "description": "Success response",