Skip to content

Commit

Permalink
fix!: add workaround for invalid Content-Type in response objects
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Nov 26, 2024
1 parent 7d9bbf2 commit 3b0a3c7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 the contentType field in the TD
specification 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
Expand Down Expand Up @@ -174,6 +204,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"
)
Expand Down

0 comments on commit 3b0a3c7

Please sign in to comment.