UNPKG

@axway/api-builder-uri-utils

Version:

A collection of URI utility functions for API Builder

20 lines (16 loc) 556 B
const escapeExpressRegex = require('./escapeExpressRegex'); const PATH_PATTERN = new RegExp(/(?:\{.*?\})/g); /** * Converts a Swagger path containing path parameters to an Express.js path. * @param {*} path - The Swagger path to convert. * @returns {string} An Express.js equivalent path. */ function oasPathToExpress(path) { let match = PATH_PATTERN.exec(path); while (match !== null) { path = path.replace(/{/, ':').replace(/}/, ''); match = PATH_PATTERN.exec(path); } return escapeExpressRegex(path); } module.exports = oasPathToExpress;