Skip to content

Commit

Permalink
feat: splitting openAPI specs by version (twilio#104)
Browse files Browse the repository at this point in the history
* 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 <sradhakrishna@twilio.com>
  • Loading branch information
shwetha-manvinkurke and shwetharadhakrishna authored Dec 1, 2020
1 parent 3757872 commit 4a8ee37
Show file tree
Hide file tree
Showing 34 changed files with 10,126 additions and 9,944 deletions.
23 changes: 22 additions & 1 deletion src/services/twilio-api/api-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ const OPERATIONS = ['post', 'get', 'delete'];
class TwilioApiBrowser {
constructor(spec) {
spec = spec || this.loadApiSpecFromDisk();

spec = this.mergeVersions(spec);
this.domains = this.loadDomains(spec);
}

mergeVersions(spec) {
// merge the domain_versions into a single domain
const mergedSpec = {};
for (const domainNameWithVersion in spec) {
if (spec.hasOwnProperty(domainNameWithVersion)) {
const domainName = domainNameWithVersion.split('_')[0];
if (domainName in mergedSpec) {
const existing = mergedSpec[domainName];
const current = spec[domainNameWithVersion];
Object.assign(existing.components.schemas, current.components.schemas);
Object.assign(existing.paths, current.paths);
mergedSpec[domainName] = existing;
} else {
mergedSpec[domainName] = spec[domainNameWithVersion];
}
}
}

return mergedSpec;
}

loadApiSpecFromDisk() {
if (!apiSpec) {
const specPattern = /twilio_(.+)\.json/;
Expand Down
File renamed without changes.
Loading

0 comments on commit 4a8ee37

Please sign in to comment.