UNPKG

@protocolnebula/ts-openapi-generator

Version:

Build API and models from Swagger/OpenAPI to use in any project type

57 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiStore = void 0; const models_util_1 = require("../utils/models.util"); class ApiStore { constructor() { this._apis = new Set(); } get apis() { return [...this._apis]; } get apisGrouped() { const groups = {}; for (const api of this.apis) { const group = api.groupName; if (!groups[group]) { groups[group] = [api]; } else { groups[group].push(api); } } return groups; } add(api) { if (!this._apis.has(api)) { this._apis.add(api); } else { throw `API ${api.verb.toUpperCase()} ${api.url} declared twice`; } } getByGroupName(groupName) { return this.apis.filter((api) => api.groupName === groupName); } getDependencesByGroupName(groupName, store) { return this.getDependencesFor(this.getByGroupName(groupName), store); } getDependencesFor(apiList, store) { const dependences = new Set(); for (const api of apiList) { api .getDependences(store) .forEach((apiElement) => dependences.add(apiElement)); } return (0, models_util_1.sortDependences)([...dependences]); } /** * Sort apis and store them sorted */ sort() { this._apis = new Set((0, models_util_1.sortApi)(this.apis)); return this; } } exports.ApiStore = ApiStore; //# sourceMappingURL=api.store.js.map