<commit_before>var RAML = require('./baseraml'),
    Schema = require('../entities/schema'),
    jsonHelper = require('../utils/json'),
    YAML = require('js-yaml');

function RAML08() {}
RAML08.prototype = new RAML();

RAML08.prototype.mapRequestBody = function(methodBody) {
  var data = {mimeType: '', body: {}, example: ''};

  //TODO: only one, the latest is in effect in stoplight!
  for (var i in methodBody) {
    var mimeType = methodBody[i];

    data.mimeType = mimeType.name();
    if (mimeType.example()) {
      data.example = mimeType.example().value();
    }

    if (mimeType.formParameters()) {
      data.body = {
        type: 'object',
        'properties': {},
        'required': []
      };
      var formParams = mimeType.formParameters();
      for (var j in formParams) {
        var param = formParams[j];
        var definition = jsonHelper.parse(YAML.load(param.dump()));

        for (var paramId in definition) {
          var paramValue = definition[paramId];
          data.body.properties[paramId] = paramValue;

          if (paramValue.required && paramValue.required) {
            data.body.required.push(paramId);
          }
        }
      }
    }
    if (mimeType.schema && mimeType.schema()) {
      data.body = jsonHelper.parse(YAML.load(mimeType.dump())[mimeType.name()].schema);
    }
  }

  return data;
};

RAML08.prototype.mapSchema = function(schemData) {
    var schemas = [];
    for (var i in schemData) {
        var schema = schemData[i];
        var schemaName = schema.key();
        var sd = new Schema(schemaName);
        sd.Name = schemaName;
        sd.Definition = RAML08.prototype.convertRefToModel(jsonHelper.parse(YAML.load(schema.dump())[schemaName]));

        schemas.push(sd);
    }
    return schemas;
};

RAML08.prototype.getSchema = function (data) {
    return data.schemas();
};

module.exports = RAML08;
<commit_msg>protect against no body<commit_after>var RAML = require('./baseraml'),
    Schema = require('../entities/schema'),
    jsonHelper = require('../utils/json'),
    YAML = require('js-yaml');

function RAML08() {}
RAML08.prototype = new RAML();

RAML08.prototype.mapRequestBody = function(methodBody) {
  var data = {mimeType: '', body: {}, example: ''};

  //TODO: only one, the latest is in effect in stoplight!
  for (var i in methodBody) {
    var mimeType = methodBody[i];

    data.mimeType = mimeType.name();
    if (mimeType.example()) {
      data.example = mimeType.example().value();
    }

    if (mimeType.formParameters()) {
      data.body = {
        type: 'object',
        'properties': {},
        'required': []
      };
      var formParams = mimeType.formParameters();
      for (var j in formParams) {
        var param = formParams[j];
        var definition = jsonHelper.parse(YAML.load(param.dump()));

        for (var paramId in definition) {
          var paramValue = definition[paramId];
          data.body.properties[paramId] = paramValue;

          if (paramValue.required && paramValue.required) {
            data.body.required.push(paramId);
          }
        }
      }
    }
    if (mimeType.schema && mimeType.schema()) {
      var body = jsonHelper.parse(YAML.load(mimeType.dump()));
      if (body && body[mimeType.name()]) {
        data.body = body[mimeType.name()].schema;
      }
    }
  }

  return data;
};

RAML08.prototype.mapSchema = function(schemData) {
    var schemas = [];
    for (var i in schemData) {
        var schema = schemData[i];
        var schemaName = schema.key();
        var sd = new Schema(schemaName);
        sd.Name = schemaName;

        var def = RAML08.prototype.convertRefToModel(jsonHelper.parse(YAML.load(schema.dump())));
        if (def && def[schemaName]) {
          sd.Definition = def[schemaName];
        }

        schemas.push(sd);
    }
    return schemas;
};

RAML08.prototype.getSchema = function (data) {
    return data.schemas();
};

module.exports = RAML08;

{'fraction_non_alphanumeric': 0.14918946301925026, 'fraction_numerical': 0.0070921985815602835, 'mean_word_length': 2.544883303411131, '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': '2323724', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1213, 'n_words': 255}