diff --git a/lib/codegen.js b/lib/codegen.js index 1226f870..52614a1b 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -54,6 +54,14 @@ var getPathToMethodName = function(opts, m, path){ return m.toLowerCase() + result[0].toUpperCase() + result.substring(1); }; +var produceHeaderKeyValue = function (name, values) { + var header = []; + header.value = []; + header.name = name; + header.value.push(values.map(function (value) { return '\'' + value + '\''; }).join(', ')); + return header; +}; + var getViewForSwagger2 = function(opts, type){ var swagger = opts.swagger; var authorizedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'COPY', 'HEAD', 'OPTIONS', 'LINK', 'UNLIK', 'PURGE', 'LOCK', 'UNLOCK', 'PROPFIND']; @@ -96,19 +104,13 @@ var getViewForSwagger2 = function(opts, type){ headers: [] }; - if(op.produces) { - var headers = []; - headers.value = []; - - headers.name = 'Accept'; - headers.value.push(op.produces.map(function(value) { return '\'' + value + '\''; }).join(', ')); - - method.headers.push(headers); + if (op.produces) { + method.headers.push(produceHeaderKeyValue('Accept', op.produces)); } var consumes = op.consumes || swagger.consumes; - if(consumes) { - method.headers.push({name: 'Content-Type', value: '\'' + consumes + '\'' }); + if (consumes) { + method.headers.push(produceHeaderKeyValue('Content-Type', consumes)); } var params = [];