Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: splitting openAPI specs by version #104

Merged
merged 9 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
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
Loading