mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-11 11:26:37 +03:00
45 lines
808 B
JavaScript
45 lines
808 B
JavaScript
|
'use strict';
|
||
|
import SwaggerParser from 'swagger-parser';
|
||
|
|
||
|
export class SchemaManager {
|
||
|
constructor() {
|
||
|
if (SchemaManager.prototype._instance) {
|
||
|
return SchemaManager.prototype._instance;
|
||
|
}
|
||
|
|
||
|
SchemaManager.prototype._instance = this;
|
||
|
|
||
|
this._schema = {};
|
||
|
}
|
||
|
|
||
|
static instance() {
|
||
|
return new SchemaManager();
|
||
|
}
|
||
|
|
||
|
load(url) {
|
||
|
let promise = new Promise((resolve, reject) => {
|
||
|
this._schema = {};
|
||
|
|
||
|
SwaggerParser.bundle(url)
|
||
|
.then(
|
||
|
(schema) => {
|
||
|
this._schema = schema;
|
||
|
resolve(this._schema);
|
||
|
},
|
||
|
(err) => reject(err)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
return promise;
|
||
|
}
|
||
|
|
||
|
get schema() {
|
||
|
// TODO: consider returning promise
|
||
|
return this._schema;
|
||
|
}
|
||
|
|
||
|
getByJsonPath(/* path */) {
|
||
|
//TODO: implement
|
||
|
}
|
||
|
}
|