Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 1161x 16x 16x 1x | 'use strict'; var express = require('express'); var apirouter = express.Router(); var debug = require('debug')('sws:testapp'); /** * @swagger * parameters: * reusableparam: * name: reusableparam * in: query * description: test reusable parameter * required: true * type: integer * format: int64 * definitions: * pet: * type: object * required: * - id * - name * properties: * id: * type: integer * format: int64 * name: * type: string * tag: * type: string * newPet: * type: object * required: * - name * properties: * id: * type: integer * format: int64 * name: * type: string * tag: * type: string * errorModel: * type: object * required: * - code * - message * properties: * code: * type: integer * format: int32 * message: * type: string */ /** * @swagger * /pets: * get: * description: Returns all pets from the system that the user has access to * operationId: findPets * produces: * - application/json * - application/xml * - text/xml * - text/html * parameters: * - name: tags * in: query * description: tags to filter by * required: false * type: array * items: * type: string * collectionFormat: csv * - name: limit * in: query * description: maximum number of results to return * required: false * type: integer * format: int32 * responses: * '200': * description: pet response * schema: * type: array * items: * $ref: '#/definitions/pet' * default: * description: unexpected error * schema: * $ref: '#/definitions/errorModel' */ // NOT IMPLEMENTED // API for tests ///////////////////////////////////////// // /** * @swagger * /success: * get: * description: Test success response * produces: * - text/html; charset=utf-8 * responses: * 200: * description: Success Response */ apirouter.get('/success', function (req, res) { res.status(200).send('OK'); }); /** * @swagger * /redirect: * get: * description: Test redirect response * responses: * 302: * description: Redirect Response */ apirouter.get('/redirect', function (req, res) { res.redirect('/v2/success'); }); /** * @swagger * /client_error: * get: * description: Test Client Error Response * produces: * - text/html; charset=utf-8 * responses: * 404: * description: Not Found Response */ apirouter.get('/client_error', function (req, res) { res.status(404).send('Not found'); }); /** * @swagger * /server_error: * get: * description: Test Server Error Response * produces: * - text/html; charset=utf-8 * responses: * 500: * description: Server Error Response */ apirouter.get('/server_error', function (req, res) { res.status(500).send('Server Error'); }); /** * @swagger * /tester/{code}: * get: * operationId: getTesterApi * summary: Test API Get opeation * description: Test Swagger API path with GET operation, producing response supplied in request parameter * tags: * - tester * - GET * produces: * - application/json * responses: * default: * description: Response Message * schema: * $ref: '#/definitions/errorModel' * post: * operationId: postTesterApi * summary: Test API POST operation * description: Test Swagger API path with POST operation, producing response supplied in request parameter * tags: * - tester * - POST * produces: * - application/json * responses: * default: * description: Response Message * schema: * $ref: '#/definitions/errorModel' * put: * description: Test PUT method and various responses * produces: * - application/json * responses: * default: * description: Response Message * schema: * $ref: '#/definitions/errorModel' * delete: * description: Test DELETE method and various responses * deprecated: true * produces: * - application/json * responses: * default: * description: Response Message * schema: * $ref: '#/definitions/errorModel' * parameters: * - $ref: '#/parameters/reusableparam' * parameters: * - name: code * in: path * description: response code to return * required: true * type: integer * format: int64 * - name: delay * in: query * description: delay to wait before responding * required: false * type: integer * format: int64 * - name: message * in: query * description: message to return * required: true * type: string */ apirouter.get('/tester/:code', testerImpl ); apirouter.post('/tester/:code', testerImpl ); apirouter.put('/tester/:code', testerImpl ); apirouter.delete('/tester/:code', testerImpl ); // Test API that is not defined in swagger spec apirouter.get('/noswagger/:code', testerImpl ); apirouter.post('/noswagger/:code', testerImpl ); apirouter.put('/noswagger/:code', testerImpl ); apirouter.delete('/noswagger/:code', testerImpl ); // Mock API request // TODO Define in swagger spec // TODO Describe parameter in header apirouter.get('/mockapi', mockApiImpl ); apirouter.post('/mockapi', mockApiImpl ); apirouter.put('/mockapi', mockApiImpl); apirouter.delete('/mockapi', mockApiImpl); apirouter.head('/mockapi', mockApiImpl); apirouter.options('/mockapi', mockApiImpl); apirouter.connect('/mockapi', mockApiImpl); /** * @swagger * /paramstest/{code}/and/{value}: * get: * operationId: getTestWithPathParams * summary: Test API with path parameters * produces: * - application/json * responses: * default: * description: Response Message * schema: * $ref: '#/definitions/errorModel' * parameters: * - name: code * in: path * description: first parameter * required: true * type: integer * format: int64 * - name: value * in: path * description: second parameter * required: true * type: string * - name: delay * in: query * description: second parameter * required: false * type: string */ apirouter.get('/paramstest/:code/and/:value', testerImpl ); function testerImpl(req, res) { var code = 500; var message = "ERROR: Wrong parameters"; if(('params' in req) && 'code' in req.params ){ code = parseInt(req.params.code); message = "Request Method:" + req.method +', params.code: ' + req.params.code; } if(('query' in req) && ('delay' in req.query)){ var delay = parseInt(req.query.delay); setTimeout(function(){ res.status(code).json({code: code, message: message}); },delay); }else { res.status(code).json({code: code, message: message}); } } function mockApiImpl(req,res){ var code = 500; var message = "MOCK API RESPONSE"; var delay = 0; var payloadsize = 0; // get header var hdrSwsRes = req.header('x-sws-res'); Eif(typeof hdrSwsRes !== 'undefined'){ var swsRes = JSON.parse(hdrSwsRes); Eif( 'code' in swsRes ) code = swsRes.code; Eif( 'message' in swsRes ) message = swsRes.message; Eif( 'delay' in swsRes ) delay = swsRes.delay; Eif( 'payloadsize' in swsRes ) payloadsize = swsRes.payloadsize; } Eif( delay > 0 ){ setTimeout(function(){ mockApiSendResponse(res,code,message,payloadsize); },delay); }else{ mockApiSendResponse(res,code,message,payloadsize); } } function mockApiSendResponse(res,code,message,payloadsize){ Iif(payloadsize<=0){ res.status(code).send(message); }else{ // generate dummy payload of approximate size var dummyPayload = []; var adjSize = payloadsize-4; Iif(adjSize<=0) adjSize = 1; var str = ''; for(var i=0;i<adjSize;i++) str += 'a'; dummyPayload.push(str); res.status(code).json(dummyPayload); } } module.exports = apirouter; |