UNPKG

openapi-diff

Version:

A CLI tool to identify differences between Swagger/OpenAPI specs.

20 lines (19 loc) 820 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizePath = (originalPath) => { let normalizedPath = ''; const substitutions = {}; const allParamNamesAndPathSegments = originalPath.split('}'); for (let index = 0; index < allParamNamesAndPathSegments.length; index += 1) { const paramNameAndPathSegment = allParamNamesAndPathSegments[index]; const [pathSegment, paramName] = paramNameAndPathSegment.split('{'); if (paramName) { substitutions[paramName] = substitutions[paramName] || `param${index}`; normalizedPath = `${normalizedPath}${pathSegment}{${substitutions[paramName]}}`; } else { normalizedPath = `${normalizedPath}${pathSegment}`; } } return normalizedPath; };