server/boot/load-model.js
function(seriesCallback) {
      async.forEach(YAMLfiles,
        function(file, fileCallback) {
          logger.debug('Loading data from %s', file);
          var readfile;
          try {
            // read the content of the files into memory and parse as JSON
            readfile = YAML.load(fs.readFileSync(file, 'utf8'));

          } catch (e) {
            fileCallback(e);
            return;
          }
          var model = {};
          var entry = {};
          // looks like a product
          if (readfile.product) {
            logger.debug('product found: skipping');
          }
          // looks like an API
          if (readfile.swagger) {
            entry.id = createAPIID(readfile);
            entry.document = expandAPIData(readfile, dir);
            if (entry.document) {
              model.name = 'api';
              if (entry.document.info['x-ibm-name']) {
                apis[entry.document.info['x-ibm-name']] = entry.document;
              } else {
                apis[entry.document.info['title']] = entry.document;
              }
            }
          }

          if (model.name) {
            // no catalog
            entry.catalog = {};
            entry['snapshot-id'] = uid;
            app.models[model.name].create(
              entry,
              function(err, mymodel) {
                if (err) {
                  logger.error(err);
                  fileCallback(err);
                  return;
                }
                logger.debug('%s created: %j', model.name, mymodel);
                fileCallback();
              });
          } else {
            fileCallback();
          }
        },
        function(err) {
          if (err) { /* suppress eslint handle-callback-err */ }
        }
      );
      seriesCallback();
    }
function(seriesCallback) {
      async.forEach(YAMLfiles,
        function(file, fileCallback) {
          logger.debug('Loading data from %s', file);
          var readfile;
          try {
            // read the content of the files into memory and parse as JSON
            readfile = YAML.load(fs.readFileSync(file, 'utf8'));

          } catch (e) {
            fileCallback(e);
            return;
          }
          var model = {};
          var entry = {};
          // looks like a product
          if (readfile.product) {
            logger.debug('product found: skipping');
          }
          // looks like an API
          if (readfile.swagger) {
            entry.id = createAPIID(readfile);
            entry.document = expandAPIData(readfile, dir);
            if (entry.document) {
              model.name = 'api';
              if (entry.document.info['x-ibm-name']) {
                apis[entry.document.info['x-ibm-name']] = entry.document;
              } else {
                apis[entry.document.info['title']] = entry.document;
              }
            }
          }

          if (model.name) {
            // no catalog
            entry.catalog = {};
            entry['snapshot-id'] = uid;
            app.models[model.name].create(
              entry,
              function(err, mymodel) {
                if (err) {
                  logger.error(err);
                  fileCallback(err);
                  return;
                }
                logger.debug('%s created: %j', model.name, mymodel);
                fileCallback();
              });
          } else {
            fileCallback();
          }
        },
        function(err) {
          if (err) { /* suppress eslint handle-callback-err */ }
        }
      );
      seriesCallback();
    }
function ( seriesCallback ) { async . forEach ( YAMLfiles , function ( file , fileCallback ) { logger . debug ( 'Loading data from %s' , file ) ; var readfile ; try { // read the content of the files into memory and parse as JSON readfile = YAML . load ( fs . readFileSync ( file , 'utf8' ) ) ; } catch ( e ) { fileCallback ( e ) ; return ; } var model = { } ; var entry = { } ; // looks like a product if ( readfile . product ) { logger . debug ( 'product found: skipping' ) ; } // looks like an API if ( readfile . swagger ) { entry . id = createAPIID ( readfile ) ; entry . document = expandAPIData ( readfile , dir ) ; if ( entry . document ) { model . name = 'api' ; if ( entry . document . info [ 'x-ibm-name' ] ) { apis [ entry . document . info [ 'x-ibm-name' ] ] = entry . document ; } else { apis [ entry . document . info [ 'title' ] ] = entry . document ; } } } if ( model . name ) { // no catalog entry . catalog = { } ; entry [ 'snapshot-id' ] = uid ; app . models [ model . name ] . create ( entry , function ( err , mymodel ) { if ( err ) { logger . error ( err ) ; fileCallback ( err ) ; return ; } logger . debug ( '%s created: %j' , model . name , mymodel ) ; fileCallback ( ) ; } ) ; } else { fileCallback ( ) ; } } , function ( err ) { if ( err ) { /* suppress eslint handle-callback-err */ } } ) ; seriesCallback ( ) ; }
1. create the "api" instances
1 . create the api instances