Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-type header works like the accept header, with support for arrays of values #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/codegen.js
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 = [];
Expand Down