Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加apidoc模块生成api文档,不过接口描述我只写了一个 #939

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ desktop.ini

.idea
public/upload/*
public/apidoc/*

*.sublime-project
*.sublime-workspace
Expand Down
43 changes: 43 additions & 0 deletions api/v1/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions apidoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "API说明",
"version": "1.0.0",
"description": "API接口文档",
"apidoc": {
"title": "API接口文档",
"url" : "/api"
},
"sampleUrl": "http://localhost:3000/api"
}
1 change: 1 addition & 0 deletions config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var config = {
// 右上角的导航区
site_navs: [
// 格式 [ path, title, [target=''] ]
[ '/public/apidoc/', 'API' ],
[ '/about', '关于' ]
],
// cdn host,如 http://cnodejs.qiniudn.com
Expand Down
3 changes: 0 additions & 3 deletions controllers/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ exports.robots = function (req, res, next) {
}));
};

exports.api = function (req, res, next) {
res.render('static/api');
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
1 change: 0 additions & 1 deletion views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
</li>
<% } %>
<li><a href='/getstart'>新手入门</a></li>
<li><a href='/api'>API</a></li>
<%
var site_navs = config.site_navs || [];
for (var i = 0, l = site_navs.length; i < l; i++) {
Expand Down
1 change: 0 additions & 1 deletion web_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down