From 9b83af5e0fa0600ff39b1c317fbce7e5be2a17a0 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2023 11:11:46 +0200 Subject: [PATCH] fix: Allow axios data property to be an array Closes #1158 --- packages/docs/connections/AxiosHttp.yaml | 2 +- .../connections/AxiosHttp/AxiosHttp.test.js | 18 ++++++++++++++++++ .../src/connections/AxiosHttp/schema.js | 6 +----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/docs/connections/AxiosHttp.yaml b/packages/docs/connections/AxiosHttp.yaml index a8cac3a16e..262fe2ef97 100644 --- a/packages/docs/connections/AxiosHttp.yaml +++ b/packages/docs/connections/AxiosHttp.yaml @@ -58,7 +58,7 @@ _ref: - `baseURL: string`: `baseURL` will be prepended to `url` unless `url` is absolute. It can be convenient to set `baseURL` for an axios connection to pass relative URLs to requests or mutations using that connection. - `headers: object`: An object with custom headers to be sent sent with the request. The object keys should be header names, and the values should be the string header values. - `params: object`: An object with URL parameters to be sent with the request. - - `data: string | object`: The data to be sent as the request body. Only applicable for request methods `'put'`, `'post'`, and `'patch'`. Can be an object or a string in the format `'Country=Brasil&City=Belo Horizonte'`. + - `data: string | object | array`: The data to be sent as the request body. Only applicable for request methods `'put'`, `'post'`, and `'patch'`. Can be an object, array or a string in the format `'Country=Brasil&City=Belo Horizonte'`. - `auth: object`: Indicates that HTTP Basic authorization should be used, and supplies credentials. This will set an `Authorization` header, overwriting any existing `Authorization` custom headers you have set using `headers`. Only HTTP Basic auth is configurable through this parameter, for Bearer tokens and such, use `Authorization` custom headers instead. The `auth` object should have the following fields: - `username: string` - `password: string` diff --git a/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/AxiosHttp.test.js b/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/AxiosHttp.test.js index a8ef1ec5f5..7f00eb6966 100644 --- a/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/AxiosHttp.test.js +++ b/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/AxiosHttp.test.js @@ -69,3 +69,21 @@ test('url is not a string', () => { 'AxiosHttp property "url" should be a string.' ); }); + +test('data is a string', () => { + const connection = { + method: 'post', + url: 'https://example.com/api', + data: 'value', + }; + expect(validate({ schema, data: connection })).toEqual({ valid: true }); +}); + +test('data is an array', () => { + const connection = { + method: 'post', + url: 'https://example.com/api', + data: [{ key: 'value' }], + }; + expect(validate({ schema, data: connection })).toEqual({ valid: true }); +}); diff --git a/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/schema.js b/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/schema.js index a797e970b9..8902416de0 100644 --- a/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/schema.js +++ b/packages/plugins/connections/connection-axios-http/src/connections/AxiosHttp/schema.js @@ -59,12 +59,8 @@ export default { }, }, data: { - type: ['string', 'object'], description: - "The data to be sent as the request body. Only applicable for request methods 'put', 'post', and 'patch'. Can be an object or a string in the format 'Country=USA&City=New York'.", - errorMessage: { - type: 'AxiosHttp property "data" should be an object or string.', - }, + "The data to be sent as the request body. Only applicable for request methods 'put', 'post', and 'patch'. Can be an object, array or a string in the format 'Country=USA&City=New York'.", }, timeout: { type: 'number',