UNPKG

ng-openapi-gen

Version:
58 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Imports = exports.Import = void 0; const gen_utils_1 = require("./gen-utils"); /** A general import */ class Import { constructor(name, typeName, qName, path, file, typeOnly) { this.name = name; this.typeName = typeName; this.qualifiedName = qName; this.useAlias = this.typeName !== this.qualifiedName; this.typeOnly = typeOnly; this.path = path; this.file = file; this.fullPath = `${this.path.split('/').filter(p => p.length).join('/')}/${this.file.split('/').filter(p => p.length).join('/')}`; this.importName = name; this.importPath = path; this.importFile = file; this.importTypeName = typeName; this.importQualifiedName = qName; } } exports.Import = Import; /** * Manages the model imports to be added to a generated file */ class Imports { constructor(options) { this.options = options; this._imports = new Map(); } /** * Adds an import */ add(param, typeOnly) { var _a, _b; let imp; if (typeof param === 'string') { // A model imp = new Import(param, (0, gen_utils_1.unqualifiedName)(param, this.options), (0, gen_utils_1.qualifiedName)(param, this.options), 'models/', (0, gen_utils_1.modelFile)(param, this.options), typeOnly); } else { // An Importable imp = new Import(param.importName, (_a = param.importTypeName) !== null && _a !== void 0 ? _a : param.importName, (_b = param.importQualifiedName) !== null && _b !== void 0 ? _b : param.importName, `${param.importPath}`, param.importFile, typeOnly); } this._imports.set(imp.name, imp); } toArray() { const array = [...this._imports.values()]; array.sort((a, b) => a.importName.localeCompare(b.importName, 'en')); return array; } get size() { return this._imports.size; } } exports.Imports = Imports; //# sourceMappingURL=imports.js.map