<commit_before>'use strict';

module.exports = init;

var debug = require('debug')('swagger:restify_middleware');
var ALL_METHODS = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch'];

function init(runner) {
  return new Middleware(runner);
}

function Middleware(runner) {

  this.runner = runner;

  var connectMiddleware = runner.connectMiddleware();
  var chain = connectMiddleware.middleware();

  this.register = function register(app) {

    var api = connectMiddleware.runner.api;

    function registerHandler(path, method) {
      app[method](path, function(req, res, next) {
        req.query = undefined; // oddly, req.query is a function in Restify, kill it
        chain(req, res, next);
      });
    }

    api.pathObjects.forEach(function(path) {
      if (path.operationObjects && path.operationObjects.length > 0) {
        path.operationObjects.forEach(function(operation) {
          registerHandler(path.path, operation.method);
        });
      } else {
        ALL_METHODS.forEach(function(method) {
          registerHandler(path.path, method);
        });
      }
    });

    connectMiddleware.register(app);
  };
}<commit_msg>Return to global path registration on restify. Fixes #20, #21, #22<commit_after>'use strict';

module.exports = init;

var debug = require('debug')('swagger:restify_middleware');
var ALL_METHODS = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch'];

function init(runner) {
  return new Middleware(runner);
}

function Middleware(runner) {

  this.runner = runner;

  var connectMiddleware = runner.connectMiddleware();
  var chain = connectMiddleware.middleware();

  this.register = function register(app) {

    // this bit of oddness forces Restify to route all requests through the middleware
    ALL_METHODS.forEach(function(method) {
      app[method]('.*', function(req, res, next) {
        req.query = undefined; // oddly, req.query is a function in Restify, kill it
        chain(req, res, function(err) {
          if (err) { return next(err); }
          if (!res.finished) {
            res.statusCode = 404;
            res.end('Not found');
          }
        });
      });
    });

    connectMiddleware.register(app);
  };
}
{'fraction_non_alphanumeric': 0.14136837335749886, 'fraction_numerical': 0.004531037607612143, 'mean_word_length': 3.1739130434782608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5416871', 'n_tokens_mistral': 660, 'n_tokens_neox': 646, 'n_words': 158}