arrow-docgen
Version:
Arrow API Documentation Generator
53 lines (49 loc) • 1.4 kB
JavaScript
// 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');
if (!endpoint.responses) {
if (endpoint.method === 'POST' && endpoint.generated) {
code.push('`201 Created`: Success, with a `Location` HTTP header with the URL to the newly created resource');
} else if (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;