From 90e0005361feb51c33c86d4d506ebc9c19bc8a15 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 3 Sep 2023 17:24:24 +0800 Subject: [PATCH] 1 --- doc/admin/README.php | 20 ++++++++--------- doc/admin/User.js | 5 +++-- doc/admin/apidoc.json | 7 ++++++ doc/admin/common.js | 10 +++++++++ tools/mydoc/app.js | 51 +++++++++++++++++++++++++++++-------------- 5 files changed, 65 insertions(+), 28 deletions(-) create mode 100644 doc/admin/apidoc.json diff --git a/doc/admin/README.php b/doc/admin/README.php index 03590766..30457d7f 100644 --- a/doc/admin/README.php +++ b/doc/admin/README.php @@ -1,11 +1,11 @@ /** - * @api {GET} AA开发指南 AA开发指南 - * @apiPermission none - * @apiGroup AA开发指南 - * @apiVersion 0.0.1 - * @apiSuccessExample {json} Success-Response: - * 所有的协议都可能携带award和property_chg,award用来显示获得的东西,propery_chg用来更新本地数据 - * - * - * - */ + * @api {GET} AA开发指南 AA开发指南 + * @apiPermission none + * @apiGroup AA开发指南 + * @apiVersion 1.0.0 + * @apiSuccessExample {json} Success-Response: + * 所有的协议都可能携带award和property_chg,award用来显示获得的东西,propery_chg用来更新本地数据 + * + * + * + */ diff --git a/doc/admin/User.js b/doc/admin/User.js index b8545a97..f0fb113e 100644 --- a/doc/admin/User.js +++ b/doc/admin/User.js @@ -10,6 +10,8 @@ module.exports = class { 'desc': '用户登录', 'group': 'User', 'url': 'api/v1/user/login', + 'header': [ + ], 'is_json_params': true, 'params': [ new common.ReqHead(), @@ -27,9 +29,8 @@ module.exports = class { 'desc': '用户登录', 'group': 'User', 'url': 'api/v1/user/info/:user_id', - 'is_json_params': true, 'params': [ - ['!rsp', [new common.RspHead()], 'ok rsp'] + ['user_id', '', 'user_id', 'optional'], ], 'response': [ new common.RspHead(), diff --git a/doc/admin/apidoc.json b/doc/admin/apidoc.json new file mode 100644 index 00000000..4536984f --- /dev/null +++ b/doc/admin/apidoc.json @@ -0,0 +1,7 @@ +{ + "name": "game2006admin", + "version": "1.0.0", + "description": "game2006admin", + "title": "game2006admin", + "url": "https://game2006admin-test.kingsome.cn/" +} diff --git a/doc/admin/common.js b/doc/admin/common.js index 786cc546..e8bd3dd2 100644 --- a/doc/admin/common.js +++ b/doc/admin/common.js @@ -1,3 +1,13 @@ +exports.DefaultHttpHeader = class DefaultHttpHeader { + + constructor() { + this.fields = [ + ['access-key', 'Users unique access-key.'], + ]; + } + +}; + exports.ReqHead = class ReqHead { constructor() { diff --git a/tools/mydoc/app.js b/tools/mydoc/app.js index 391ed508..79760693 100644 --- a/tools/mydoc/app.js +++ b/tools/mydoc/app.js @@ -46,26 +46,46 @@ class Doc const method = item.method ? 'GET' : item.method; this.data += ` /** - * @api {${method}} ${item.url} - * @apiPermission - * @apiGroup ${item.group} - * @apiVersion 1.0 - * @apiDescription ${item.desc} + * @api {${method}} ${item.url} ${item.name} + * @apiPermission none + * @apiGroup ${item.group} + * @apiVersion 1.0.0 + * @apiDescription ${item.desc} `; + const headers = []; + if (item.hasOwnProperty('header')) { + item['header'].forEach( + (item) => { + headers.push(item); + } + ); + } else { + const common = require(resolve('./common')); + headers.push(new common.DefaultHttpHeader()); + } + headers.forEach( + (header) => { + header.fields.forEach( + (field) => { + this.data += ` * @apiHeader {String} ${field[0]} ${field[1]}\n`; + } + ); + } + ); if (item.is_json_params) { - this.data += ` * @apiParamExample {json} 请求样例:\n`; - this.data += ` * {\n`; + this.data += ` * @apiParamExample {json} 请求样例:\n`; + this.data += ` * {\n`; this.asJsonOut(item.params, 1); - this.data += ` * }\n`; + this.data += ` * }\n`; } else { this.asParamOut(item.params); } - this.data += ' * @apiSuccessExample {json} Success-Response:\n'; - this.data += ` * HTTP/1.1 200 OK\n`; - this.data += ` * {\n`; + this.data += ' * @apiSuccessExample {json} Success-Response:\n'; + this.data += ` * HTTP/1.1 200 OK\n`; + this.data += ` * {\n`; this.asJsonOut(item.response, 1); - this.data += ` * }\n`; - this.data += ` */ + this.data += ` * }\n`; + this.data += ` */ `; } ); @@ -85,7 +105,7 @@ class Doc (item) => { if (util.isArray(item)) { const paramType = this.getFieldType(item[1]); - this.data += ` * @apiParam ${paramType} ${item[0]} ${item[2]}\n`; + this.data += ` * @apiParam {${paramType}} ${item[0]} ${item[2]}\n`; } else { this.asParamOut(item.fields); } @@ -107,13 +127,12 @@ class Doc const curIdent = (new Array(ident * 4)).fill(' ').join(''); if (util.isArray(item[1])) { if (item[0].slice(0,1) == '!') { - this.data += ` * ${curIdent}"${item[0].slice(1)}": [ // struct ${item[2]}\n`; + this.data += ` * ${curIdent}"${item[0].slice(1)}": [ // struct ${item[2]}\n`; if (item[1].length == 1) { if (['string', 'number'].indexOf(typeof item[1][0]) >= 0) { this.data += ` * ${curIdent + IDENT}${this.getJsonValue(item[1])}\n`; } else { this.data += ` * ${curIdent + IDENT}{\n`; - console.log(item); this.asJsonOut(item[1][0].fields, ident + 2); this.data += ` * ${curIdent + IDENT}}\n`; }