<commit_before>/**
 * https://github.com/tjwebb/sails-swagger
 */

import path from 'path'
import _ from 'lodash'
import Marlinspike from 'marlinspike'
import xfmr from './lib/xfmr'

class Swagger extends Marlinspike {
  defaults(overrides) {
    return {
      'swagger': {
        pkg: {
          name: 'No package information',
          description: 'You should set sails.config.swagger.pkg to retrieve the content of the package.json file',
          version: '0.0.0'
        }
      }
    };
  }

  constructor(sails) {
    super(sails, module)
  }

  initialize(next) {
    let hook = this.sails.hooks.swagger;
    this.sails.after('lifted', () => {
      hook.doc = xfmr.getSwagger(this.sails, this.sails.config.swagger.pkg);
    });

    next();
  }
}

export default Marlinspike.createSailsHook(Swagger)<commit_msg>refactor(swagger): Bind explorer route in swagger hook<commit_after>/**
 * https://github.com/tjwebb/sails-swagger
 */

import path from 'path'
import _ from 'lodash'
import Marlinspike from 'marlinspike'
import xfmr from './lib/xfmr'
import express from 'express';

class Swagger extends Marlinspike {
  defaults(overrides) {
    this.bindExplorerRoute();

    return {
      'swagger': {
        pkg: {
          name: 'No package information',
          description: 'You should set sails.config.swagger.pkg to retrieve the content of the package.json file',
          version: '0.0.0'
        }
      }
    };
  }

  constructor(sails) {
    super(sails, module)
  }

  initialize(next) {
    let hook = this.sails.hooks.swagger;
    this.sails.after('lifted', () => {
      hook.doc = xfmr.getSwagger(this.sails, this.sails.config.swagger.pkg);
    });

    next();
  }

  bindExplorerRoute() {
    let originalCustomMiddleware = _.get(this.sails.config, 'http.customMiddleware');
    let customMiddleware = app => {
      app.use('/explorer', express.static(process.cwd() + '/explorer'));
      if (_.isFunction(originalCustomMiddleware)) {
        originalCustomMiddleware(app);
      }
    };
    _.set(this.sails.config, 'http.customMiddleware', customMiddleware);
  }
}

export default Marlinspike.createSailsHook(Swagger)
{'fraction_non_alphanumeric': 0.1334569045412419, 'fraction_numerical': 0.0027803521779425394, 'mean_word_length': 2.911231884057971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '6808852', 'n_tokens_mistral': 727, 'n_tokens_neox': 709, 'n_words': 145}