openapi-diff
Version:
A CLI tool to identify differences between Swagger/OpenAPI specs.
22 lines (21 loc) • 889 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizePath = void 0;
const 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;
};
exports.normalizePath = normalizePath;