UNPKG

openapi-ts-generator

Version:

Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.

41 lines (40 loc) 2.07 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelGenerator = void 0; var _ = require("lodash"); var base_generator_1 = require("./base.generator"); var ModelGenerator = /** @class */ (function (_super) { __extends(ModelGenerator, _super); function ModelGenerator(options) { var _this = this; var _a, _b; _this = _super.call(this, options, options.genClasses ? (_a = options.templates) === null || _a === void 0 ? void 0 : _a.entity : (_b = options.templates) === null || _b === void 0 ? void 0 : _b.model) || this; _this.GeneratorName = 'ModelGenerator'; return _this; } ModelGenerator.prototype.generate = function (templateData) { var _this = this; var _a; var fileSuffix = this.generatorOptions.genClasses ? '.entity.ts' : '.model.ts'; (_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.filter(function (entity) { return !entity.isEnum; }).forEach(function (entity) { _super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name)).concat(fileSuffix), entity); }); }; return ModelGenerator; }(base_generator_1.BaseGenerator)); exports.ModelGenerator = ModelGenerator;