function loadDefinition(defPath, swaggerDefinition) {
  const resolvedPath = path.resolve(defPath);
  const extName = path.extname(resolvedPath);

  // eslint-disable-next-line
  const loadCjs = () => require(resolvedPath);
  const loadJson = () => JSON.parse(swaggerDefinition);
  // eslint-disable-next-line
  const loadYaml = () => require('yaml').parse(swaggerDefinition);

  const LOADERS = {
    '.js': loadCjs, // on purpose, to allow throwing by nodejs and .cjs suggestion
    '.cjs': loadCjs,
    '.json': loadJson,
    '.yml': loadYaml,
    '.yaml': loadYaml,
  };

  const loader = LOADERS[extName];

  if (loader === undefined) {
    throw new Error('Definition file should be .cjs, .json, .yml or .yaml');
  }

  return loader();
}
Get an object of the definition file configuration.
@param {string} defPath
@param {object} swaggerDefinition