Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -277,31 +277,30 @@ 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') {
throw new Error(error.reason + ' in ' + error.evidence + ' (' + error.code + ')');
}
});
}

if (opts.beautify === undefined || opts.beautify === true) {
return beautify(source, { indent_size: 4, max_preserve_newlines: 2 });
} else {
Expand Down