Skip to content

Commit 402c1d6

Browse files
author
Ilya Radchenko
committed
Merge pull request #835 from vmadman/master
Added Doc-Blocks for API documentation generation by ApiDoc
2 parents 3ef8ea2 + ea432a0 commit 402c1d6

File tree

9 files changed

+293
-99
lines changed

9 files changed

+293
-99
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Strider Editor/IDE Settings
2+
# This file is used to promote consistent source code standards
3+
# amongst all Strider-CD contributors.
4+
# More information can be found here: http://editorconfig.org/
5+
6+
# General Settings
7+
root = true
8+
9+
# Settings for all files
10+
[*]
11+
indent_style = space
12+
indent_size = 2
13+
end_of_line = lf
14+
charset = utf-8
15+
trim_trailing_whitespace = true
16+
insert_final_newline = true
17+
18+
# Settings specific to Markdown files
19+
[*.md]
20+
trim_trailing_whitespace = false

lib/routes/api/account.js

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ var Project = models.Project;
1111

1212
router.use(auth.requireUserOr401);
1313

14-
/**
15-
* @api {put} /:provider/:id Update a User's provider account
16-
* @apiName UpdateAccount
17-
* @apiGroup Account
18-
*
19-
* @apiParam {String} provider Type of provider, e.g. github
20-
* @apiParam {Number} id Unique provider identification
21-
*/
2214
router.route('/:provider/:id')
15+
16+
/**
17+
* @api {put} /:provider/:id Update Provider Account
18+
* @apiDescription Updates a provider account for the _active_ user (the API user).
19+
* @apiName UpdateAccount
20+
* @apiGroup Account
21+
* @apiVersion 1.0.0
22+
*
23+
* @apiParam {String} provider Type of provider, e.g. github
24+
* @apiParam {Number} id Unique provider identification
25+
*/
2326
.put(function (req, res) {
2427
var accounts = req.user.accounts;
2528
var provider = req.params.provider;
@@ -51,6 +54,17 @@ router.route('/:provider/:id')
5154
res.sendStatus(200);
5255
});
5356
})
57+
58+
/**
59+
* @api {delete} /:provider/:id Delete Provider Account
60+
* @apiDescription Deletes a provider account for the _active_ user (the API user).
61+
* @apiName DeleteAccount
62+
* @apiGroup Account
63+
* @apiVersion 1.0.0
64+
*
65+
* @apiParam {String} provider Type of provider, e.g. github
66+
* @apiParam {Number} id Unique provider identification
67+
*/
5468
.delete(function (req, res) {
5569
var accounts = req.user.accounts;
5670
var provider = req.params.provider;
@@ -94,14 +108,17 @@ router.route('/:provider/:id')
94108
});
95109
});
96110

97-
/*
98-
* POST /api/account/password
99-
*
100-
* Change the password for this account.
101-
*
102-
* <password> - the new password for the account.
103-
*/
104111
router.route('/password')
112+
113+
/**
114+
* @api {post} /password Change Password
115+
* @apiDescription Changes the password for the _active_ user (the API user).
116+
* @apiName ChangePassword
117+
* @apiGroup Account
118+
* @apiVersion 1.0.0
119+
*
120+
* @apiParam (RequestBody) {String{6..}} password The new password, which must be at least 6 characters long.
121+
*/
105122
.post(function(req, res) {
106123
if (req.user !== undefined) {
107124
console.log('password change by ' + req.user.email);
@@ -133,14 +150,17 @@ router.route('/password')
133150
});
134151

135152

136-
/*
137-
* POST /api/account/email
138-
*
139-
* Change the email for this account.
140-
*
141-
* <email> - the new email for the account.
142-
*/
143153
router.route('/email')
154+
155+
/**
156+
* @api {post} /email Change Email
157+
* @apiDescription Changes the email address for the _active_ user (the API user).
158+
* @apiName ChangeEmail
159+
* @apiGroup Account
160+
* @apiVersion 1.0.0
161+
*
162+
* @apiParam (RequestBody) {String} email The new email address. This must be a VALID email address.
163+
*/
144164
.post(function(req, res) {
145165
var newEmail = req.body.email;
146166

lib/routes/api/admin/index.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ var router = express.Router();
1010

1111
router.use(auth.requireAdminOr401);
1212

13-
/*
14-
* GET /admin/users
13+
/**
14+
* @api {get} /admin/users Get All Users
15+
* @apiPermission GlobalAdmin
16+
* @apiDescription Retrieves a list of all Strider users.
17+
* @apiName GetUsers
18+
* @apiGroup Admin
19+
* @apiVersion 1.0.0
20+
*
21+
* @apiExample {curl} CURL Example:
22+
* curl -X GET http://localhost/admin/users
1523
*/
1624
router.route('/users')
1725
.get(function(req, res) {
@@ -29,23 +37,36 @@ router.route('/users')
2937
});
3038
});
3139

32-
/*
33-
* GET /api/admin/jobs_status
34-
* Returns JSON object of last 100 jobs across entire system
40+
/**
41+
* @apiIgnore
42+
* @api {get} /admin/jobs Get Job Status
43+
* @apiPermission GlobalAdmin
44+
* @apiDescription Returns a JSON object of the last 100 jobs executed.
45+
* @apiName GetJobs
46+
* @apiGroup Admin
47+
* @apiVersion 1.0.0
48+
*
49+
* @apiExample {curl} CURL Example:
50+
* curl -X GET http://localhost/admin/jobs
3551
*/
3652
router.route('/jobs')
3753
.get(function(req, res) {
3854
res.send(500, 'Not yet implemented');
3955
});
4056

41-
/*
42-
* POST /api/invite/new
43-
*
44-
* Create & email a new Strider invite. Only core@beyondfog.com may use this.
57+
/**
58+
* @api {post} /invite/new Send Invite
59+
* @apiPermission GlobalAdmin
60+
* @apiDescription Create & email a new Strider invite.
61+
* @apiName SendInvite
62+
* @apiGroup Admin
63+
* @apiVersion 1.0.0
4564
*
46-
* <invite_code> - Invite token string to set.
47-
* <email> - Email to send to.
65+
* @apiExample {curl} CURL Example:
66+
* curl -X POST -d invite_code=xoxox -d email=new_guy@strider-cd.com http://localhost/invite/new
4867
*
68+
* @apiParam (RequestBody) {String} invite_code The invite code/token to use in the invitation
69+
* @apiParam (RequestBody) {String} email The email address of the new user being invited
4970
*/
5071
router.route('/invite/new')
5172
.post(function (req, res) {
@@ -68,6 +89,20 @@ router.route('/invite/new')
6889
});
6990
});
7091

