Skip to content

Commit

Permalink
fix: added support for default output prop in operation (twilio#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
kridai committed Feb 2, 2022
1 parent 0a013aa commit 8ae4ba5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/services/twilio-api/api-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class TwilioApiBrowser {
return apiSpec;
}

updateTwilioVendorExtensionProperty(input) {
Object.entries(input).forEach(([key, value]) => {
if (key === 'x-twilio') {
Object.entries(value).forEach(([subKey, subValue]) => {
input[subKey] = subValue;
});
delete input[key];
}
});
}

loadDomains(obj) {
// Clone the spec since we'll be modifying it.
const domains = JSON.parse(JSON.stringify(obj));
Expand All @@ -71,6 +82,7 @@ class TwilioApiBrowser {
OPERATIONS.forEach((operationName) => {
if (operationName in path) {
const operation = path[operationName];
this.updateTwilioVendorExtensionProperty(operation);
path.operations[operationName] = operation;
delete path[operationName];

Expand All @@ -87,14 +99,7 @@ class TwilioApiBrowser {
});

// Lift the Twilio vendor extension properties.
Object.entries(path).forEach(([key, value]) => {
if (key === 'x-twilio') {
Object.entries(value).forEach(([subKey, subValue]) => {
path[subKey] = subValue;
});
delete path[key];
}
});
this.updateTwilioVendorExtensionProperty(path);
});
});

Expand Down
41 changes: 41 additions & 0 deletions test/services/twilio-api/api-browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,47 @@ describe('services', () => {
},
});
});

test.it('lift twilio vendor extension property', () => {
const browser = new TwilioApiBrowser({
api: {
paths: {
'/v2/Services/{ServiceSid}/Entities/{Identity}/Factors.json': {
servers: [
{
url: 'https://api.twilio.com',
},
],
get: {
listStuff: '',
},
post: {
createStuff: '',
'x-twilio': { defaultOutputProperties: ['sid', 'status', 'binding'] },
},
description: '',
'x-twilio': { defaultOutputProperties: ['sid', 'status'] },
},
},
},
});

expect(browser.domains).to.deep.equal({
api: {
paths: {
'/v2/Services/{ServiceSid}/Entities/{Identity}/Factors.json': {
operations: {
post: { createStuff: '', defaultOutputProperties: ['sid', 'status', 'binding'] },
get: { listStuff: '' },
},
server: 'https://api.twilio.com',
description: '',
defaultOutputProperties: ['sid', 'status'],
},
},
},
});
});
});
});
});

0 comments on commit 8ae4ba5

Please sign in to comment.