node-red/node-red-nodegen

undefined queryParameters are still being added to request

dexterlabora opened this issue · 4 comments

It seems as though any request that supports query parameters is failing. If the query params are left undefined, they are still being added to the request URL, causing the API to fail.

I was able to determine this by sending the requests to a dev server. In the server logs, the request looks like this:

https://myapi/networks/L_1234567890/latencyStats?t0=[object Object]&t1=[object Object]&ssid=[object Object]&vlan=[object Object]&apTag=[object Object]&fields=[object Object]

Since no query parameters were actually specified in the node form, it should have just looked like this:

https://myapi/networks/L_1234567890/latencyStats

I was able to hack a fix for a single endpoint by commenting out the queryParam section:

// REMOVING queryParameters fixes* this call
    /*
    if (parameters["t0"] !== undefined) {
      queryParameters["t0"] = parameters["t0"];
    }
    ...
   queryParameters = mergeQueryParams(parameters, queryParameters);
  */

Tested with..

  • node v10.13.0
  • node-red v0.19 & v0.20

Other notes:

  • nodegen generated new library node with out error
  • swagger v2

btw, love this project and hoping to see its potential.

This is the current specification of the Node generator. The generated node automatically uses received msg.payload as value for the parameter if Node-RED user doesn't input the query parameter on node property UI. To customize the generated code, node developers can modify it as you mentioned.

If we need to change the current specification, I suggest that parameters on node property UI always have msg.payload as the default values like this screenshot.

msgpayload

@dexterlabora Can I close this issue?

@dexterlabora Thank you for your reply. Please keep posting your concerns if you encounter a problem. I'll close this issue.