Skip to content

Commit

Permalink
fix: getParams when operation parameters is absent (twilio#103)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergiofbsilva authored Nov 24, 2020
1 parent 2c2273c commit 3757872
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/open-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OpenApiClient {

getParams(opts, operation) {
const params = {};
operation.parameters.forEach((parameter) => {
(operation.parameters || []).forEach((parameter) => {
/*
* Build the actual request params from the spec's query parameters. This
* effectively drops all params that are not in the spec.
Expand Down
18 changes: 18 additions & 0 deletions test/services/twilio-api/twilio-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,24 @@ describe('services', () => {
});
});

describe('absent operation parameters', () => {
test
.nock('https://conversations.twilio.com', (api) => {
api.get(`/v1/Configuration`).reply(200, {
// eslint-disable-next-line camelcase
account_sid: accountSid,
});
})
.it('can fetch', async () => {
const response = await apiClient.fetch({
domain: 'conversations',
path: '/v1/Configuration',
});

expect(response).to.eql({ accountSid });
});
});

describe('regional and edge support', () => {
const defaultRegionTest = test.nock('https://api.edge.us1.twilio.com', (api) => {
api.post(`/2010-04-01/Accounts/${accountSid}/Messages.json`).reply(201, {
Expand Down

0 comments on commit 3757872

Please sign in to comment.