Skip to content

Commit 3757872

Browse files
fix: getParams when operation parameters is absent (twilio#103)
This commit fixes a bug that happens when operation parameters are absent. Accordingly to OpenAPI spec, operation parameters are not mandatory, however the existing code was expecting it.
1 parent 2c2273c commit 3757872

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/services/open-api-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class OpenApiClient {
6161

6262
getParams(opts, operation) {
6363
const params = {};
64-
operation.parameters.forEach((parameter) => {
64+
(operation.parameters || []).forEach((parameter) => {
6565
/*
6666
* Build the actual request params from the spec's query parameters. This
6767
* effectively drops all params that are not in the spec.

test/services/twilio-api/twilio-client.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,24 @@ describe('services', () => {
317317
});
318318
});
319319

320+
describe('absent operation parameters', () => {
321+
test
322+
.nock('https://conversations.twilio.com', (api) => {
323+
api.get(`/v1/Configuration`).reply(200, {
324+
// eslint-disable-next-line camelcase
325+
account_sid: accountSid,
326+
});
327+
})
328+
.it('can fetch', async () => {
329+
const response = await apiClient.fetch({
330+
domain: 'conversations',
331+
path: '/v1/Configuration',
332+
});
333+
334+
expect(response).to.eql({ accountSid });
335+
});
336+
});
337+
320338
describe('regional and edge support', () => {
321339
const defaultRegionTest = test.nock('https://api.edge.us1.twilio.com', (api) => {
322340
api.post(`/2010-04-01/Accounts/${accountSid}/Messages.json`).reply(201, {

0 commit comments

Comments
 (0)