92+
/**
93+
* @api {post} /invite/revoke Revoke Invite
94+
* @apiPermission GlobalAdmin
95+
* @apiDescription Revokes a previously sent Strider invitation.
96+
* @apiName RevokeInvite
97+
* @apiGroup Admin
98+
* @apiVersion 1.0.0
99+
*
100+
* @apiExample {curl} CURL Example:
101+
* curl -X POST -d invite_code=xoxox http://localhost/invite/revoke
102+
*
103+
* @apiParam (RequestBody) {String} invite_code The invite code/token of the invite
104+
* being revoked.
105+
*/
71106
router.route('/invite/revoke')
72107
.post(function (req, res) {
73108
var inviteCode = requireBody('invite_code', req, res);

lib/routes/api/branches.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
'use strict';
22

3+
34
var express = require('express');
45
var Project = require('../../models').Project
56
var middleware = require('../../middleware');
67
var router = express.Router();
78
var requireBody = middleware.requireBody;
89
var root = router.route('/');
910

10-
/*
11-
* POST /:org/:repo/branches/
11+
/**
12+
* @api {post} /:org/:repo/branches Add Branch
13+
* @apiUse ProjectReference
14+
* @apiPermission ProjectAdmin
15+
* @apiDescription Add a new branch for a project.
16+
* @apiName AddBranch
17+
* @apiGroup Branch
18+
* @apiVersion 1.0.0
1219
*
13-
* Add a new branch for a project. You must have admin privileges on the corresponding RepoConfig
14-
* to be able to use this endpoint.
20+
* @apiExample {curl} CURL Example:
21+
* curl -X POST -d name=newbranch http://localhost/api/strider/strider-cd/branches
1522
*
23+
* @apiParam (RequestBody) {String} name The name of the new branch
1624
*/
1725
root.post(requireBody(['name']), function (req, res) {
1826
req.project.addBranch(req.body.name, function (err, branch) {
@@ -21,11 +29,19 @@ var root = router.route('/');
2129
})
2230
});
2331

24-
/*
25-
* PUT /:org/:repo/branches/
32+
/**
33+
* @api {put} /:org/:repo/branches Reorder Branches
34+
* @apiUse ProjectReference
35+
* @apiPermission ProjectAdmin
36+
* @apiDescription Updates the branch order for a project.
37+
* @apiName ReorderBranches
38+
* @apiGroup Branch
39+
* @apiVersion 1.0.0
2640
*
27-
* Used to update the order of branches
41+
* @apiExample {curl} CURL Example:
42+
* curl -X PUT -d branches=master,testing http://localhost/api/strider/strider-cd/branches
2843
*
44+
* @apiParam (RequestBody) {String} branches The new branch order, comma delimited
2945
*/
3046
root.put(requireBody(['branches']), function (req, res) {
3147
var branches = req.body.branches
@@ -39,11 +55,19 @@ var root = router.route('/');
3955
})
4056
});
4157

