-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Describe the bug.
I am trying out generating a template for the example mqtt document . I was testing the subscribe function registerReceiveLightMeasurementMiddleware
and it seems that the message's payload is not parsed from string to object, it stays as string. There is also no validation.
I can't also parse it manually either, it will give an error due to it not being a valid JSON object string.
Expected behavior
1- message.payload
should be parsed into an object, respecting that the type is specified to object in the asyncapi document.
2- There should be validation for the payload.
Screenshots
How to Reproduce
1- Copy the linked AsyncAPI document to a new folder.
2- Generate a nodejs template from the file.
3- Copy the example script, add to the callback of client.registerReceiveLightMeasurementMiddleware
: console.log(typeof message.payload)
.
4- Try it out, for example: npx mqtt pub -t 'smartylighting/streetlights/1/0/event/101/lighting/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": 3}'
5- It will output string
. You also can't use JSON.parse
to parse it. There is also no validation to the message, you can send anything.
🖥️ Device Information [optional]
No response
👀 Have you checked for similar open issues?
- I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to work on this issue ?
None