Skip to content

Commit

Permalink
fix: Allow axios data property to be an array
Browse files Browse the repository at this point in the history
Closes #1158
  • Loading branch information
SamTolmay committed Feb 17, 2023
1 parent 6fb9578 commit 9b83af5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/docs/connections/AxiosHttp.yaml
Expand Up @@ -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`
Expand Down
Expand Up @@ -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 });
});
Expand Up @@ -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',
Expand Down

0 comments on commit 9b83af5

Please sign in to comment.