UNPKG

@igli.kokici/st-open-api

Version:

Generates API client SDKs from an OpenAPI specification written in OpenAPI version 3.x.x

69 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var render_mustache_1 = require("../function/render-mustache"); var unique_array_1 = require("./unique-array"); var split_by_line_break_1 = require("../function/split-by-line-break"); var formatText_1 = require("../function/formatText"); var InterfaceProperty = /** @class */ (function () { function InterfaceProperty(originalName) { this.originalName = originalName; this.description = []; this.imports = new unique_array_1.UniqueArray(); this.properties = {}; //later put here an type this.additionalProperties = []; this.convertName(originalName); } InterfaceProperty.prototype.convertName = function (originalName) { this.interfaceName = formatText_1.formatText(originalName, 'ANY', 'PascalCase'); this.fileName = formatText_1.formatText(originalName, 'ANY', 'KebabCase'); }; InterfaceProperty.prototype.addImports = function (_import) { this.imports.push(_import); }; InterfaceProperty.prototype.addAdditionalProperties = function (type, isArray) { if (isArray === void 0) { isArray = false; } this.additionalProperties.push({ type: type, isArray: isArray }); }; InterfaceProperty.prototype.addProperty = function (prop) { var data = { isDescription: !!prop.description, description: split_by_line_break_1.splitByLineBreak(prop.description), required: prop.required, value: prop.value, propertyName: prop.propertyName, isArray: prop.isArray, }; this.properties[data.propertyName] = { data: data, import: prop.import }; }; InterfaceProperty.prototype.render = function () { var _this = this; var renderProperties = Object.values(this.properties).map(function (prop) { return { import: prop.import, name: prop.data.propertyName, render: render_mustache_1.renderMustache('property-class.mustache', prop.data) }; }).sort(function (a, b) { return a.name.localeCompare(b.name); }); renderProperties.filter(function (p) { return !!p.import; }).forEach(function (property) { return _this.imports.push(property.import); }); var viewData = { interfaceName: this.interfaceName, isImport: this.imports.get().length > 0, imports: this.imports.get().sort(), isDescription: (this.description || '').length > 0, description: this.description, isProperties: renderProperties.length > 0, properties: renderProperties.map(function (rf) { return split_by_line_break_1.splitByLineBreak(rf.render); }), isAdditionalProperties: this.additionalProperties.length > 0, additionalProperties: this.additionalProperties }; return { classEnumName: this.interfaceName, fileName: this.fileName, render: render_mustache_1.renderMustache('interface.mustache', viewData) }; }; return InterfaceProperty; }()); exports.InterfaceProperty = InterfaceProperty; //# sourceMappingURL=interface-property.js.map