UNPKG

parse-openapi

Version:

OpenAPI v3 parser

27 lines (26 loc) 1.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOperationName = void 0; const camelcase_1 = __importDefault(require("camelcase")); /** * Convert the input value to a correct operation (method) classname. * This will use the operation ID - if available - and otherwise fallback * on a generated name from the URL */ const getOperationName = (url, method, operationId) => { if (operationId) { return (0, camelcase_1.default)(operationId .replace(/^[^a-zA-Z]+/g, '') .replace(/[^\w\-]+/g, '-') .trim()); } const urlWithoutPlaceholders = url .replace(/[^/]*?{api-version}.*?\//g, '') .replace(/{(.*?)}/g, '') .replace(/\//g, '-'); return (0, camelcase_1.default)(`${method}-${urlWithoutPlaceholders}`); }; exports.getOperationName = getOperationName;