<commit_before>var Swagger = require('./swagger'),
    Importer = require('./importer'),
    UtilityFunction = require('../entities/utilityFunction'),
    Text = require('../entities/text'),
    fs = require('fs');

function StopLightX() {
  this.metadata = null;
  this.swaggerImporter = new Swagger();
}
StopLightX.prototype = new Importer();

StopLightX.prototype.loadFile = function(path, cb){
  var me = this;
  return this.swaggerImporter.loadFile(path, function(){
    me.data = me.swaggerImporter.data;
    cb();
  });
};

StopLightX.prototype.loadData = function(path, cb){
  var me = this;
  return this.swaggerImporter.loadData(path, function(err){
    if (err) {
      return cb(err);
    }
    me.data = me.swaggerImporter.data;
    cb();
  });
};

StopLightX.prototype._import = function () {

  try {
    this.project = this.swaggerImporter.import();

    var data = this.swaggerImporter.data;
    var prefix = 'x-stoplight';
    if (data.hasOwnProperty(prefix)) {
      var environment = this.project.Environment;
      environment.loadSLData(data[prefix].version);

      //property names are different from db name
      environment.GroupsOrder = data[prefix].version.groups;
      environment.MiddlewareBefore = data[prefix].version.beforeScript;
      environment.MiddlewareAfter = data[prefix].version.afterScript;

      this.project.Environment = environment;

      for (var name in data[prefix].functions) {
        var ufData = data[prefix].functions[name];
        var uf = new UtilityFunction(ufData.name);
        uf.Description = ufData.description;
        uf.Script = ufData.script;
        this.project.addUtilityFunction(uf);
      }

      for (var name in data[prefix].textSections) {
        var txtData = data[prefix].textSections[name];
        var txt = new Text(txtData.name);
        txt.Id = txtData.id;
        txt.Content = txtData.content;
        txt.Public = txtData.public;
        this.project.addText(txt);
      }

      for(var i in this.project.Endpoints) {
        var endpoint = this.project.Endpoints[i];
        var method = data.paths[endpoint.Path][endpoint.Method][prefix];
        endpoint.Before = method['beforeScript'];
        endpoint.After = method['afterScript'];
        endpoint.Mock = method['mock'];
        endpoint.Id = method['id'];
      }

      for(var i in this.project.Schemas) {
        var schema = this.project.Schemas[i];
        var schemaData = data.definitions[schema.Name][prefix];
        schema.Id = schemaData.id;
        schema.Name = schemaData.name;
        schema.Summary = schemaData.summary;
        schema.Description = schemaData.description;
        schema.Public = schemaData.public;
      }
    }
  } catch(err) {
    console.log(err);
  }
};

module.exports = StopLightX;<commit_msg>- additional checking for stoplight extensions data.<commit_after>var Swagger = require('./swagger'),
    Importer = require('./importer'),
    UtilityFunction = require('../entities/utilityFunction'),
    Text = require('../entities/text'),
    fs = require('fs');

function StopLightX() {
  this.metadata = null;
  this.swaggerImporter = new Swagger();
}
StopLightX.prototype = new Importer();

StopLightX.prototype.loadFile = function(path, cb){
  var me = this;
  return this.swaggerImporter.loadFile(path, function(){
    me.data = me.swaggerImporter.data;
    cb();
  });
};

StopLightX.prototype.loadData = function(path, cb){
  var me = this;
  return this.swaggerImporter.loadData(path, function(err){
    if (err) {
      return cb(err);
    }
    me.data = me.swaggerImporter.data;
    cb();
  });
};

StopLightX.prototype._import = function () {

    this.project = this.swaggerImporter.import();

    var data = this.swaggerImporter.data;
    var prefix = 'x-stoplight';
    if (!data.hasOwnProperty(prefix)) {
      return;
    }
    var environment = this.project.Environment;

    var stoplightData = data[prefix];

    if (stoplightData.hasOwnProperty('version')) {
      environment.loadSLData(data[prefix].version);
      //property names are different from db name
      environment.GroupsOrder = data[prefix].version.groups;
      environment.MiddlewareBefore = data[prefix].version.beforeScript;
      environment.MiddlewareAfter = data[prefix].version.afterScript;

      this.project.Environment = environment;
    }

    for (var name in data[prefix].functions) {
      var ufData = data[prefix].functions[name];
      var uf = new UtilityFunction(ufData.name);
      uf.Description = ufData.description;
      uf.Script = ufData.script;
      this.project.addUtilityFunction(uf);
    }

    for (var name in data[prefix].textSections) {
      var txtData = data[prefix].textSections[name];
      var txt = new Text(txtData.name);
      txt.Id = txtData.id;
      txt.Content = txtData.content;
      txt.Public = txtData.public;
      this.project.addText(txt);
    }

    for(var i in this.project.Endpoints) {
      var endpoint = this.project.Endpoints[i];
      var method = data.paths[endpoint.Path][endpoint.Method][prefix];
      if (method) {
        endpoint.Before = method['beforeScript'];
        endpoint.After = method['afterScript'];
        endpoint.Mock = method['mock'];
        endpoint.Id = method['id'];
      }
    }

    for(var i in this.project.Schemas) {
      var schema = this.project.Schemas[i];
      var schemaData = data.definitions[schema.NameSpace][prefix];
      if (schemaData) {
        schema.Id = schemaData.id;
        schema.Name = schemaData.name;
        schema.Summary = schemaData.summary;
        schema.Description = schemaData.description;
        schema.Public = schemaData.public;
      }
    }
};

module.exports = StopLightX;
{'fraction_non_alphanumeric': 0.1319859402460457, 'fraction_numerical': 0.0, 'mean_word_length': 2.9411357340720223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92726', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1687, 'n_words': 330}