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/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 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);