<commit_before>"use strict";

var _      = require('underscore'),
    assert = require('assert');

var draftSchemas = {
  "draft-03-schema":            require('./drafts/03-schema.json'),
  "draft-04-schema":            require('./drafts/04-schema.json'),
};

var popoloSchemas = {
  "address":                    require('./popolo/address.json'),
  "membership":                 require('./popolo/membership.json'),
  "organization":               require('./popolo/organization.json'),
  "other_name":                 require('./popolo/other_name.json'),
  "person":                     require('./popolo/person.json'),
  "post":                       require('./popolo/post.json'),
};

var allSchemas = _.extend({}, draftSchemas, popoloSchemas);

var urlSchemas = {};
_.each( allSchemas, function (schema) {
  urlSchemas[schema.id] = schema;
});





module.exports = urlSchemas;<commit_msg>Manually replace {$ref: ...} entries with the schema they refer to. Workaround for garycourt/JSV#68<commit_after>"use strict";

var _      = require('underscore'),
    assert = require('assert');

var draftSchemas = {
  "draft-03-schema":            require('./drafts/03-schema.json'),
  "draft-04-schema":            require('./drafts/04-schema.json'),
};

var popoloSchemas = {
  "address":                    require('./popolo/address.json'),
  "membership":                 require('./popolo/membership.json'),
  "organization":               require('./popolo/organization.json'),
  "other_name":                 require('./popolo/other_name.json'),
  "person":                     require('./popolo/person.json'),
  "post":                       require('./popolo/post.json'),
};

var allSchemas = _.extend({}, draftSchemas, popoloSchemas);

var urlSchemas = {};
_.each( allSchemas, function (schema) {
  urlSchemas[schema.id] = schema;
});



// go through all the url schemas and make sure that any $refs are replaced with
// the schema they refer to. This is a workaround for
// https://github.com/garycourt/JSV/issues/68
_.each( popoloSchemas, function (schema) {
  swapOutDollarRefs(schema);
});

function swapOutDollarRefs (data) {
  
  // If we are not a dict or array don't continue
  if (!_.isObject(data)) {
    return;
  }

  // look at all the contents of data to see if it needs swapping
  _.each(data, function (val, key) {
    // Is there a $ref to replace?
    if (_.isObject(val)) {
      if (_.has(val, '$ref')) {
        var $ref = val.$ref;
        var refSchema = urlSchemas[$ref];
        assert(refSchema, "Could not find schema for '" + $ref + "'");

        // swap out the contents
        data[key] = refSchema;
      }
    }
  });


  // recurse down
  _.each(data, swapOutDollarRefs);
    
}


module.exports = urlSchemas;
{'fraction_non_alphanumeric': 0.1599418393311523, 'fraction_numerical': 0.007270083605961469, 'mean_word_length': 2.43142144638404, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3584519', 'n_tokens_mistral': 856, 'n_tokens_neox': 817, 'n_words': 191}