diff --git a/lib/codegen.js b/lib/codegen.js index 54dbe7ef..4715f910 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -65,15 +65,15 @@ var getViewForSwagger2 = function(opts, type){ } var secureTypes = []; if(swagger.securityDefinitions !== undefined || op.security !== undefined) { - var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){ - return Object.keys(security); + var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){ + return Object.keys(security); }); - if(swagger.securityDefinitions) { - for(var sk in swagger.securityDefinitions) { + if(swagger.securityDefinitions) { + for(var sk in swagger.securityDefinitions) { if(mergedSecurity.join(',').indexOf(sk) !== -1){ - secureTypes.push(swagger.securityDefinitions[sk].type); + secureTypes.push(swagger.securityDefinitions[sk].type); } - } + } } } var methodName = (op.operationId ? normalizeName(op.operationId) : getPathToMethodName(opts, m, path)); @@ -101,22 +101,22 @@ var getViewForSwagger2 = function(opts, type){ summary: op.description || op.summary, externalDocs: op.externalDocs, isSecure: swagger.security !== undefined || op.security !== undefined, - isSecureToken: secureTypes.indexOf('oauth2') !== -1, - isSecureApiKey: secureTypes.indexOf('apiKey') !== -1, - isSecureBasic: secureTypes.indexOf('basic') !== -1, + isSecureToken: secureTypes.indexOf('oauth2') !== -1, + isSecureApiKey: secureTypes.indexOf('apiKey') !== -1, + isSecureBasic: secureTypes.indexOf('basic') !== -1, parameters: [], headers: [] }; - if(method.isSecure && method.isSecureToken) { - data.isSecureToken = method.isSecureToken; - } - if(method.isSecure && method.isSecureApiKey) { - data.isSecureApiKey = method.isSecureApiKey; - } - if(method.isSecure && method.isSecureBasic) { - data.isSecureBasic = method.isSecureBasic; - } - var produces = op.produces || swagger.produces; + if(method.isSecure && method.isSecureToken) { + data.isSecureToken = method.isSecureToken; + } + if(method.isSecure && method.isSecureApiKey) { + data.isSecureApiKey = method.isSecureApiKey; + } + if(method.isSecure && method.isSecureBasic) { + data.isSecureBasic = method.isSecureBasic; + } + var produces = op.produces || swagger.produces; if(produces) { method.headers.push({ name: 'Accept', @@ -277,24 +277,22 @@ var getCode = function(opts, type) { } var source = Mustache.render(opts.template.class, data, opts.template); - var lintOptions = { - node: type === 'node' || type === 'custom', - browser: type === 'angular' || type === 'custom' || type === 'react', - undef: true, - strict: true, - trailing: true, - smarttabs: true, - maxerr: 999 - }; - if (opts.esnext) { - lintOptions.esnext = true; - } - if(type === 'typescript') { + if (type === 'typescript') { opts.lint = false; } - if (opts.lint === undefined || opts.lint === true) { + if (opts.lint || opts.lint === undefined) { + var lintOptions = _.merge({ + node: type === 'node' || type === 'custom', + browser: type === 'angular' || type === 'custom' || type === 'react', + undef: true, + strict: true, + trailing: true, + smarttabs: true, + esnext = Boolean(opts.next), + maxerr: 999 + }, _.isObject(opts.lint) ? opts.lint : {}); lint(source, lintOptions); lint.errors.forEach(function(error) { if (error.code[0] === 'E') { @@ -302,6 +300,7 @@ var getCode = function(opts, type) { } }); } + if (opts.beautify === undefined || opts.beautify === true) { return beautify(source, { indent_size: 4, max_preserve_newlines: 2 }); } else {