Skip to content

Commit 4a8ee37

Browse files
shwetha-manvinkurkeshwetharadhakrishna
and
shwetharadhakrishna
authored
feat: splitting openAPI specs by version (#104)
* Splitting API specs by version * Adding comments * Deleting preview.jsons * Updated with right version of api-definitions * Added test for mergeDomains func * Adding back preview.json * Added test for preview Co-authored-by: shwetharadhakrishna <[email protected]>
1 parent 3757872 commit 4a8ee37

34 files changed

+10126
-9944
lines changed

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,31 @@ const OPERATIONS = ['post', 'get', 'delete'];
99
class TwilioApiBrowser {
1010
constructor(spec) {
1111
spec = spec || this.loadApiSpecFromDisk();
12-
12+
spec = this.mergeVersions(spec);
1313
this.domains = this.loadDomains(spec);
1414
}
1515

16+
mergeVersions(spec) {
17+
// merge the domain_versions into a single domain
18+
const mergedSpec = {};
19+
for (const domainNameWithVersion in spec) {
20+
if (spec.hasOwnProperty(domainNameWithVersion)) {
21+
const domainName = domainNameWithVersion.split('_')[0];
22+
if (domainName in mergedSpec) {
23+
const existing = mergedSpec[domainName];
24+
const current = spec[domainNameWithVersion];
25+
Object.assign(existing.components.schemas, current.components.schemas);
26+
Object.assign(existing.paths, current.paths);
27+
mergedSpec[domainName] = existing;
28+
} else {
29+
mergedSpec[domainName] = spec[domainNameWithVersion];
30+
}
31+
}
32+
}
33+
34+
return mergedSpec;
35+
}
36+
1637
loadApiSpecFromDisk() {
1738
if (!apiSpec) {
1839
const specPattern = /twilio_(.+)\.json/;

0 commit comments

Comments
 (0)