UNPKG

@igli.kokici/st-open-api

Version:

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

177 lines 7.71 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; 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"); exports.HTTP_FUNCTION_REF = function (folder) { return { fileName: "http", refKey: "HTTP_FUNCTION_REF", className: "http", folderPath: folder.getFunctionFolder() }; }; exports.HTTP_REQUEST_INTERCEPTOR_INTERFACE_REF = function (folder) { return { fileName: "i-$-open-api", refKey: "HTTP_REQUEST_INTERCEPTOR_INTERFACE_REF", className: "RequestInterceptor", folderPath: folder.getInterfaceFolder() }; }; exports.HTTP_RESPONSE_INTERCEPTOR_INTERFACE_REF = function (folder) { return { fileName: "i-$-open-api", refKey: "HTTP_RESPONSE_INTERCEPTOR_INTERFACE_REF", className: "ResponseInterceptor", folderPath: folder.getInterfaceFolder() }; }; exports.HTTP_ERROR_HANDLER_INTERFACE_REF = function (folder) { return { fileName: "i-$-open-api", refKey: "HTTP_ERROR_HANDLER_INTERFACE_REF", className: "ErrorHandler", folderPath: folder.getInterfaceFolder() }; }; exports.OPEN_API_FUNCTION_REF = function (folder) { return { fileName: "open-api", refKey: "OPEN_API_FUNCTION_REF", className: "openApi", folderPath: folder.getFunctionFolder() }; }; exports.QUERY_PARAMETER_FUNCTION_REF = function (folder) { return { fileName: "get-query-params", refKey: "QUERY_PARAMETER_FUNCTION_REF", className: "getQueryParameters", folderPath: folder.getFunctionFolder() }; }; exports.SERVICE_REFERENCES = [ exports.HTTP_FUNCTION_REF, exports.HTTP_REQUEST_INTERCEPTOR_INTERFACE_REF, exports.HTTP_RESPONSE_INTERCEPTOR_INTERFACE_REF, exports.HTTP_ERROR_HANDLER_INTERFACE_REF, exports.OPEN_API_FUNCTION_REF, exports.QUERY_PARAMETER_FUNCTION_REF ]; var ObjectProperty = /** @class */ (function () { function ObjectProperty(originalName) { this.description = []; this.imports = new unique_array_1.UniqueArray(); this.functions = []; this.properties = []; this.convertName(originalName); } ObjectProperty.prototype.convertName = function (originalName) { this.className = formatText_1.formatText(originalName, 'ANY', 'PascalCase'); this.fileName = formatText_1.formatText(originalName, 'ANY', 'KebabCase'); }; ObjectProperty.prototype.addImports = function (_import) { this.imports.push(_import); }; ObjectProperty.prototype.addFunction = function (fun) { var _a, _b, _c, _d, _e, _f; var data = { functionName: fun.functionName, originalPath: fun.originalPath, httpMethod: fun.httpMethod, isDescription: !!fun.description, description: split_by_line_break_1.splitByLineBreak(fun.description), isPathParameters: !!fun.pathParameters, pathParameters: (_a = fun.pathParameters) === null || _a === void 0 ? void 0 : _a.params, pathParameterClassName: (_b = fun.pathParameters) === null || _b === void 0 ? void 0 : _b.className, isQueryParameters: !!fun.queryParameters, queryParameters: (_c = fun.queryParameters) === null || _c === void 0 ? void 0 : _c.params, queryParameterClassName: (_d = fun.queryParameters) === null || _d === void 0 ? void 0 : _d.className, isHeaderParameters: !!fun.headerParameters, headerParameters: (_e = fun.headerParameters) === null || _e === void 0 ? void 0 : _e.params, headerParameterClassName: (_f = fun.headerParameters) === null || _f === void 0 ? void 0 : _f.className, isRequestBody: !!fun.requestBodyClass, isRequestBodyJson: !!fun.requestBodyClass && fun.isRequestBodyJson, requestBodyClass: fun.requestBodyClass, forceInterceptor: fun.forceInterceptor, isResponse: !!fun.responseClass, isJsonResponse: !!fun.responseClass && fun.isJsonResponse, isPlaintextResponse: fun.isPlaintextResponse, isDownloadResponse: fun.isDownloadResponse, responseClass: fun.responseClass }; this.functions.push({ data: data, imports: fun.imports, name: fun.functionName }); }; ObjectProperty.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.push({ data: data, import: prop.import, name: data.propertyName }); }; ObjectProperty.prototype.render = function () { var _this = this; var renderedFunctions = this.functions.map(function (fun) { return { imports: fun.imports || [], name: fun.name, render: render_mustache_1.renderMustache('function-class.mustache', fun.data) }; }).sort(function (a, b) { return a.name.localeCompare(b.name); }); var renderProperties = this.properties.map(function (prop) { return { import: prop.import, name: prop.name, render: render_mustache_1.renderMustache('property-class.mustache', prop.data) }; }).sort(function (a, b) { return a.name.localeCompare(b.name); }); var isFunction = renderedFunctions.length > 0; renderedFunctions.forEach(function (fun) { var _a; return (_a = _this.imports).push.apply(_a, __spread(fun.imports)); }); renderProperties.forEach(function (property) { return _this.imports.push(property.import); }); var viewData = { className: this.className, isInterface: Object.values(this.functions).length == 0, isImport: this.imports.get().length > 0, imports: this.imports.get().sort(), isDescription: (this.description || '').length > 0, description: this.description, isFunction: isFunction, function: renderedFunctions.map(function (rf) { return split_by_line_break_1.splitByLineBreak(rf.render); }), isProperties: renderProperties.length > 0, properties: renderProperties.map(function (rf) { return split_by_line_break_1.splitByLineBreak(rf.render); }) }; return { classEnumName: this.className, fileName: this.fileName, render: render_mustache_1.renderMustache('service-class.mustache', viewData) }; }; return ObjectProperty; }()); exports.ObjectProperty = ObjectProperty; //# sourceMappingURL=object-property.js.map