UNPKG

openapi-typescript

Version:

Generate TypeScript types from Swagger OpenAPI specs

49 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformPathsObj = void 0; const utils_1 = require("../utils"); const operation_1 = require("./operation"); const parameters_1 = require("./parameters"); function transformPathsObj(paths, options) { const { globalParameters, operations, ...ctx } = options; const readonly = (0, utils_1.tsReadonly)(ctx.immutableTypes); let output = ""; for (const [url, pathItem] of Object.entries(paths)) { if (pathItem.description) output += (0, utils_1.comment)(pathItem.description); if (pathItem.$ref) { output += ` ${readonly}"${url}": ${pathItem.$ref};\n`; continue; } output += ` ${readonly}"${url}": {\n`; for (const method of ["get", "put", "post", "delete", "options", "head", "patch", "trace"]) { const operation = pathItem[method]; if (!operation) continue; if (operation.description) output += (0, utils_1.comment)(operation.description); if (operation.operationId) { operations[operation.operationId] = { operation, pathItem }; const namespace = ctx.namespace ? `external["${ctx.namespace}"]["operations"]` : `operations`; output += ` ${readonly}"${method}": ${namespace}["${operation.operationId}"];\n`; } else { output += ` ${readonly}"${method}": {\n ${(0, operation_1.transformOperationObj)(operation, { ...ctx, globalParameters, pathItem, })}\n }\n`; } } if (pathItem.parameters) { output += ` ${readonly}parameters: {\n ${(0, parameters_1.transformParametersArray)(pathItem.parameters, { ...ctx, globalParameters, })}\n }\n`; } output += ` }\n`; } return output; } exports.transformPathsObj = transformPathsObj; //# sourceMappingURL=paths.js.map