<commit_before>const $RefParser = require('json-schema-ref-parser');
const SwaggerParser = require('swagger-parser');
const maybe = require('call-me-maybe');
const traverse = require('traverse');
const _ = require('lodash');

function filterPaths([schemas, apis, combinedSchema]) {
  schemas.map((schema, idx) => {
    if (apis[idx].paths) {
      if (apis[idx].paths.include && apis[idx].paths.include.length > 0) {
        schema.paths = _.pick(schema.paths, apis[idx].paths.include);
      } else if (apis[idx].paths.exclude && apis[idx].paths.exclude.length > 0) {
        schema.paths = _.omit(schema.paths, apis[idx].paths.exclude);
      }
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renamePaths([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].paths && apis[idx].paths.rename && Object.keys(apis[idx].paths.rename).length > 0) {
      _.forIn(apis[idx].paths.rename, (renamePath, pathToRename) => {
        schema.paths = _.mapKeys(schema.paths, (value, curPath) => {
          if (pathToRename === curPath) {
            return renamePath;
          }

          return curPath;
        });
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renameTags([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].tags && apis[idx].tags.rename && Object.keys(apis[idx].tags.rename).length > 0) {
      _.forIn(apis[idx].tags.rename, (newTagName, tagNameToRename) => {
        traverse(schema).forEach((function traverseSchema() {
          if (this.key === 'tags' && Array.isArray(this.node) && this.node.includes(tagNameToRename)) {
            this.update(this.node.map(tag => tag === tagNameToRename ? newTagName : tag)); // eslint-disable-line
          }
        }));
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renameSecurityDefinitions([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].securityDefinitions && apis[idx].securityDefinitions.rename &&
      Object.keys(apis[idx].securityDefinitions.rename).length > 0) {
      _.forIn(apis[idx].securityDefinitions.rename, (newName, curName) => {
        if (_.has(schema.securityDefinitions, curName)) {
          _.set(schema.securityDefinitions, newName, schema.securityDefinitions[curName]);
          _.unset(schema.securityDefinitions, curName);

          traverse(schema).forEach((function traverseSchema() {
            if (this.key === 'security' && Array.isArray(this.node) && this.node.some(sec => !!sec[curName])) {
              this.update(this.node.map((sec) => {
                if (_.has(sec, curName)) {
                  _.set(sec, newName, sec[curName]);
                  _.unset(sec, curName);
                }

                return sec;
              }));
            }
          }));
        }
      });
    }

    return schema;
  });

  schemas = schemas.map((schema, idx) => {
    if (apis[idx].tags && apis[idx].tags.rename && Object.keys(apis[idx].tags.rename).length > 0) {
      _.forIn(apis[idx].tags.rename, (newTagName, tagNameToRename) => {
        traverse(schema).forEach((function traverseSchema() {
          if (this.key === 'tags' && Array.isArray(this.node) && this.node.includes(tagNameToRename)) {
            this.update(this.node.map(tag => tag === tagNameToRename ? newTagName : tag)); // eslint-disable-line
          }
        }));
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];<commit_msg>Fix security definition renaming by removing tag renaming logic<commit_after>const $RefParser = require('json-schema-ref-parser');
const SwaggerParser = require('swagger-parser');
const maybe = require('call-me-maybe');
const traverse = require('traverse');
const _ = require('lodash');

function filterPaths([schemas, apis, combinedSchema]) {
  schemas.map((schema, idx) => {
    if (apis[idx].paths) {
      if (apis[idx].paths.include && apis[idx].paths.include.length > 0) {
        schema.paths = _.pick(schema.paths, apis[idx].paths.include);
      } else if (apis[idx].paths.exclude && apis[idx].paths.exclude.length > 0) {
        schema.paths = _.omit(schema.paths, apis[idx].paths.exclude);
      }
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renamePaths([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].paths && apis[idx].paths.rename && Object.keys(apis[idx].paths.rename).length > 0) {
      _.forIn(apis[idx].paths.rename, (renamePath, pathToRename) => {
        schema.paths = _.mapKeys(schema.paths, (value, curPath) => {
          if (pathToRename === curPath) {
            return renamePath;
          }

          return curPath;
        });
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renameTags([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].tags && apis[idx].tags.rename && Object.keys(apis[idx].tags.rename).length > 0) {
      _.forIn(apis[idx].tags.rename, (newTagName, tagNameToRename) => {
        traverse(schema).forEach((function traverseSchema() {
          if (this.key === 'tags' && Array.isArray(this.node) && this.node.includes(tagNameToRename)) {
            this.update(this.node.map(tag => tag === tagNameToRename ? newTagName : tag)); // eslint-disable-line
          }
        }));
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
}

function renameSecurityDefinitions([schemas, apis, combinedSchema]) {
  schemas = schemas.map((schema, idx) => {
    if (apis[idx].securityDefinitions && apis[idx].securityDefinitions.rename &&
      Object.keys(apis[idx].securityDefinitions.rename).length > 0) {
      _.forIn(apis[idx].securityDefinitions.rename, (newName, curName) => {
        if (_.has(schema.securityDefinitions, curName)) {
          _.set(schema.securityDefinitions, newName, schema.securityDefinitions[curName]);
          _.unset(schema.securityDefinitions, curName);

          traverse(schema).forEach((function traverseSchema() {
            if (this.key === 'security' && Array.isArray(this.node) && this.node.some(sec => !!sec[curName])) {
              this.update(this.node.map((sec) => {
                if (_.has(sec, curName)) {
                  _.set(sec, newName, sec[curName]);
                  _.unset(sec, curName);
                }

                return sec;
              }));
            }
          }));
        }
      });
    }

    return schema;
  });

  return [schemas, apis, combinedSchema];
{'fraction_non_alphanumeric': 0.1655500967693911, 'fraction_numerical': 0.001637635849337502, 'mean_word_length': 2.767807066741447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '4516902', 'n_tokens_mistral': 2125, 'n_tokens_neox': 2046, 'n_words': 347}