all files / generators/spec/ types.js

100% Statements 17/17
100% Branches 6/6
100% Functions 4/4
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                     
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../../commons/utils/utils");
var config_1 = require("../../configs/config");
var schemaUtil_1 = require("../../commons/utils/schemaUtil");
/**
 * Class which holds the logic for generating raml types.
 *
 * @export
 * @class RamlContentGenerator
 */
var RamlContentGenerator = (function () {
    function RamlContentGenerator() {
    }
    /**
     * Generate type file content.
     *
     * @param {Table} table - table schema
     * @return {string} raml content
     */
    RamlContentGenerator.prototype.generateTypeContent = function (table) {
        var objectContent = '#%RAML 1.0 DataType\ntype: object\nproperties:\n';
        table.columns.forEach(function (column) {
            objectContent += utils_1.default.formatLine(config_1.default.DEFAULT_INDENTATION, 0, column.name + ":");
            objectContent += utils_1.default.formatLine(config_1.default.DEFAULT_INDENTATION, 1, "required: " + (column.allowNull ? 'false' : 'true'));
            var typeLine = column.dataType.values ? schemaUtil_1.default.valuesToRamlDataType(column.dataType.values) :
                "" + column.dataType.type + (column.dataType.isArray ? '[]' : '');
            objectContent += utils_1.default.formatLine(config_1.default.DEFAULT_INDENTATION, 1, "type: " + typeLine);
        });
        return objectContent;
    };
    return RamlContentGenerator;
}());
exports.RamlContentGenerator = RamlContentGenerator;
exports.default = new RamlContentGenerator();