openapi-graph-core
Version:
A TS library to manage large API projects defined by OpenAPIv3 specification.
34 lines (33 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenAPIGraphsBuilder = void 0;
const _1 = require(".");
const openapi_graph_types_1 = require("openapi-graph-types");
const OpenAPIGraph_1 = require("../OpenAPIGraph");
const utils_1 = require("../../utils");
const OpenAPIGraphsBuilder = class OpenAPIGraphsBuilderImpl {
constructor(apis) {
this.graphs = this.initializeGraph(apis);
}
initializeGraph(apis) {
const graphs = {};
apis.forEach((api) => {
const graph = new OpenAPIGraph_1.OpenAPIGraph(api.path);
graph.setSchemaNodes(this.getSchemaNodes(api));
graphs[api.path] = graph;
});
Object.keys(graphs).map((graphKey, i) => {
graphs[graphKey].setRefEdges(this.getRefEdges(graphs, apis[i]));
});
return graphs;
}
getSchemaNodes(api) {
return _1.getSchemaNodes(api.content);
}
getRefEdges(graphs, api) {
const edges = _1.getRefEdges(api.content, api.path);
utils_1.log(`Found ${Object.values(edges.schemaRef).length} schema references in ${api.content.info.title}`, openapi_graph_types_1.LogLevel.DEBUG);
return _1.resolveReference(graphs, edges);
}
};
exports.OpenAPIGraphsBuilder = OpenAPIGraphsBuilder;