eclipse-thingweb / eclipse-thingweb/node-wot
Server should use serialization method specified in expectedResponse
- Dominant language
- TypeScript
- Stars
- 192
- Forks
- 100
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 6
Description
I'm trying to describe an action in a TD which has different input contentType and response contentType. According to the TD standard an InteractionAffordance has the field [forms](https://www.w3.org/TR/wot-thing-description10/#form) which has the optional field response of type [ExpectedResponse](https://www.w3.org/TR/wot-thing-description10/#expectedresponse). Here is an example TD:
```
actions: {
exampleaction: {
title: "Takes image with the mounted camera",
description: "there is a camera attached and if invoked will take an image",
input: {
type: "object",
testparam: {
type: "string"
}
},
forms: [{
op: "invokeaction",
contentType: "application/json",
response: {
contentType: "image/jpg"
}
}],
}
},
```
When I invoke this action the server uses the serialization application/json to send back the request. But it should use image/jpeg right? I'm rather new to the WoT topics. Furthermore, the client should throw an error since the expected response type doesn't match with the received response type(but this might be another issue).
I did some digging and this part seems responsible.
https://github.com/eclipse/thingweb.node-wot/blob/62106f4978d88a7cf70f3333ba801f00cdf4d929/packages/binding-http/src/http-server.ts#L700-L708
here the received contentType (line 704) was application/json. It's because of this:
https://github.com/eclipse/thingweb.node-wot/blob/62106f4978d88a7cf70f3333ba801f00cdf4d929/packages/core/src/protocol-helpers.ts#L87-L95
Apparently, it doesn't check for the response field and it's content Type. My suggestions how these could be solved (depending if the function getActionContentType() might be used elsewhere e.g. clientcode):
- Write an additional function getActionResponseContentType().
- write internal function checkForResponseType() which gives back bool value if a response type field exists in the forms.
- write an additional if/else check to see if there is a property response in the forms object. if yes, then take response ContentType
What do you think? Cab you observe the same behavior?
Contributor guide
Assessment
This issue has not been assessed yet.