From 8ae4ba5a418521d5877c7fc753ed08cee2a43f22 Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 2 Feb 2022 16:53:02 +0530 Subject: [PATCH] fix: added support for default output prop in operation (#192) --- src/services/twilio-api/api-browser.js | 21 ++++++---- test/services/twilio-api/api-browser.test.js | 41 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/services/twilio-api/api-browser.js b/src/services/twilio-api/api-browser.js index fee3f9d1..3ae6c061 100644 --- a/src/services/twilio-api/api-browser.js +++ b/src/services/twilio-api/api-browser.js @@ -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)); @@ -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]; @@ -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); }); }); diff --git a/test/services/twilio-api/api-browser.test.js b/test/services/twilio-api/api-browser.test.js index b7b6cf11..785ca05e 100644 --- a/test/services/twilio-api/api-browser.test.js +++ b/test/services/twilio-api/api-browser.test.js @@ -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'], + }, + }, + }, + }); + }); }); }); });