<commit_before>var express = require('express');
var app = express()
var bodyParser = require('body-parser');
var port = process.env.PORT || 3000;

app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));

function buildMongooseScript(classname, fieldContents)
{
    var mystring = 'var mongoose = require("mongoose");\n'+
       'var '+classname+'Schema = mongoose.Schema(\n'+JSON.stringify(fieldContents)+');\n';

    mystring+= "var "+classname+" = mongoose.model('"+classname+"', "+classname+"Schema);\n";
    mystring+= "module.export = "+classname+";\n";
    console.log(mystring);

    return mystring;
}

app.post('/schema', function(req, res) {

    var classes = req.body.classes;
    var names = [];
    var responseToSend = [];
    for(var i = 0; i < classes.length; i++)
    {
        names.push(classes[i].title);

        var fields = classes[i].fields;

        var fieldContents = {};

        for(var j = 0; j < fields.length; j++) {

            var title = fields[j].title;
            var type = fields[j].type;

            if (type === "Schema.types.ObjectId")
            {
                var relationObject = {};
                relationObject["type"] = "Schema.type.ObjectId";
                relationObject["ref"] = fields[j].ref;

                if (fields[j].reftype == "1tm")
                {
                    var holder = [];
                    holder.push(relationObject);
                    relationObject = holder;
                }

                fieldContents[title] = relationObject;
            }
            else
            {
                fieldContents[title] = type;
            }
        }

        var classname = classes[i].title;

        responseToSend.push(buildMongooseScript(classname, fieldContents));
    }

    res.status(200).send(responseToSend);

});


app.listen(port, function() {
    console.log('Listening on PORT ' + port);
});
<commit_msg>Updated code to work with new agreed upon JSON schema<commit_after>var express = require('express');
var app = express()
var bodyParser = require('body-parser');
var port = process.env.PORT || 3000;

app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));

function buildMongooseScript(classname, fieldContents)
{
    var mystring = 'var mongoose = require("mongoose");\n'+
       'var '+classname+'Schema = mongoose.Schema(\n'+JSON.stringify(fieldContents)+');\n';

    mystring+= "var "+classname+" = mongoose.model('"+classname+"', "+classname+"Schema);\n";
    mystring+= "module.export = "+classname+";\n";
    console.log(mystring);

    return mystring;
}

app.post('/schema', function(req, res) {

    var classes = req.body;
    var names = [];
    var responseToSend = [];
    for(var i = 0; i < classes.length; i++)
    {
        names.push(classes[i].title);

        var fields = classes[i].fields;

        var fieldContents = {};

        for(var j = 0; j < fields.length; j++) {

            var title = fields[j].title;
            var type = fields[j].type;

            if (type === "Schema.types.ObjectId")
            {
                var relationObject = {};
                relationObject["type"] = "Schema.type.ObjectId";
                relationObject["ref"] = fields[j].ref;

                if (fields[j].reftype == "1tm")
                {
                    var holder = [];
                    holder.push(relationObject);
                    relationObject = holder;
                }

                fieldContents[title] = relationObject;
            }
            else
            {
                fieldContents[title] = type;
            }
        }

        var classname = classes[i].title;

        responseToSend.push(buildMongooseScript(classname, fieldContents));
    }

    res.status(200).send(responseToSend);

});


app.listen(port, function() {
    console.log('Listening on PORT ' + port);
});

{'fraction_non_alphanumeric': 0.15332326283987915, 'fraction_numerical': 0.005035246727089627, 'mean_word_length': 2.1657370517928287, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1278717', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1125, 'n_words': 225}