swagger-routes-express
Version:
Connect Express route controllers to restful paths using a Swagger 2 or OpenAPI 3 definition file
19 lines (16 loc) • 566 B
JavaScript
const substituteVariables = require('../../utils/substituteVariables')
/**
* given an array of servers, return a single base path.
* @param servers — The array of servers
* @param variables — a map of variable names and the values to be substituted
* @returns the eventual base path
*/
const basePath = (servers, variables) =>
Array.isArray(servers)
? servers.reduce(
(acc, { url }) =>
acc !== '' || !url.startsWith('/') ? acc : substituteVariables(url, variables),
''
)
: undefined
module.exports = basePath