<commit_before>var mschema = require("mschema");

module.exports = function validateParamsMiddleware (schema) {
  return function validateParamsHandler (input, output, next) {
    input.resource = input.resource || {};
    input.resource.schema = schema || input.resource.schema  || {};
    input.resource.params = input.resource.params || {};
    //console.log('mschema validate', input.resource.params,  input.resource.schema);
    var validate = mschema.validate(input.resource.params, input.resource.schema, { strict: false });
    //console.log(validate.instance)
    if (validate.valid) {
      input.resource.instance = validate.instance;
      next();
    } else {
      next(new Error(JSON.stringify(validate.errors, true, 2)));
    }
  }
}<commit_msg>[api] [fix] schema plugin should end response   * Ends request when schema invalid   * Actually sending JSON back<commit_after>var mschema = require("mschema");

module.exports = function validateParamsMiddleware (schema) {
  return function validateParamsHandler (input, output, next) {
    input.resource = input.resource || {};
    input.resource.schema = schema || input.resource.schema  || {};
    input.resource.params = input.resource.params || {};
    //console.log('mschema validate', input.resource.params,  input.resource.schema);
    var validate = mschema.validate(input.resource.params, input.resource.schema, { strict: false });
    //console.log(validate.instance)
    if (validate.valid) {
      input.resource.instance = validate.instance;
      next();
    } else {
      // if schema did not validate, end the response immediately
      // send the error as JSON back to the client
      return output.json(validate.errors)
    }
  }
}
{'fraction_non_alphanumeric': 0.1317016317016317, 'fraction_numerical': 0.0005827505827505828, 'mean_word_length': 3.6155913978494625, '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': '3181811', 'n_tokens_mistral': 461, 'n_tokens_neox': 463, 'n_words': 113}