UNPKG

swagger-typescript-generator

Version:

Generate typescript code from swagger.json. Before start this project I try use [swagger-typescript-codegen](https://github.com/mtennoe/swagger-typescript-codegen) based on [mustache templates](https://github.com/mtennoe/swagger-js-codegen/tree/master/lib

91 lines 3.82 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { 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.SwaggerModelProperty = void 0; var swagger_base_1 = require("./swagger-base"); var model_type_1 = require("./model-type"); var SwaggerModelProperty = /** @class */ (function (_super) { __extends(SwaggerModelProperty, _super); function SwaggerModelProperty(parent, name, source, required) { var _this = _super.call(this) || this; _this.name = ""; _this.source = source; _this.parent = parent; _this.modelType = new model_type_1.ModelType(_this.config); _this.name = name; _this.maxNumber = source.maximum !== undefined ? source.maximum : undefined; _this.minNumber = source.minimum !== undefined ? source.minimum : undefined; _this.description = source.description !== undefined ? source.description : undefined; _this.modelType.isEnum = _this.utils.isEnum(source) ? true : undefined; _this.modelType.type = _this.utils.getModelPropertyType(_this, source); _this.modelType.isJsType = _this.utils.isJsType(_this.modelType.type); _this.modelType.isArray = _this.utils.isArray(source) ? true : undefined; _this.required = required; if (_this.modelType.isEnum) { _this.modelType.enumValues = _this.utils.getEnumValues(source); } if (_this.modelType.isArray) { var type = _this.utils.getArrayItemType(source); _this.modelType.arrayItemType = type || undefined; } return _this; } SwaggerModelProperty.prototype.init = function () { if (this.modelType.isEnum) { this.initEnumRef(); } if (!this.modelType.isEnum && !this.modelType.isJsType) { this.initModelRef(); } }; SwaggerModelProperty.prototype.initEnumRef = function () { var _this = this; var fullName = this.parent.name + "." + this.utils.getEnumName(this.name); var enumName = this.utils.getEnumName(this.name); var enumRef = this.doc.enums.find(function (f) { return f.getFullName === fullName || f.getFullName === _this.name || f.name === enumName; }); if (enumRef) { this.modelType.enumRef = enumRef; } else { console.error("Enum not found [model property] = " + this.name + ", [fullName=]" + fullName + " [model name] = " + this.parent.name); } }; SwaggerModelProperty.prototype.initModelRef = function () { var _this = this; var modelRef = this.doc.models.find(function (f) { return f.name === _this.modelType.type || f.name === _this.modelType.arrayItemType; }); if (modelRef) { this.modelType.modelRef = modelRef; } else { console.error("Model not found into swagger-def-model " + this.modelType.type); } }; return SwaggerModelProperty; }(swagger_base_1.SwaggerBase)); exports.SwaggerModelProperty = SwaggerModelProperty; //# sourceMappingURL=swagger-model-property.js.map