<commit_before>'use strict';

var config = require('./config'),
    raml = require('raml-parser'),
    YAML = require('yamljs'),
    validate = require('./validate'),
    _ = require('lodash');

var buildPhraseDefinition = function(phrase) {
    var doc = {};

    var url = '/' + phrase.url;
    doc[url] = {};

    ['get', 'post', 'put', 'delete', 'options'].forEach(function(method) {
        if (phrase[method]) {
            validate.isValue(phrase[method].doc, 'undefined:phrase:' + method + ':doc');
            doc[url][method] = phrase[method].doc;

            // oauth_2_0 has specific type for common header documentation
            if (phrase[method].doc && phrase[method].doc.securedBy && phrase[method].doc.securedBy.indexOf('oauth_2_0') !== -1) {
                doc[url].type = 'secured';
            }
        }
    });

    return doc;
};

/**
 * Builds a raml definition from the doc contained into a phrase
 * @param  {String} domain
 * @param  {Object} phrase
 * @return {String}
 */<commit_msg>RAML uriParams support<commit_after>'use strict';

var config = require('./config'),
    raml = require('raml-parser'),
    YAML = require('yamljs'),
    validate = require('./validate'),
    _ = require('lodash');

var buildPhraseDefinition = function(phrase) {
    var doc = {};

    // convert express URL `path/:param1/:param2` to
    // RAML URL`path/{param1}/{param2}`
    var url = phrase.url.split('/');
    url = url.map(function(item) {
        if (item[0] === ':') {
            item = item.replace(':', '{').replace('?', '');
            item += '}';
        }
        return item;
    }).join('/');

    url = '/' + url;
    doc[url] = {};

    ['get', 'post', 'put', 'delete', 'options'].forEach(function(method) {
        if (phrase[method]) {
            validate.isValue(phrase[method].doc, 'undefined:phrase:' + method + ':doc');
            doc[url][method] = phrase[method].doc;

            // oauth_2_0 has specific type for common header documentation
            if (phrase[method].doc && phrase[method].doc.securedBy && phrase[method].doc.securedBy.indexOf('oauth_2_0') !== -1) {
                doc[url].type = 'secured';
            }
        }
    });

    return doc;
};

/**
 * Builds a raml definition from the doc contained into a phrase
 * @param  {String} domain
 * @param  {Object} phrase
 * @return {String}
 */
{'fraction_non_alphanumeric': 0.18308668076109938, 'fraction_numerical': 0.006342494714587738, 'mean_word_length': 2.5419161676646707, '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': '2810764', 'n_tokens_mistral': 737, 'n_tokens_neox': 712, 'n_words': 162}