<commit_before>import Kapow from 'kapow';
import validator from 'is-my-json-valid';

function transformErrorFields(input, errors) {
  return errors.map(function(error) {
    var field = error.field.replace(/^data/, input);
    return Kapow(400, field + ' ' + error.message, error);
  });
}

export default function (request, endpoint) {
  var err;
  var schema = endpoint.schema || {};

  for (var prop in schema) {
    var validate = validator(schema[prop] || {});
    if (!validate(request[prop])) {
      err = transformErrorFields(prop, validate.errors);
      break;
    }
  }<commit_msg>Fetch schema from the config, not the endpoint<commit_after>import Kapow from 'kapow';
import validator from 'is-my-json-valid';

function transformErrorFields(input, errors) {
  return errors.map(function(error) {
    var field = error.field.replace(/^data/, input);
    return Kapow(400, field + ' ' + error.message, error);
  });
}

export default function (request, endpoint) {
  var err;
  var schema = endpoint.config.schema || {};

  for (var prop in schema) {
    var validate = validator(schema[prop] || {});
    if (!validate(request[prop])) {
      err = transformErrorFields(prop, validate.errors);
      break;
    }
  }
{'fraction_non_alphanumeric': 0.14355628058727568, 'fraction_numerical': 0.004893964110929853, 'mean_word_length': 3.77431906614786, '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': '2211457', 'n_tokens_mistral': 377, 'n_tokens_neox': 369, 'n_words': 99}