Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where metadata was being incorrectly modified before being sent to the API #571

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Fix issue where metadata was being incorrectly modified before being sent to the API

### 7.5.1 / 2024-07-09
* Added collective availability method
* Fix crash when timeout encountered
Expand Down
2 changes: 1 addition & 1 deletion src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default class APIClient {

if (optionParams.body) {
requestOptions.body = JSON.stringify(
objKeysToSnakeCase(optionParams.body)
objKeysToSnakeCase(optionParams.body, ['metadata']) // metadata should remain as is
);
requestOptions.headers['Content-Type'] = 'application/json';
}
Expand Down
23 changes: 23 additions & 0 deletions tests/apiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ describe('APIClient', () => {
)
);
});

it('should not convert metadata object keys to snake_case', () => {
const metadata = {
key0: 'value',
key1: 'another',
camelCase: true,
snake_case: false,
normal: 'yes',
};
const expectedBody = JSON.stringify({
metadata: metadata,
});

const options = client.requestOptions({
path: '/test',
method: 'POST',
body: {
metadata: metadata,
},
});

expect(options.body).toEqual(expectedBody);
});
});

describe('newRequest', () => {
Expand Down
Loading