packages/api-gateway/src/index.js
function mergeSpecsFiles(beginPath, subPath) {
  // Initialise specification
  const spec = {};

  // List all directories where we have to look for specifications
  const subDirs = subPath.split(path.sep);

  // Initialize the directory path for the do/while statement
  let searchSpecDir = beginPath;

  do {
    let subSpec = {};
    const subDir = subDirs.shift();
    searchSpecDir = path.join(searchSpecDir, subDir);

    try {
      // Try to load the definition and silently ignore the error if it does not exist
      // Because we use require() to get the config, it could either be a JSON file
      // or the content exported by a node module
      // But because require() caches the content it loads, we clone the result to avoid bugs
      // if the function is called twice
      subSpec = _.cloneDeep(require(searchSpecDir + path.sep + 'spec'));
    } catch (e) {
      // Silently ignore the error when calling require() on an unexisting spec.json file
      if (e.code !== 'MODULE_NOT_FOUND') { throw e; }
    }

    // Merge the spec eventually found
    _.merge(spec, subSpec);
  } while (subDirs.length);

  // return the result of the merges
  return spec;
}
function mergeSpecsFiles(beginPath, subPath) {
  // Initialise specification
  const spec = {};

  // List all directories where we have to look for specifications
  const subDirs = subPath.split(path.sep);

  // Initialize the directory path for the do/while statement
  let searchSpecDir = beginPath;

  do {
    let subSpec = {};
    const subDir = subDirs.shift();
    searchSpecDir = path.join(searchSpecDir, subDir);

    try {
      // Try to load the definition and silently ignore the error if it does not exist
      // Because we use require() to get the config, it could either be a JSON file
      // or the content exported by a node module
      // But because require() caches the content it loads, we clone the result to avoid bugs
      // if the function is called twice
      subSpec = _.cloneDeep(require(searchSpecDir + path.sep + 'spec'));
    } catch (e) {
      // Silently ignore the error when calling require() on an unexisting spec.json file
      if (e.code !== 'MODULE_NOT_FOUND') { throw e; }
    }

    // Merge the spec eventually found
    _.merge(spec, subSpec);
  } while (subDirs.length);

  // return the result of the merges
  return spec;
}
function mergeSpecsFiles ( beginPath , subPath ) { // Initialise specification const spec = { } ; // List all directories where we have to look for specifications const subDirs = subPath . split ( path . sep ) ; // Initialize the directory path for the do/while statement let searchSpecDir = beginPath ; do { let subSpec = { } ; const subDir = subDirs . shift ( ) ; searchSpecDir = path . join ( searchSpecDir , subDir ) ; try { // Try to load the definition and silently ignore the error if it does not exist // Because we use require() to get the config, it could either be a JSON file // or the content exported by a node module // But because require() caches the content it loads, we clone the result to avoid bugs // if the function is called twice subSpec = _ . cloneDeep ( require ( searchSpecDir + path . sep + 'spec' ) ) ; } catch ( e ) { // Silently ignore the error when calling require() on an unexisting spec.json file if ( e . code !== 'MODULE_NOT_FOUND' ) { throw e ; } } // Merge the spec eventually found _ . merge ( spec , subSpec ) ; } while ( subDirs . length ) ; // return the result of the merges return spec ; }
Function that aggregates the specifications found in all spec.json|js files in a path
@param {string} beginPath - path from which the function will look for swagger.json|js files
@param {string} subPath - path until which the function will look for swagger.json|js files
@returns {Object} - aggregation of specifications that have been found
Function that aggregates the specifications found in all spec . json|js files in a path