コード例 #1
0
def type_validator(instance, schema, path_stack):
    if 'min' in instance and 'max' in instance:
        if (isinstance(instance['min'], int)
                and isinstance(instance['max'], int)):
            if instance['min'] > instance['max']:
                msg = 'min is greater than max.'
                err_msg = get_error_msg(path_stack, instance, msg)
                raise SchemaValidatorError(err_msg)
        if isinstance(instance['min'], (unicode, str)):
            msg = 'min can not be "unlimited".'
            err_msg = get_error_msg(path_stack, instance, msg)
            raise SchemaValidatorError(err_msg)
    if 'key' in instance and 'value' in instance:
        if 'valueMap' not in instance:
            column_name = get_column_name(path_stack)
            if column_name != 'other_config' and column_name != 'external_ids':
                msg = ('There are no keys defined for this map column ' +
                       '(there is no valueMap).')
                print get_warn_msg(path_stack[:len(path_stack) - 1], '', msg)
    if 'valueMap' in instance:
        if 'max' not in instance:
            msg = 'There is a "valueMap", but no "max" limit defined.'
            print get_warn_msg(path_stack, '', msg)
        else:
            if instance['max'] == 'unlimited':
                msg = ('"max" is "unlimited", but should be bounded to the ' +
                       'number of keys defined in "valueMap".')
                print get_warn_msg(path_stack, '', msg)
            else:
                if instance['max'] != len(instance['valueMap']):
                    msg = ('"max" is not equal to the number of keys defined' +
                           ' in "valueMap".')
                    print get_warn_msg(path_stack, '', msg)
コード例 #2
0
def doc_validator(instance, schema, path_stack):
    ref_mark = ']('
    for line in instance:
        index = line.find(ref_mark)
        while index != -1:
            table, column, key = get_ref(line, index)
            index = line.find(ref_mark, index + len(ref_mark))
            if table is not None:
                tables = schema['tables']
                if table not in tables:
                    msg = ('Wrong reference: table "%s" does not exist in ' +
                           'the schema.') % table
                    err_msg = get_error_msg(path_stack, instance, msg)
                    raise SchemaValidatorError(err_msg)
            if column is not None:
                columns = tables[table]['columns']
                if column not in columns:
                    msg = ('Wrong reference: column "%s" does not exist in ' +
                           'table "%s" in the schema.') % (column, table)
                    err_msg = get_error_msg(path_stack, instance, msg)
                    raise SchemaValidatorError(err_msg)
            if key is not None:
                column_type = columns[column]['type']
                if 'valueMap' not in column_type:
                    msg = ('Wrong reference: column "%s" in table "%s" does' +
                           ' not contain a valueMap.') % (column, table)
                    err_msg = get_error_msg(path_stack, instance, msg)
                    raise SchemaValidatorError(err_msg)
                value_map = column_type['valueMap']
                if key not in value_map:
                    msg = ('Wrong reference: key "%s" is not present in ' +
                           'column "%s" in table "%s" in the schema.') % (
                               key, column, table)
                    err_msg = get_error_msg(path_stack, instance, msg)
                    raise SchemaValidatorError(err_msg)
コード例 #3
0
def keyvalue_validator(instance, schema, path_stack):
    if 'minLength' in instance and 'maxLength' in instance:
        if instance['minLength'] > instance['maxLength']:
            msg = 'minLength is greater than maxLength.'
            err_msg = get_error_msg(path_stack, instance, msg)
            raise SchemaValidatorError(err_msg)
    if 'minInteger' in instance and 'maxInteger' in instance:
        if instance['minInteger'] > instance['maxInteger']:
            msg = 'minInteger is greater than maxInteger.'
            err_msg = get_error_msg(path_stack, instance, msg)
            raise SchemaValidatorError(err_msg)
    if 'minReal' in instance and 'maxReal' in instance:
        if instance['minReal'] > instance['maxReal']:
            msg = 'minReal is greater than maxReal.'
            err_msg = get_error_msg(path_stack, instance, msg)
            raise SchemaValidatorError(err_msg)
コード例 #4
0
def pervalue_validator(instance, schema, path_stack):
    col_type = get_column_type(schema, path_stack)
    for cat in instance:
        if not valid_type(cat['value'], col_type):
            msg = ('Invalid value: "%s" is not the same type as column "%s"'
                   ) % (str(cat['value']), get_column_name(path_stack))
            err_msg = get_error_msg(path_stack, '', msg)
            raise SchemaValidatorError(err_msg)
コード例 #5
0
def follows_validator(instance, schema, path_stack):
    table = get_table(schema, path_stack)
    columns = table['columns']
    if instance not in columns:
        msg = ('Invalid follows: Table "%s" does not have a column named "%s"'
               ) % (get_table_name(path_stack), instance)
        err_msg = get_error_msg(path_stack, instance, msg)
        raise SchemaValidatorError(err_msg)
コード例 #6
0
def reftable_validator(instance, schema, path_stack):
    tables = schema['tables']
    groups = schema['groups']
    if instance not in tables and instance not in groups:
        print "Groups: %s" % groups
        msg = ('Invalid refTable: Table "%s" does not exist in the schema.'
               ) % (instance)
        err_msg = get_error_msg(path_stack, instance, msg)
        raise SchemaValidatorError(err_msg)
コード例 #7
0
def indexes_validator(instance, schema, path_stack):
    table = get_table(schema, path_stack)
    columns = table['columns']
    for index in instance:
        for column in index:
            if column not in columns:
                msg = ('Bad index: table "%s" does not contain a column ' +
                       'named "%s".') % (get_table_name(path_stack), column)
                err_msg = get_error_msg(path_stack, instance, msg)
                raise SchemaValidatorError(err_msg)
コード例 #8
0
def emptyvalue_validator(instance, schema, path_stack):

    last = [path_stack.pop()]

    if 'valueMap' in path_stack:
        # emptyValue for a valueMap
        # Move up to the column definition to extract the valueType
        last.insert(0, path_stack.pop())
        last.insert(0, path_stack.pop())

    parent = get_instance(schema, path_stack)

    path_stack += last
    parent_type = get_instance_type(parent)
    if not valid_type(instance, parent_type):
        msg = 'emptyValue does not have the correct type.'
        err_msg = get_error_msg(path_stack, instance, msg)
        raise SchemaValidatorError(err_msg)