swagger-routes-express
Version:
Connect Express route controllers to restful paths using a Swagger 2 or OpenAPI 3 definition file
20 lines (15 loc) • 564 B
JavaScript
const ni = require('../routes/notImplemented')
const nf = require('../routes/notFound')
const allAboard = (isFun, fun) => typeof fun === 'function' && isFun
const connectController = (api, operationId, options) => {
const { notFound = nf, notImplemented = ni } = options
const controller = api[operationId]
return operationId
? typeof controller === 'function'
? controller
: Array.isArray(controller) && controller.reduce(allAboard, true)
? controller
: notImplemented
: notFound
}
module.exports = connectController