UNPKG

ng-openapi-gen

Version:

An OpenAPI 3.0 and 3.1 codegen for Angular 16+

76 lines 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenType = void 0; const gen_utils_1 = require("./gen-utils"); const imports_1 = require("./imports"); const openapi_typings_1 = require("./openapi-typings"); /** * Base definitions of a generated type */ class GenType { constructor(name, typeNameTransform, options) { this.name = name; this.options = options; this._additionalDependencies = new Set(); this.typeName = typeNameTransform(name, options); this.namespace = (0, gen_utils_1.namespace)(name); this.fileName = (0, gen_utils_1.fileName)(this.typeName); this.qualifiedName = this.typeName; if (this.namespace) { this.fileName = this.namespace + '/' + this.fileName; this.qualifiedName = (0, gen_utils_1.typeName)(this.namespace, options) + this.typeName; } this._imports = new imports_1.Imports(options, this.typeName); } addImport(param, typeOnly) { if (param && !this.skipImport(param)) { this._imports.add(param, !!typeOnly); } } updateImports() { this.pathToRoot = this.initPathToRoot(); this.imports = this._imports.toArray(); for (const imp of this.imports) { imp.path = this.pathToRoot + imp.path; } this.additionalDependencies = [...this._additionalDependencies]; } collectImports(schema, additional = false, processOneOf = false) { if (!schema) { return; } else if ((0, openapi_typings_1.isReferenceObject)(schema)) { const dep = (0, gen_utils_1.simpleName)(schema.$ref); if (additional) { this._additionalDependencies.add(dep); } else { this.addImport(dep); } } else { schema = schema; (schema.oneOf || []).forEach(i => this.collectImports(i, additional)); (schema.allOf || []).forEach(i => this.collectImports(i, additional)); (schema.anyOf || []).forEach(i => this.collectImports(i, additional)); if (processOneOf) { (schema.oneOf || []).forEach(i => this.collectImports(i, additional)); } if ((0, openapi_typings_1.isArraySchemaObject)(schema) && 'items' in schema) { this.collectImports(schema.items, additional); } if (schema.properties) { const properties = schema.properties; Object.keys(properties).forEach(p => { const prop = properties[p]; this.collectImports(prop, additional, true); }); } if (typeof schema.additionalProperties === 'object') { this.collectImports(schema.additionalProperties, additional); } } } } exports.GenType = GenType; //# sourceMappingURL=gen-type.js.map