From 7593a3d6e2498a4e8f4d235de1e0d46c19aa89d6 Mon Sep 17 00:00:00 2001 From: hhdem Date: Sun, 9 Apr 2017 16:07:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=BD=BF=E7=94=A8apidoc=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=94=9F=E6=88=90api=E9=9D=99=E6=80=81=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E7=9C=81=E5=8E=BB=E7=BB=B4=E6=8A=A4=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=202.=20=E5=8E=BB=E6=8E=89=E5=8E=9F=E6=9C=89=E7=9A=84a?= =?UTF-8?q?pi=E6=8E=A5=E5=8F=A3=203.=20=E9=9D=99=E6=80=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6apidoc=E7=9A=84=E7=94=9F=E6=88=90=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=9C=A8public/apidoc=204.=20=E5=A2=9E=E5=8A=A0public/apidoc?= =?UTF-8?q?=E5=88=B0gitignore=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + api/v1/topic.js | 43 +++++++++++++++++++++++++++++++++++++++++++ config.default.js | 1 + controllers/static.js | 3 --- package.json | 4 +++- views/layout.html | 1 - web_router.js | 1 - 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ab05ebd6ba..b682d31b39 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ desktop.ini .idea public/upload/* +public/apidoc/* *.sublime-project *.sublime-workspace diff --git a/api/v1/topic.js b/api/v1/topic.js index 910fa071c7..8992c1ccfc 100644 --- a/api/v1/topic.js +++ b/api/v1/topic.js @@ -11,6 +11,49 @@ var at = require('../../common/at'); var renderHelper = require('../../common/render_helper'); var validator = require('validator'); + +/** + * @api {get} /v1/topics 主题列表 + * @apiDescription + * 获取本站主题列表 + * @apiName getTopics + * @apiGroup topic + * + * @apiParam {Number} page 页数 + * @apiParam {String} tab 主题分类。目前有 ask share job good + * @apiParam {Number} limit 每一页的主题数量 + * @apiParam {String} mdrender 当为 false 时,不渲染。默认为 true,渲染出现的所有 markdown 格式文本 + * + * @apiPermission none + * @apiSampleRequest /v1/topics + * + * @apiVersion 1.0.0 + * + * @apiSuccessExample Success-Response: + * HTTP/1.1 200 OK + * { + "success": true, + "data": [ + { + "id": "", + "author_id": "", + "tab": "ask", + "content": "", + "title": "", + "last_reply_at": "", + "good": false, + "top": false, + "reply_count": 2, + "visit_count": 8, + "create_at": "", + "author": { + "loginname": "admin", + "avatar_url": "//gravatar.com/avatar/80579ac37c768d5dffa97b46bb4754f2?size=48" + } + } + ] + } + */ var index = function (req, res, next) { var page = parseInt(req.query.page, 10) || 1; page = page > 0 ? page : 1; diff --git a/config.default.js b/config.default.js index f00dbf23df..6f1438c31d 100644 --- a/config.default.js +++ b/config.default.js @@ -23,6 +23,7 @@ var config = { // 右上角的导航区 site_navs: [ // 格式 [ path, title, [target=''] ] + [ '/public/apidoc/', 'API' ], [ '/about', '关于' ] ], // cdn host,如 http://cnodejs.qiniudn.com diff --git a/controllers/static.js b/controllers/static.js index b1b3f6fe67..d690a98ed9 100644 --- a/controllers/static.js +++ b/controllers/static.js @@ -32,6 +32,3 @@ exports.robots = function (req, res, next) { })); }; -exports.api = function (req, res, next) { - res.render('static/api'); -}; diff --git a/package.json b/package.json index 306542427f..391aadca11 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "xss": "0.2.10" }, "devDependencies": { + "apidoc": "^0.17.5", "errorhandler": "1.4.3", "istanbul": "0.4.2", "loader-connect": "1.0.1", @@ -64,6 +65,7 @@ "supertest": "1.2.0" }, "scripts": { - "test": "make test" + "test": "make test", + "apidoc": "./node_modules/.bin/apidoc -i api/ -o public/apidoc" } } diff --git a/views/layout.html b/views/layout.html index 7dfbcef1d1..a26c573ce0 100644 --- a/views/layout.html +++ b/views/layout.html @@ -91,7 +91,6 @@ <% } %>
  • 新手入门
  • -
  • API
  • <% var site_navs = config.site_navs || []; for (var i = 0, l = site_navs.length; i < l; i++) { diff --git a/web_router.js b/web_router.js index a71b0f318e..7cedcad38c 100644 --- a/web_router.js +++ b/web_router.js @@ -104,7 +104,6 @@ router.get('/about', staticController.about); router.get('/faq', staticController.faq); router.get('/getstart', staticController.getstart); router.get('/robots.txt', staticController.robots); -router.get('/api', staticController.api); //rss router.get('/rss', rss.index); From aea20c840c67339e7a477ab01919f5427654620d Mon Sep 17 00:00:00 2001 From: git Date: Sun, 9 Apr 2017 16:16:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=20apidoc=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apidoc.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 apidoc.json diff --git a/apidoc.json b/apidoc.json new file mode 100644 index 0000000000..36c5ad9f4e --- /dev/null +++ b/apidoc.json @@ -0,0 +1,10 @@ +{ + "name": "API说明", + "version": "1.0.0", + "description": "API接口文档", + "apidoc": { + "title": "API接口文档", + "url" : "/api" + }, + "sampleUrl": "http://localhost:3000/api" +} \ No newline at end of file