Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/services/twilio-api/api-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,32 @@ class TwilioApiBrowser {
if (path.description === undefined) path.description = '';
path.description = path.description.replace(/(\r\n|\n|\r)/gm, ' ');

// Resolve $ref in path-level parameters and merge into each operation.
const pathParams = (path.parameters || []).map((p) =>
p.$ref ? this.resolveParameterRef(p.$ref, spec) : p,
).filter(Boolean);
delete path.parameters;

// Move the operations into an operations object.
OPERATIONS.forEach((operationName) => {
if (operationName in path) {
const operation = path[operationName];
this.updateTwilioVendorExtensionProperty(operation);

// Resolve $ref in operation-level parameters.
if (operation.parameters) {
operation.parameters = operation.parameters.map((p) =>
p.$ref ? this.resolveParameterRef(p.$ref, spec) : p,
).filter(Boolean);
}

// Merge path-level parameters into the operation (operation-level takes precedence).
if (pathParams.length > 0) {
const opParamNames = new Set((operation.parameters || []).map((p) => p.name));
const merged = pathParams.filter((p) => !opParamNames.has(p.name));
operation.parameters = (operation.parameters || []).concat(merged);
}

path.operations[operationName] = operation;
delete path[operationName];

Expand All @@ -111,6 +132,16 @@ class TwilioApiBrowser {
return domains;
}

resolveParameterRef(ref, spec) {
// Resolve local $ref like "#/components/parameters/StoreId"
const parts = ref.replace(/^#\//, '').split('/');
let node = spec;
for (const part of parts) {
node = node && node[part];
}
return node || null;
}

requestPropertiesToParameters(requestBody) {
const parameters = [];
const content = (requestBody || {}).content || {};
Expand Down
8 changes: 6 additions & 2 deletions src/services/twilio-api/twilio-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ class TwilioApiClient {
async remove(opts) {
opts.method = 'delete';

const { statusCode } = await this.request(opts);
const { statusCode, body } = await this.request(opts);

return statusCode === 204;
/*
* APIs that return a body (e.g. 202 Accepted) surface it for the caller.
* Existing no-body APIs (204 No Content) continue to return true/false.
*/
return body || statusCode === 204;
}

async list(opts) {
Expand Down
Loading