<commit_before>'use strict';

module.exports = init;

var debug = require('debug')('swagger:restify_middleware');

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) {

    // currently requires ownership of request.query, so set it to undefined
    // todo: FIX THIS!
    app.use(function(req, res, next) { req.query = undefined; next(); });

    // this bit of oddness forces Restify to route all requests through the middleware
    ['del', 'get', 'head', 'opts', 'post', 'put', 'patch']
      .forEach(function(method) {
        app[method]('.*', function(req, res, next) {
          chain(req, res, function(err) {
            if (err) { return next(err); }
            if (!res.finished) {
              res.statusCode = 404;
              res.end('Not found');
            }
          });
        });
      });

    connectMiddleware.register(app);
  };
}<commit_msg>enable Restify route handling<commit_after>'use strict';

module.exports = init;

var debug = require('debug')('swagger:restify_middleware');

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;

    api.pathObjects.forEach(function(path) {
      path.operationObjects.forEach(function(operation) {
        app[operation.method](path.path, function(req, res, next) {
          req.query = undefined;
          chain(req, res, next);
        });
      });
    });

    connectMiddleware.register(app);
  };
}
{'fraction_non_alphanumeric': 0.13967391304347826, 'fraction_numerical': 0.0016304347826086956, 'mean_word_length': 3.06401766004415, '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': '4006653', 'n_tokens_mistral': 535, 'n_tokens_neox': 527, 'n_words': 126}