zh-cli是什么
工具实现参考了scion。
如何使用
初始化项目
api文档生成
- pip install mkdocs
- zcli mkdocs nodejs | c++
基于mkdocs生成api文档
项目根目录中增加配置文件mkdocs.json
{
mkdocs: {
"site_name": "z-seneca",
"site_favicon": "favicon.ico",
"copyright": "© Zz"
},
apiCfgFilePath: "*.js",
"indexFilePath": "../README.md",
"mdFilePath": [
"../header.md"
]
}
api配置文件:.js、.json
例如定义部门相关api文件department.js:
module.exports = {
name: '部门',
groupName: "Department",
description: "提供部门相关api",
Role: {
description: "部门角色,如:组长,运营总监",
propertys: {
name: {
type: "String",
descrpition: "角色名称",
},
status: {
type: "Enum",
description: "状态。1:可用,2:不可用",
values: [1, 2]
},
}
},
create: {
description: "创建一个部门",
funcType: 'async',
paramsIsObject: true,
method: 'post',
url: '/departments',
params: {
name: {
type: "String",
descrpition: "名称",
required: true,
},
status: {
type: "Enum",
description: "状态。1:可用,2:不可用",
values: [1, 2],
defaultValue: 1,
},
role: {
type: "Role",
}
},
returns: {
name: {
type: "String",
descrpition: "名称",
required: true,
},
status: {
type: "Enum",
description: "状态。1:可用,2:不可用",
values: [1, 2],
defaultValue: 1,
}
},
exampleSuccess: [{
desc: '成功时例子',
params: {
id: 1,
status: 1
},
returns: {
id: 1,
status: 1,
name: 'aa',
}
}, {
desc: '成功时例子',
params: {
id: 1,
status: 1
},
returns: {
id: 1,
status: 1,
name: 'aa',
}
}],
exampleFail: {
desc: '失败时例子',
params: {
id: 1,
status: 1
},
returns: {
id: 1,
status: 1,
name: 'aa',
}
},
}
}
例如定义部门相关api文件department.json:
{
"name": "部门",
"groupName": "Department",
"description": "xxxxxxx",
"Role": {
"description": "部门角色。如:组长,运营总监",
"propertys": {
"name": {
"type": "String",
"descrpition": "角色名称"
},
"status": {
"type": "Enum",
"description": "状态。1:可用,2:不可用",
"values": [1, 2]
}
}
},
"create": {
"params": {
"name": {
"type": "String",
"descrpition": "角色名称",
"required": true
},
"status": {
"type": "Enum",
"description": "状态。1:可用,2:不可用",
"values": [1, 2],
"defaultValue": 1
},
"role": {
"name": {
"type": "String",
"descrpition": "角色名称"
},
"status": {
"type": "RoleStatus",
"description": "角色状态"
}
}
},
"returns": {
"name": {
"type": "String",
"descrpition": "角色名称",
"required": true
},
"status": {
"type": "Enum",
"description": "状态。1:可用,2:不可用。",
"values": [1, 2],
"defaultValue": 1
}
}
}
}
参数,返回值,属性type
支持常用的nodejs,c++等类型。自定义时传自定义类型的名称即可。
其他语言可自定义类型转换表。
引入内置类型:
const dateTypes = require('zh-cli')
dataTypes['c++']
dataTypes['nodejs']
nodejs支持type
{
String: 'String',
Number: 'Number',
Boolean: 'Boolean',
Symbol: 'Symbol',
Object: 'Object',
Enum: 'Enum',
Date: 'Date',
DateTime: 'DateTime',
Function: 'Function',
FuncType: {
kStatic: 'static',
kAsync: 'async',
kStaticAsync: 'static async',
}
}
c++支持type
{
String: 'string',
Int: 'int',
UnsignedInt: 'unsigned int',
SignedInt: 'signed int',
ShortInt: 'short int',
UnsignedShortInt: 'unsigned short int',
SignedShortInt: 'signed short int',
LongInt: 'long int',
SignedLongInt : 'signed long int',
UnsignedLongInt: 'unsigned long int',
Float: 'float',
Double: 'double',
LongDouble: 'long double',
Struct: 'struct',
Boolean: 'bool',
Bool: 'bool',
Void: 'void',
Wchar_t: 'wchar_t',
Char: 'char',
UnsignedChar: 'unsigned char',
SignedChar: 'signed char',
Enum: 'enum',
Date: 'date',
DateTime: 'date time',
Function: 'function',
FuncType: {
kStatic: 'static',
kVirtual: 'virtual',
}
}
帮助
问题反馈
在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流