Skip to content

Commit 8ae4ba5

Browse files
authored
fix: added support for default output prop in operation (#192)
1 parent 0a013aa commit 8ae4ba5

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

src/services/twilio-api/api-browser.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ class TwilioApiBrowser {
5454
return apiSpec;
5555
}
5656

57+
updateTwilioVendorExtensionProperty(input) {
58+
Object.entries(input).forEach(([key, value]) => {
59+
if (key === 'x-twilio') {
60+
Object.entries(value).forEach(([subKey, subValue]) => {
61+
input[subKey] = subValue;
62+
});
63+
delete input[key];
64+
}
65+
});
66+
}
67+
5768
loadDomains(obj) {
5869
// Clone the spec since we'll be modifying it.
5970
const domains = JSON.parse(JSON.stringify(obj));
@@ -71,6 +82,7 @@ class TwilioApiBrowser {
7182
OPERATIONS.forEach((operationName) => {
7283
if (operationName in path) {
7384
const operation = path[operationName];
85+
this.updateTwilioVendorExtensionProperty(operation);
7486
path.operations[operationName] = operation;
7587
delete path[operationName];
7688

@@ -87,14 +99,7 @@ class TwilioApiBrowser {
8799
});
88100

89101
// Lift the Twilio vendor extension properties.
90-
Object.entries(path).forEach(([key, value]) => {
91-
if (key === 'x-twilio') {
92-
Object.entries(value).forEach(([subKey, subValue]) => {
93-
path[subKey] = subValue;
94-
});
95-
delete path[key];
96-
}
97-
});
102+
this.updateTwilioVendorExtensionProperty(path);
98103
});
99104
});
100105

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

+41
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,47 @@ describe('services', () => {
151151
},
152152
});
153153
});
154+
155+
test.it('lift twilio vendor extension property', () => {
156+
const browser = new TwilioApiBrowser({
157+
api: {
158+
paths: {
159+
'/v2/Services/{ServiceSid}/Entities/{Identity}/Factors.json': {
160+
servers: [
161+
{
162+
url: 'https://api.twilio.com',
163+
},
164+
],
165+
get: {
166+
listStuff: '',
167+
},
168+
post: {
169+
createStuff: '',
170+
'x-twilio': { defaultOutputProperties: ['sid', 'status', 'binding'] },
171+
},
172+
description: '',
173+
'x-twilio': { defaultOutputProperties: ['sid', 'status'] },
174+
},
175+
},
176+
},
177+
});
178+
179+
expect(browser.domains).to.deep.equal({
180+
api: {
181+
paths: {
182+
'/v2/Services/{ServiceSid}/Entities/{Identity}/Factors.json': {
183+
operations: {
184+
post: { createStuff: '', defaultOutputProperties: ['sid', 'status', 'binding'] },
185+
get: { listStuff: '' },
186+
},
187+
server: 'https://api.twilio.com',
188+
description: '',
189+
defaultOutputProperties: ['sid', 'status'],
190+
},
191+
},
192+
},
193+
});
194+
});
154195
});
155196
});
156197
});

0 commit comments

Comments
 (0)