|
| 1 | +# Documentation |
| 2 | + |
| 3 | +In this project we try our level best to document the code so that the any new |
| 4 | +developer can easily chip in and understand what is going on. We highly recommend |
| 5 | +that you document any piece of code your are adding on this project. |
| 6 | + |
| 7 | +Below is our recommendation when documenting routers in API modules. It is not |
| 8 | +an exhaustive list but it will act as a starting point when we are documenting |
| 9 | +routers for API modules. |
| 10 | + |
| 11 | +## API Router Documentation |
| 12 | + |
| 13 | +For API routes documentation we use [apidoc](http://apidocjs.com/) which generate |
| 14 | +API documentation directly from block comments from the codes. |
| 15 | + |
| 16 | +### Route Documentation |
| 17 | + |
| 18 | +While documenting a route we recommend the comments to have the following |
| 19 | + |
| 20 | +- @api |
| 21 | +- @apiVersion |
| 22 | +- @apiName |
| 23 | +- @apiGroup |
| 24 | +- @apiDescription |
| 25 | +- @apiUse RequestHeaders |
| 26 | +- @apiUse [*Success returned object format*] |
| 27 | +- @apiUse RequestHeadersExample |
| 28 | +- @apiUse [*Success response example*] |
| 29 | +- @apiUse JWTError |
| 30 | +- @apiUse JWTErrorExample |
| 31 | +- @apiUse AuthorizationHeaderError |
| 32 | +- @apiUse AuthorizationHeaderErrorExample |
| 33 | + |
| 34 | +```js |
| 35 | +/** |
| 36 | + * @api {get} /jurisdictions List Jurisdictions |
| 37 | + * @apiVersion 1.0.0 |
| 38 | + * @apiName GetJurisdictions |
| 39 | + * @apiGroup Jurisdiction |
| 40 | + * @apiDescription Returns a list of jurisdictions |
| 41 | + * @apiUse RequestHeaders |
| 42 | + * @apiUse Jurisdictions |
| 43 | + * |
| 44 | + * @apiUse RequestHeadersExample |
| 45 | + * @apiUse JurisdictionsSuccessResponse |
| 46 | + * @apiUse JWTError |
| 47 | + * @apiUse JWTErrorExample |
| 48 | + * @apiUse AuthorizationHeaderError |
| 49 | + * @apiUse AuthorizationHeaderErrorExample |
| 50 | + */ |
| 51 | +router.get(PATH_LIST, function getJurisdictions(request, response, next) { |
| 52 | + ... |
| 53 | +} |
| 54 | +``` |
| 55 | +
|
| 56 | +For RequestHeaders, RequestHeadersExample, JWTError, JWTErrorExample, |
| 57 | +AuthorizationHeaderError and AuthorizationHeaderErrorExample apidocs comments are |
| 58 | +already defined in [majifix-common](https://github.com/CodeTanzania/majifix-common) module. |
| 59 | +To use it you just have to include it in your apidoc build system. |
| 60 | +
|
| 61 | +This is an example of configuring apidoc grunt plugin to read apidoc comments from |
| 62 | +[majifix-common](https://github.com/CodeTanzania/majifix-common) |
| 63 | +
|
| 64 | +```js |
| 65 | +apidoc: { |
| 66 | + api: { |
| 67 | + src: ['node_modules/@codetanzania/majifix-common/lib', 'lib/'], |
| 68 | + dest: 'docs/', |
| 69 | + options: { |
| 70 | + debug: true, |
| 71 | + includeFilters: ['.*\\.js$'], |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | +
|
| 77 | +For Success returned object format and Success response example should be defined in the router file as shown in below examples: |
| 78 | +
|
| 79 | +```js |
| 80 | +/** |
| 81 | + * @apiDefine Jurisdictions |
| 82 | + * @apiSuccess {Object[]} data List of jurisdictions |
| 83 | + * @apiSuccess {String} data._id Unique jurisdiction identifier |
| 84 | + * @apiSuccess {String} [data.jurisdiction = undefined] jurisdiction under |
| 85 | + * which this jurisdiction belongs |
| 86 | + * @apiSuccess {String} data.code Unique human readable coded name of |
| 87 | + * the jurisdiction. Used in deriving service request code |
| 88 | + * @apiSuccess {String} data.name Unique human readable name of the jurisdiction |
| 89 | + * @apiSuccess {String} data.phone Primary mobile phone number used to |
| 90 | + * contact jurisdiction |
| 91 | + * @apiSuccess {String} data.email Primary email address used to contact |
| 92 | + * jurisdiction direct |
| 93 | + * @apiSuccess {String} [data.website] Primary website url of the jurisdiction |
| 94 | + * @apiSuccess {String} [data.about] A brief summary about jurisdiction |
| 95 | + * if available i.e additional details that clarify what a jurisdiction do |
| 96 | + * @apiSuccess {String} [data.address] Human readable physical address of |
| 97 | + * jurisdiction office |
| 98 | + * @apiSuccess {String} [data.color] A color code(in hexadecimal format) |
| 99 | + * eg. #363636 used to differentiate jurisdictions visually |
| 100 | + * @apiSuccess {Point} [data.location] A center of jurisdiction. Its an |
| 101 | + * office reachable by citizen(or customer) |
| 102 | + * @apiSuccess {MultiPolygon} [data.boundaries] Jurisdiction boundaries. |
| 103 | + * Its mainly used for geo lookup of service request jurisdiction |
| 104 | + * based on its geo coordinates. |
| 105 | + * @apiSuccess {Date} data.createdAt Date when jurisdiction was created |
| 106 | + * @apiSuccess {Date} data.updatedAt Date when jurisdiction was last updated |
| 107 | + * @apiSuccess {Number} total Total number of jurisdiction |
| 108 | + * @apiSuccess {Number} size Number of jurisdiction returned |
| 109 | + * @apiSuccess {Number} limit Query limit used |
| 110 | + * @apiSuccess {Number} skip Query skip/offset used |
| 111 | + * @apiSuccess {Number} page Page number |
| 112 | + * @apiSuccess {Number} pages Total number of pages |
| 113 | + * @apiSuccess {Date} lastModified Date and time at which latest jurisdiction |
| 114 | + * was last modified |
| 115 | + */ |
| 116 | + |
| 117 | + |
| 118 | +/** |
| 119 | + * @apiDefine JurisdictionsSuccessResponse |
| 120 | + * @apiSuccessExample {json} Success-Response: |
| 121 | + * { |
| 122 | + * "data": [ |
| 123 | + * { |
| 124 | + * "_id": "5aef42d59748e41e02e2a562", |
| 125 | + * "jurisdiction": { |
| 126 | + * "_id": "5af2aad4408ccb594b173f96", |
| 127 | + * "code": "84105193", |
| 128 | + * "name": "Faroe Islands" |
| 129 | + * }, |
| 130 | + * "code": "66230485", |
| 131 | + * "name": "Kunze and Sons", |
| 132 | + * "phone": "1-964-200-3838 x5726", |
| 133 | + * "email": "mazie_bayer@hotmail.com", |
| 134 | + * "website": "vilma.net", |
| 135 | + * "about": "Molestias culpa porro pariatur.", |
| 136 | + * "address": "6552 Haven Prairie", |
| 137 | + * "color": "#b32acc", |
| 138 | + * "location": { |
| 139 | + * "type": "Point", |
| 140 | + * "coordinates": [ |
| 141 | + * -77.5707764925392, |
| 142 | + * 39.880937519031235 |
| 143 | + * ] |
| 144 | + * }, |
| 145 | + * "boundaries": { |
| 146 | + * "type": "MultiPolygon", |
| 147 | + * "coordinates": [ |
| 148 | + * [ |
| 149 | + * [ |
| 150 | + * [ |
| 151 | + * -76.80207859497996, |
| 152 | + * 55.69469494228919 |
| 153 | + * ], |
| 154 | + * [ |
| 155 | + * -75.71404588095427, |
| 156 | + * 53.59198291229545 |
| 157 | + * ], |
| 158 | + * [ |
| 159 | + * -73.49941546156064, |
| 160 | + * 47.7536674960849 |
| 161 | + * ], |
| 162 | + * [ |
| 163 | + * -78.24692848453104, |
| 164 | + * 51.75424604090497 |
| 165 | + * ], |
| 166 | + * [ |
| 167 | + * -77.96718998971203, |
| 168 | + * 43.532912808667284 |
| 169 | + * ], |
| 170 | + * [ |
| 171 | + * -80.05583147381611, |
| 172 | + * 51.2655718114278 |
| 173 | + * ], |
| 174 | + * [ |
| 175 | + * -87.10717890417094, |
| 176 | + * 49.55715210838287 |
| 177 | + * ], |
| 178 | + * [ |
| 179 | + * -86.82247323878836, |
| 180 | + * 57.53161913076085 |
| 181 | + * ], |
| 182 | + * [ |
| 183 | + * -81.00322721012589, |
| 184 | + * 56.68343367062641 |
| 185 | + * ], |
| 186 | + * [ |
| 187 | + * -81.15080039041881, |
| 188 | + * 57.91444311426214 |
| 189 | + * ], |
| 190 | + * [ |
| 191 | + * -76.80207859497996, |
| 192 | + * 55.69469494228919 |
| 193 | + * ] |
| 194 | + * ] |
| 195 | + * ], |
| 196 | + * ] |
| 197 | + * } |
| 198 | + * ], |
| 199 | + * "total": 5, |
| 200 | + * "size": 1, |
| 201 | + * "limit": 1, |
| 202 | + * "skip": 0, |
| 203 | + * "page": 1, |
| 204 | + * "pages": 5, |
| 205 | + * "lastModified": "2018-05-06T18:00:53.283Z" |
| 206 | + * } |
| 207 | + */ |
| 208 | +``` |
0 commit comments