UNPKG

@elliots/openapi-ts-backend

Version:

Enables easy implementions of OpenAPI REST APIs in TypeScript with full typings of schemas and operations.

43 lines 1.83 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getApiOperationIds = void 0; const ts = __importStar(require("typescript")); console.log(`Using TypeScript v${ts.version}`); function getApiOperationIds(specTypesPath) { const program = ts.createProgram([specTypesPath], {}); const tsFile = program.getSourceFile(specTypesPath); if (!tsFile) { throw new Error(`Cannot find OpenAPI types ${specTypesPath}`); } const operationsNode = tsFile .getChildAt(0) .getChildren() .find(c => c.kind === ts.SyntaxKind.InterfaceDeclaration && c.name.escapedText === 'operations'); if (!operationsNode) { throw new Error(`Could not find operations interface`); } const operationsInterface = operationsNode; return operationsInterface.members.map(m => m.name.escapedText.toString()); } exports.getApiOperationIds = getApiOperationIds; //# sourceMappingURL=parser.js.map