lib/jsdoc-to-json-schema.js
function buildJsonSchema(comments) {

    // skeleton schema object
    var schema = {
        properties: {
        }
    };

    // go through each comment block
    (comments || []).forEach(function(block) {

        // we're only interested in customTags (none standard jsDoc comments i.e. @schema.)
        (block.customTags || []).forEach(function(item) {

            var tag = item.tag.replace('schema.', '');
            var value = item.value || '';

            // skip properties with no value
            if (value === '') return;

            if (block.scope === 'global') {
                schema[tag] = value;
            }
            else {

                // item is a property
                schema.properties[block.name] = schema.properties[block.name] || {};

                // jsdoc-parse lowercase tag names, so we need more case blocks to correct this
                switch (tag) {

                    /* integers */

                    case 'minimum':
                    case 'maximum': {
                        schema.properties[block.name][tag] = parseInt(value, 10);
                    } break;

                    case 'minitems': {
                        schema.properties[block.name].minItems = parseInt(value, 10);
                    } break;

                    case 'maxitems': {
                        schema.properties[block.name].maxItems = parseInt(value, 10);
                    } break;

                    case 'minlength': {
                        schema.properties[block.name].minLength = parseInt(value, 10);
                    } break;

                    case 'maxlength': {
                        schema.properties[block.name].maxLength = parseInt(value, 10);
                    } break;

                    case 'exclusiveminimum': {
                        schema.properties[block.name].exclusiveMinimum = parseInt(value, 10);
                    } break;

                    case 'exclusivemaximum': {
                        schema.properties[block.name].exclusiveMaximum = parseInt(value, 10);
                    } break;

                    case 'divisibleby': {
                        schema.properties[block.name].divisibleBy = parseInt(value, 10);
                    } break;

                    /* boolean's */

                    case 'required': {
                        schema.properties[block.name][tag] = (value === 'true');
                    } break;

                    case 'uniqueitems': {
                        schema.properties[block.name].uniqueItems = (value === 'true');
                    } break;

                    /* strings */

                    case 'extends':
                    case 'id':
                    case 'type':
                    case 'pattern':
                    case 'title':
                    case 'format':
                    case 'disallow':
                    case 'extends':
                    case 'enum':
                    case 'description':
                    case 'name':
                    case 'default':
                    default: {
                        schema.properties[block.name][tag] = value;
                    } break;
                }
            }

        });
    });

    return schema;
}
function buildJsonSchema(comments) {

    // skeleton schema object
    var schema = {
        properties: {
        }
    };

    // go through each comment block
    (comments || []).forEach(function(block) {

        // we're only interested in customTags (none standard jsDoc comments i.e. @schema.)
        (block.customTags || []).forEach(function(item) {

            var tag = item.tag.replace('schema.', '');
            var value = item.value || '';

            // skip properties with no value
            if (value === '') return;

            if (block.scope === 'global') {
                schema[tag] = value;
            }
            else {

                // item is a property
                schema.properties[block.name] = schema.properties[block.name] || {};

                // jsdoc-parse lowercase tag names, so we need more case blocks to correct this
                switch (tag) {

                    /* integers */

                    case 'minimum':
                    case 'maximum': {
                        schema.properties[block.name][tag] = parseInt(value, 10);
                    } break;

                    case 'minitems': {
                        schema.properties[block.name].minItems = parseInt(value, 10);
                    } break;

                    case 'maxitems': {
                        schema.properties[block.name].maxItems = parseInt(value, 10);
                    } break;

                    case 'minlength': {
                        schema.properties[block.name].minLength = parseInt(value, 10);
                    } break;

                    case 'maxlength': {
                        schema.properties[block.name].maxLength = parseInt(value, 10);
                    } break;

                    case 'exclusiveminimum': {
                        schema.properties[block.name].exclusiveMinimum = parseInt(value, 10);
                    } break;

                    case 'exclusivemaximum': {
                        schema.properties[block.name].exclusiveMaximum = parseInt(value, 10);
                    } break;

                    case 'divisibleby': {
                        schema.properties[block.name].divisibleBy = parseInt(value, 10);
                    } break;

                    /* boolean's */

                    case 'required': {
                        schema.properties[block.name][tag] = (value === 'true');
                    } break;

                    case 'uniqueitems': {
                        schema.properties[block.name].uniqueItems = (value === 'true');
                    } break;

                    /* strings */

                    case 'extends':
                    case 'id':
                    case 'type':
                    case 'pattern':
                    case 'title':
                    case 'format':
                    case 'disallow':
                    case 'extends':
                    case 'enum':
                    case 'description':
                    case 'name':
                    case 'default':
                    default: {
                        schema.properties[block.name][tag] = value;
                    } break;
                }
            }

        });
    });

    return schema;
}
function buildJsonSchema ( comments ) { // skeleton schema object var schema = { properties : { } } ; // go through each comment block ( comments || [ ] ) . forEach ( function ( block ) { // we're only interested in customTags (none standard jsDoc comments i.e. @schema.) ( block . customTags || [ ] ) . forEach ( function ( item ) { var tag = item . tag . replace ( 'schema.' , '' ) ; var value = item . value || '' ; // skip properties with no value if ( value === '' ) return ; if ( block . scope === 'global' ) { schema [ tag ] = value ; } else { // item is a property schema . properties [ block . name ] = schema . properties [ block . name ] || { } ; // jsdoc-parse lowercase tag names, so we need more case blocks to correct this switch ( tag ) { /* integers */ case 'minimum' : case 'maximum' : { schema . properties [ block . name ] [ tag ] = parseInt ( value , 10 ) ; } break ; case 'minitems' : { schema . properties [ block . name ] . minItems = parseInt ( value , 10 ) ; } break ; case 'maxitems' : { schema . properties [ block . name ] . maxItems = parseInt ( value , 10 ) ; } break ; case 'minlength' : { schema . properties [ block . name ] . minLength = parseInt ( value , 10 ) ; } break ; case 'maxlength' : { schema . properties [ block . name ] . maxLength = parseInt ( value , 10 ) ; } break ; case 'exclusiveminimum' : { schema . properties [ block . name ] . exclusiveMinimum = parseInt ( value , 10 ) ; } break ; case 'exclusivemaximum' : { schema . properties [ block . name ] . exclusiveMaximum = parseInt ( value , 10 ) ; } break ; case 'divisibleby' : { schema . properties [ block . name ] . divisibleBy = parseInt ( value , 10 ) ; } break ; /* boolean's */ case 'required' : { schema . properties [ block . name ] [ tag ] = ( value === 'true' ) ; } break ; case 'uniqueitems' : { schema . properties [ block . name ] . uniqueItems = ( value === 'true' ) ; } break ; /* strings */ case 'extends' : case 'id' : case 'type' : case 'pattern' : case 'title' : case 'format' : case 'disallow' : case 'extends' : case 'enum' : case 'description' : case 'name' : case 'default' : default : { schema . properties [ block . name ] [ tag ] = value ; } break ; } } } ) ; } ) ; return schema ; }
Builds a JSON v3 schema based on schema tags found
@param {array} comments - array of jsdoc comment blocks with scope information
@returns {object} JSON Schema object
Builds a JSON v3 schema based on schema tags found