codegen.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:ml-rest 作者: apinf 项目源码 文件源码
def generate_handler_stub(router, handler_template=HANDLER_TEMPLATE):
    output = StringIO()
    func_name_to_operation = {}
    for path in router.get_paths():
        for operation in path.get_operations():
            snake_operation_id = camel_case_to_spaces(operation.id).replace(' ', '_')
            func_name_to_operation[snake_operation_id] = operation
    for func_name, operation in sorted(func_name_to_operation.items()):
        parameter_names = [p['name'] for p in operation.parameters]
        handler = handler_template.format(
            func_name=func_name,
            operation_id=operation.id,
            parameters=', '.join(parameter_names),
        )
        output.write(handler)
        output.write('\n\n\n')
    return output.getvalue()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号