Add support of array in querystring (#1914)

*  Add support of array in querystring

In the HTTP Request node, a parameter that appeared multiple times with the same name will be converted into an array.
Any parameters that appeared only once will be kept in the form of a string for backward compatibility.

*  Prefer spread operator
This commit is contained in:
Kaito Udagawa 2021-07-11 06:51:35 +09:00 committed by GitHub
parent 922880f93d
commit 800e5ec97f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -811,8 +811,23 @@ export class HttpRequest implements INodeType {
// @ts-ignore
requestOptions[optionName] = {};
for (const parameterData of setUiParameter!.parameter as IDataObject[]) {
// @ts-ignore
requestOptions[optionName][parameterData!.name as string] = parameterData!.value;
const parameterDataName = parameterData!.name as string;
const newValue = parameterData!.value;
if (optionName === 'qs') {
const computeNewValue = (oldValue: unknown) => {
if (typeof oldValue === 'string') {
return [oldValue, newValue];
} else if (Array.isArray(oldValue)) {
return [...oldValue, newValue];
} else {
return newValue;
}
};
requestOptions[optionName][parameterDataName] = computeNewValue(requestOptions[optionName][parameterDataName]);
} else {
// @ts-ignore
requestOptions[optionName][parameterDataName] = newValue;
}
}
}
}