diff --git a/lib/nodegen.js b/lib/nodegen.js index 971db1a..32137dc 100644 --- a/lib/nodegen.js +++ b/lib/nodegen.js @@ -186,20 +186,25 @@ function function2node(data, options) { function swagger2node(data, options) { // Modify swagger data var swagger = JSON.parse(JSON.stringify(data.src), function (key, value) { - if (key === 'consumes') { // 1. Filter type for 'Content-Type' in request header - return undefined; - } else if (key === 'produces') { // 2. Filter type for 'Accept' in request header + if (key === 'consumes' || key === 'produces') { // Filter type of 'Content-Type' and 'Accept' in request header if (value.indexOf('application/json') >= 0) { return ['application/json']; - } - if (value.indexOf('application/xml') >= 0) { + } else if (value.indexOf('application/xml') >= 0) { return ['application/xml']; + } else if (value.indexOf('text/csv') >= 0) { + return ['text/csv']; + } else if (value.indexOf('text/plain') >= 0) { + return ['text/plain']; + } else if (value.indexOf('multipart/form-data') >= 0) { + return ['multipart/form-data']; + } else if (value.indexOf('application/octet-stream') >= 0) { + return ['application/octet-stream']; } else { - return [value[0]]; + return undefined; } - } else if (key === 'default') { // 3. Handle swagger-js-codegen bug + } else if (key === 'default') { // Handle swagger-js-codegen bug return undefined; - } else if (key === 'operationId') { // 4. Sanitize 'operationId' (remove special chars) + } else if (key === 'operationId') { // Sanitize 'operationId' (remove special chars) return value.replace(/(?!\w|\s)./g, ''); } else { return value;