42-
/*
43-
* DELETE /:org/:repo/branches/
58+
/**
59+
* @api {delete} /:org/:repo/branches Delete Branch
60+
* @apiUse ProjectReference
61+
* @apiPermission ProjectAdmin
62+
* @apiDescription Deletes a branch from a project
63+
* @apiName DeleteBranch
64+
* @apiGroup Branch
65+
* @apiVersion 1.0.0
4466
*
45-
* Delete the specified branch from the project
67+
* @apiExample {curl} CURL Example:
68+
* curl -X DELETE -d name=mybranch http://localhost/api/strider/strider-cd/branches
4669
*
70+
* @apiParam (RequestBody) {String} name The name of the branch to delete
4771
*/
4872
root.delete(requireBody(['name']), function (req, res) {
4973
var name = req.body.name

lib/routes/api/collaborators/index.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ module.exports = {
1515
}
1616

1717

18-
/*
19-
* GET /:org/:repo/collaborators
18+
/**
19+
* @api {get} /:org/:repo/collaborators Get Collaborators
20+
* @apiUse ProjectReference
21+
* @apiDescription Gets a list of collaborators for a project
22+
* @apiName GetCollaborators
23+
* @apiGroup Collaborators
24+
* @apiVersion 1.0.0
2025
*
21-
* Get the current list of collaborators for the Github repository.
22-
*
23-
* @param url Github html_url of the project.
26+
* @apiExample {curl} CURL Example:
27+
* curl -X GET http://localhost/api/strider/strider-cd/collaborators
2428
*/
2529
function get(req, res) {
2630
var project = req.params.org + '/' + req.params.repo;
@@ -45,15 +49,23 @@ function get(req, res) {
4549
});
4650
}
4751

48-
/*
49-
* POST /:org/:repo/collaborators/
52+
/**
53+
* @api {post} /:org/:repo/collaborators Add Collaborator
54+
* @apiUse ProjectReference
55+
* @apiPermission ProjectAdmin
56+
* @apiDescription Add a new collaborator to a repository/project.
57+
* @apiName AddCollaborator
58+
* @apiGroup Collaborators
59+
* @apiVersion 1.0.0
5060
*
51-
* Add a new collaborator for a Github repository. You must have admin privileges on the corresponding RepoConfig
52-
* to be able to use this endpoint.
61+
* @apiExample {curl} CURL Example:
62+
* curl -X GET http://localhost/api/strider/strider-cd/collaborators?email=new_guy@strider-cd.com&access_level=2
5363
*
54-
* @param email Email address to add. If the user is not registered with Strider, we will send them an invite. If
55-
* they are already registered, they will receive a notification of access.
56-
* @param access_level Access level to grant. 0 = read-only, 2 = admin (default: 0)
64+
* @apiParam (RequestBody) {String} email Email address to add. If the user is
65+
* not registered with Strider, we will send them an invite. If they are already
66+
* registered, they will receive a notification of access.
67+
* @apiParam (RequestBody) {Number} access_level=0 Access level to grant to the
68+
* new collaborator. This can be `0`, for read only access, or `2` for admin access.
5769
*/
5870
function post(req, res) {
5971
var project = req.params.org + '/' + req.params.repo
@@ -67,12 +79,19 @@ function post(req, res) {
6779
})
6880
}
6981

70-
/*
71-
* DELETE /:org/:repo/collaborators/
82+
/**
83+
* @api {delete} /:org/:repo/collaborators Delete Collaborator
84+
* @apiUse ProjectReference
85+
* @apiPermission ProjectAdmin
86+
* @apiDescription Remove a collaborator from a repository/project.
87+
* @apiName DeleteCollaborator
88+
* @apiGroup Collaborators
89+
* @apiVersion 1.0.0
7290
*
73-
* Delete the specified user from the list of collaborators for the Github repository.
91+
* @apiExample {curl} CURL Example:
92+
* curl -X DELETE -d email=old_guy@strider-cd.com http://localhost/api/strider/strider-cd/collaborators
7493
*
75-
* @param email Email of the user.
94+
* @apiParam (RequestBody) {String} email Email address to remove from the repo/project.
7695
*/
7796
function del(req, res) {
7897
var project = req.params.org + '/' + req.params.repo

lib/routes/api/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,36 @@ router.use('/account', require('./account'));
77
router.use('/admin', require('./admin'));
88

99
module.exports = router;
10+
11+
12+
// Globals & Commons for ApiDoc ..
13+
14+
/**
15+
* @apiDefine RequestUrl Request URL Parameters
16+
* Indicates that this parameter should be specified in the request URL.
17+
*/
18+
19+
/**
20+
* @apiDefine RequestBody Request Body Parameters
21+
* Indicates that this parameter should be specified in the request body.
22+
*/
23+
24+
/**
25+
* @apiDefine ProjectAdmin
26+
* You must have admin privileges on the corresponding RepoConfig to be able to use this endpoint.
27+
*/
28+
29+
/**
30+
* @apiDefine GlobalAdmin
31+
* You must have admin privileges in Strider (globally) in order to use this endpoint.
32+
*/
33+
34+
/**
35+
* @apiDefine ProjectReference
36+
*
37+
* @apiParam (RequestUrl) {String} org The organization name for the project. This is
38+
* usually a GitHub user or organization name (e.g. "strider" in "strider/strider-cd")
39+
* but may vary from one project provider to another. (as another example,
40+
* in GitLab this refers to the repository's "group").
41+
* @apiParam (RequestUrl) {String} repo The project's repository name.
42+
*/

0 commit comments

Comments
 (0)