<commit_before>var fs = require('fs');
var xml2js = require('xml2js');
var url = require('url');


module.exports = {
  genopenapi: genopenapi
}

function genopenapi(location, answers, xmlFile, cb) {
  var openapiJson = {};
  loadXMLDoc(location + "/apiproxy/" + answers.api + ".xml", function(err, reply) {
    openapiJson.swagger = "2.0";
    // Info Section
    openapiJson.info = {};
    try {
      openapiJson.info.description = reply.APIProxy.Description ? reply.APIProxy.Description[0] : '';
      openapiJson.info.version = (reply.APIProxy.$.revision || "1") + ".0.0";
      openapiJson.info.title = reply.APIProxy.DisplayName ? reply.APIProxy.DisplayName[0] : answers.api;
      openapiJson.info.contact = {}
      openapiJson.info.contact.email = reply.APIProxy.CreatedBy[0] || '';
    } catch (ex) {console.log(ex)}
    // Host & BasePath Section..
    var proxy = url.parse(answers.proxyEndPoint);
    openapiJson.host = proxy.host ? proxy.host : '';
    var schemes = [];
    var protocol = proxy.protocol ? proxy.protocol : 'http';
    schemes.push(protocol.substring(0, protocol.length -1));
    openapiJson.schemes = schemes;
    loadXMLDoc(xmlFile, function(err, replyProxy) {
      // Add base path
      try {
        openapiJson.basePath = replyProxy.ProxyEndpoint.HTTPProxyConnection[0].BasePath[0];
      } catch (ex) {console.log(ex);}

      // Add Paths
      openapiJson.paths = {};
      for (key in replyProxy.ProxyEndpoint.Flows[0].Flow) {
        var openapiPath = JSON.parse(JSON.stringify(replyProxy.ProxyEndpoint.Flows[0].Flow[key]));;
        if (openapiPath["Condition"] != null) {
          var flowCondition = openapiPath["Condition"].pop();
          // Get Path & Verb...
          var rxVerb = /request.verb = "(.*?)"/g;
          var rxPath = /proxy.pathsuffix MatchesPath "(.*?)"/g;
          var verbArr = rxVerb.exec(flowCondition);
          var pathArr = rxPath.exec(flowCondition);
          if (verbArr != null && pathArr != null) {
            var resourcePath = pathArr[1];
            var resourceVerb = verbArr[1].toLowerCase();
            openapiJson.paths[resourcePath] = {};
            openapiJson.paths[resourcePath][resourceVerb] = {};
            openapiJson.paths[resourcePath][resourceVerb].operationId = openapiPath.$.name;
            if (openapiPath.Description != null) {
              openapiJson.paths[resourcePath][resourceVerb].summary = openapiPath.Description[0];
            }
            var resourceResponse = {
              "200": {
                "description": "successful operation"
              }
            };
            openapiJson.paths[resourcePath][resourceVerb].responses = resourceResponse;
            // Add parameters if path includes dynamic value....
            var rxParam = /\{(.*?)\}/g;
            var rxParamArr = pathArr[1].match(rxParam);
            if (rxParamArr != null) {
              // Add Parameters
              openapiJson.paths[resourcePath][resourceVerb].parameters = [];
              for (var i in rxParamArr) {
                var resourceParameter = rxParamArr[i];<commit_msg>Path with multiple verbs<commit_after>var fs = require('fs');
var xml2js = require('xml2js');
var url = require('url');


module.exports = {
  genopenapi: genopenapi
}

function genopenapi(location, answers, xmlFile, cb) {
  var openapiJson = {};
  loadXMLDoc(location + "/apiproxy/" + answers.api + ".xml", function(err, reply) {
    openapiJson.swagger = "2.0";
    // Info Section
    openapiJson.info = {};
    try {
      openapiJson.info.description = reply.APIProxy.Description ? reply.APIProxy.Description[0] : '';
      openapiJson.info.version = (reply.APIProxy.$.revision || "1") + ".0.0";
      openapiJson.info.title = reply.APIProxy.DisplayName ? reply.APIProxy.DisplayName[0] : answers.api;
      openapiJson.info.contact = {}
      openapiJson.info.contact.email = reply.APIProxy.CreatedBy[0] || '';
    } catch (ex) {console.log(ex)}
    // Host & BasePath Section..
    var proxy = url.parse(answers.proxyEndPoint);
    openapiJson.host = proxy.host ? proxy.host : '';
    var schemes = [];
    var protocol = proxy.protocol ? proxy.protocol : 'http';
    schemes.push(protocol.substring(0, protocol.length -1));
    openapiJson.schemes = schemes;
    loadXMLDoc(xmlFile, function(err, replyProxy) {
      // Add base path
      try {
        openapiJson.basePath = replyProxy.ProxyEndpoint.HTTPProxyConnection[0].BasePath[0];
      } catch (ex) {console.log(ex);}

      // Add Paths
      openapiJson.paths = {};
      for (key in replyProxy.ProxyEndpoint.Flows[0].Flow) {
        var openapiPath = JSON.parse(JSON.stringify(replyProxy.ProxyEndpoint.Flows[0].Flow[key]));;
        if (openapiPath["Condition"] != null) {
          var flowCondition = openapiPath["Condition"].pop();
          // Get Path & Verb...
          var rxVerb = /request.verb = "(.*?)"/g;
          var rxPath = /proxy.pathsuffix MatchesPath "(.*?)"/g;
          var verbArr = rxVerb.exec(flowCondition);
          var pathArr = rxPath.exec(flowCondition);
          if (verbArr != null && pathArr != null) {
            var resourcePath = pathArr[1];
            var resourceVerb = verbArr[1].toLowerCase();
            if (!openapiJson.paths[resourcePath]) openapiJson.paths[resourcePath] = {}
            openapiJson.paths[resourcePath][resourceVerb] = {};
            openapiJson.paths[resourcePath][resourceVerb].operationId = openapiPath.$.name;
            if (openapiPath.Description != null) {
              openapiJson.paths[resourcePath][resourceVerb].summary = openapiPath.Description[0];
            }
            var resourceResponse = {
              "200": {
                "description": "successful operation"
              }
            };
            openapiJson.paths[resourcePath][resourceVerb].responses = resourceResponse;
            // Add parameters if path includes dynamic value....
            var rxParam = /\{(.*?)\}/g;
            var rxParamArr = pathArr[1].match(rxParam);
            if (rxParamArr != null) {
              // Add Parameters
              openapiJson.paths[resourcePath][resourceVerb].parameters = [];
              for (var i in rxParamArr) {
                var resourceParameter = rxParamArr[i];
{'fraction_non_alphanumeric': 0.14132522407170295, 'fraction_numerical': 0.00736235595390525, 'mean_word_length': 2.4969222160044766, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4970343', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1814, 'n_words': 344}