Пример #1
0
def produce_type(type_stmt):
    logging.debug(
        "In produce_type with: %s %s",
        type_stmt.keyword,
        type_stmt.arg,
    )
    type_id = type_stmt.arg

    if types.is_base_type(type_id):
        logging.debug("In produce_type base type: %s %s", type_stmt.keyword,
                      type_stmt.arg)
        if type_id in _numeric_type_trans_tbl:
            type_str = numeric_type_trans(type_id)
        elif type_id in _other_type_trans_tbl:
            type_str = other_type_trans(type_id, type_stmt)
            logging.debug("else case, type_str:%s", type_str)
        else:
            logging.debug("Missing mapping of base type: %s %s",
                          type_stmt.keyword, type_stmt.arg)
            type_str = {"type": "string"}
    elif hasattr(type_stmt, "i_typedef") and type_stmt.i_typedef is not None:
        logging.debug(
            "In produce_type  Found typedef type in: %s %s (typedef) %s",
            type_stmt.keyword, type_stmt.arg, type_stmt.i_typedef)
        #typedef_type_stmt = type_stmt.i_typedef.search_one('type')
        #typedef_type = produce_type(typedef_type_stmt)
        #type_str = typedef_type
        type_str = {"type": type_stmt.arg}
    else:
        logging.debug("Missing mapping of: %s %s", type_stmt.keyword,
                      type_stmt.arg, type_stmt.i_typede)
        type_str = {"type": "string"}
    return type_str
Пример #2
0
def produce_leaf_list(stmt):
    logging.debug("in produce_leaf_list: %s %s", stmt.keyword, stmt.arg)
    arg = qualify_name(stmt)
    type_stmt = stmt.search_one('type')
    type_id = type_stmt.arg

    if types.is_base_type(type_id) or type_id in _other_type_trans_tbl:
        type_str = produce_type(type_stmt)
        result = {arg: {"type": "array", "items": [type_str]}}
    else:
        logging.debug("Missing mapping of base type: %s %s, type: %s",
                      stmt.keyword, stmt.arg, type_id)
        result = {arg: {"type": "array", "items": [{"type": "string"}]}}
    return result
Пример #3
0
def produce_type(type_stmt):
    logging.debug("In produce_type with: %s %s", type_stmt.keyword, type_stmt.arg)
    type_id = type_stmt.arg

    if types.is_base_type(type_id):
        if type_id in _numeric_type_trans_tbl:
            type_str = _numeric_type_trans_tbl[type_id]
        elif type_id in _other_type_trans_tbl:
            type_str = other_type_trans(type_id, type_stmt)
        else:
            logging.debug("Missing mapping of base type: %s %s",
                          type_stmt.keyword, type_stmt.arg)
            type_str = {"type": "string"}
    elif hasattr(type_stmt, "i_typedef") and type_stmt.i_typedef is not None:
        logging.debug("Found typedef type in: %s %s (typedef) %s",
                      type_stmt.keyword, type_stmt.arg, type_stmt.i_typedef)
        type_name = type_stmt.arg.split(':')[-1]
        type_str = { "$ref" : ("#/definitions/type-definitions/definitions/%s" % type_name) }
        update_stats(type_name, 'type-definitions')
    else:
        logging.debug("Missing mapping of: %s %s",
                      type_stmt.keyword, type_stmt.arg, type_stmt.i_typede)
        type_str = {"type": "string"}
    return type_str