Score
0
Watch 3 Star 5 Fork 0

CornWu / ApiPluginsFramework Python

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
ApiPluginsFramework是Web Api插件框架,使用Flask作为Http协议处理,使用flasgger作为Http测试。 让开发者只关注于业务,业务体现在插件实现中。 插件模块中通过@plugin_base.ModuleFunc来设置Api信息 欢迎各位一起加入和完善更多的功能,让ApiPluginsFramework开发更加简便和强大,让ApiPluginsFramework下的插件更加丰富 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

说明

ApiPluginsFramework是Web Api插件框架,使用Flask作为Http协议处理,使用flasgger作为Http测试。
让开发者只关注于业务,业务体现在插件实现中。

插件模块中通过@plugin_base.ModuleFunc来设置Api信息

欢迎各位一起加入和完善更多的功能,让ApiPluginsFramework开发更加简便和强大,让ApiPluginsFramework下的插件更加丰富

代码目录结构

.
├── README.MD
├── docs (文档)
│  
├── src (源码)
│   ├── core(核心)
│   └── libs(库)
│   └── plugins(插件)
│   └── utils(公共)
└── main.py (启动主程序)

插件目录结构

.ApiPluginsFramework
    │---Plugins

            │---Plugin1(插件目录)
            │   ├── __init__.py(插件定义文件)
            │   └── plugin_moduleX.py(插件模块文件)

            │---Plugin2(插件目录)
            │   ├── __init__.py(插件定义文件)
            │   └── plugin_moduleX.py(插件模块文件)

运行环境

python 2.7.*

requirements

flask
flasgger
logging

运行

python main.py

插件开发规范

插件定义__init__.py文件写法

#: 插件类定义
class Plugin1(plugin_base.PluginBase):
    #: 插件初始化方法
    def __init__(self, pluginName,pluginPath):
        super(Plugin1, self).__init__(pluginName,pluginPath)

    #: 实现关于插件信息接口
    def GetAbout(self):
        return {
            "plugin_version": "1.0.0.1",
            "plugin_author": "CornWu",
            "plugin_description": "测试插件",
            "plugin_copyright": "海南新境界软件有限公司",
            "plugin_pubdate": "2018-08-20",
        }
#: 创建插件实例接口
def createPluginInstance(pluginName,pluginPath):
    return Plugin1(pluginName,pluginPath)

插件模块plugin_module1.py文件写法(这里就专注业务实现)

# -*- coding: utf-8 -*-
from libs import plugin_base

@plugin_base.ModuleFunc("/test.do",
                        ApiOperation = {
                            "Name": "测试功能1",
                            "Description": "测试功能1描述",
                            "NeedAuth": False
                        },
                        ApiParameter = {
                            "Description": "用户信息",
                            "Properties": {
                                "UserID": { "DataType": "string", "Description": "用户ID", "Required": True },
                                "UserName": { "DataType": "string", "Description": "用户姓名", "Required": True },
                                "UserStatus": { "DataType": "string", "Description": "用户状态", "Enum": ["Stop","Start"], "Required": True },
                                "UserDept": {
                                    "DataType": "object", "Description": "组织机构", "Required": True,
                                    "Properties": {
                                        "DeptID": { "DataType": "string", "Description": "部门ID", "Required": True },
                                        "DeptName": { "DataType": "string", "Description": "部门名称", "Required": True }
                                    }
                                },
                                "UserCorps": {
                                    "DataType": "array", "Description": "用户公司", "Required": True,
                                    "Items": {
                                        "DataType": "string"
                                    }
                                },
                                "UserRoles": {
                                    "DataType": "array", "Description": "用户角色", "Required": True,
                                    "Items": {
                                        "DataType": "object",
                                        "Properties": {
                                            "RoleID": {"DataType": "string", "Description": "角色ID", "Required": True},
                                            "RoleName": {"DataType": "string", "Description": "角色名称", "Required": True}
                                        }
                                    }
                                }
                            }
                        },
                        ApiResponse = {
                            "Description": "部门信息",
                            "DataType": "string",
                            "Properties": {
                                "DeptID": {"DataType": "string", "Description": "部门ID", "Required": True},
                                "DeptName": {"DataType": "string", "Description": "部门名称", "Required": True}
                            }
                        }
                        )
def PluginModuleFunc1(inParameter):
    isExist = inParameter.HasAttr("UserName")
    return inParameter.UserName

相关运行截图,基于ApiPluginsFramework

Flasgger界面

Flasgger1

Flasgger2

JS自动生成相关截图,基于ApiPluginsFramework

JS页面

ApiJs

ApiJs

Comments ( 0 )

Sign in for post a comment

Python
1
https://gitee.com/CornWu/ApiPluginsFramework.git
git@gitee.com:CornWu/ApiPluginsFramework.git
CornWu
ApiPluginsFramework
ApiPluginsFramework
master

Help Search