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
79 lines • 3.49 kB
JavaScript
;
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.SwaggerMethodParameter = exports.EParameterIn = void 0;
var swagger_base_1 = require("./swagger-base");
var model_type_1 = require("./model-type");
var EParameterIn;
(function (EParameterIn) {
EParameterIn["query"] = "query";
EParameterIn["body"] = "body";
EParameterIn["path"] = "path";
EParameterIn["formData"] = "formData";
})(EParameterIn = exports.EParameterIn || (exports.EParameterIn = {}));
var SwaggerMethodParameter = /** @class */ (function (_super) {
__extends(SwaggerMethodParameter, _super);
function SwaggerMethodParameter(parent, source) {
var _this = _super.call(this) || this;
_this.label = '';
_this.name = '';
_this.parent = parent;
_this.source = source;
_this.modelType = new model_type_1.ModelType(_this.config);
var name = _this.utils.getMethodParameterName(_this, source.name);
_this.name = name;
_this.label = name;
_this.modelType.type = _this.utils.getMethodParameterType(_this, source);
_this.modelType.isJsType = _this.utils.isJsType(_this.modelType.type);
_this.modelType.isArray = _this.utils.isArray(source) || undefined;
if (_this.modelType.isArray) {
var type = _this.utils.getArrayItemType(source);
_this.modelType.arrayItemType = type || undefined;
}
_this.in = source.in ? source.in : undefined;
_this.required = source.required || undefined;
_this.modelType.isEnum = _this.utils.isEnum(source) || undefined;
_this.description = source.description || undefined;
if (_this.modelType.isEnum) {
_this.modelType.enumValues = _this.utils.getEnumValues(source);
}
return _this;
}
SwaggerMethodParameter.prototype.init = function () {
var _this = this;
_super.prototype.init.call(this);
if (!this.modelType.isJsType && !this.modelType.isEnum) {
var modelRef = this.doc.models.find(function (modelItem) { return modelItem.name === _this.modelType.type; });
if (modelRef) {
this.modelType.modelRef = modelRef;
}
else {
console.error('Model not found', this.name);
}
}
if (this.modelType.isEnum) {
var enumRef = this.doc.enums.find(function (enumItem) { return enumItem.keys.includes(_this.name); });
if (enumRef) {
this.modelType.enumRef = enumRef;
}
else {
console.error('Model for enum not found (method parameter)' + this.name);
}
}
};
return SwaggerMethodParameter;
}(swagger_base_1.SwaggerBase));
exports.SwaggerMethodParameter = SwaggerMethodParameter;
//# sourceMappingURL=swagger-method-parameter.js.map