all files / arrow-docgen/lib/ response.js

58.82% Statements 10/17
53.33% Branches 8/15
100% Functions 1/1
58.82% Lines 10/17
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                                                                                     
// jscs:disable jsDoc
 
var codesToDisplay = {
	200: 'OK',
	201: 'Created',
	202: 'Accepted',
	204: 'No Content',
	205: 'Reset Content',
	301: 'Moved Permanently',
	302: 'Found',
	304: 'Not Modified',
	400: 'Bad Request',
	401: 'Unauthorized',
	402: 'Payment Required',
	403: 'Forbidden',
	404: 'Not Found',
	405: 'Method Not Allowed',
	406: 'Not Acceptable',
	408: 'Request Timeout',
	500: 'Internal Server Error',
	501: 'Not Implemented',
	502: 'Bad Gateway',
	503: 'Service Unavailable',
	504: 'Gateway Timeout'
};
 
function generate(object, api, endpoint, opts) {
	var code = [];
	code.push('### HTTP Response\n');
	Eif (!endpoint.responses) {
		Iif (endpoint.method === 'POST' && endpoint.generated) {
			code.push('`201 Created`: Success, with a `Location` HTTP header with the URL to the newly created resource');
		} else Iif (endpoint.generated && (endpoint.method === 'DELETE' || endpoint.method === 'PUT')) {
			code.push('`204 No Content`: Success');
		} else {
			code.push('`200 OK`: Success');
		}
	} else {
		for (var statusCode in endpoint.responses) {
			if (endpoint.responses.hasOwnProperty(statusCode)) {
				var statusText = codesToDisplay[+statusCode],
					response = endpoint.responses[statusCode];
				if (statusText) {
					code.push('`' + statusCode + ' ' + statusText + '`: ' + response.description);
				}
			}
		}
	}
	return code.join('\n');
}
 
exports.generate = generate;