updated client to enable auth #588

This commit is contained in:
Tony Tam
2014-09-20 21:21:04 -07:00
parent fedb12960b
commit 0cabc3017b
2 changed files with 20 additions and 52 deletions

View File

@@ -237,12 +237,10 @@ SwaggerClient.prototype.build = function() {
if(responseObj.swagger && responseObj.swagger === 2.0) { if(responseObj.swagger && responseObj.swagger === 2.0) {
self.swaggerVersion = responseObj.swagger; self.swaggerVersion = responseObj.swagger;
self.buildFromSpec(responseObj); self.buildFromSpec(responseObj);
self.isValid = true; this.isValid = true;
}
else {
self.isValid = false;
self.failure()
} }
else
this.isValid = false;
} }
} }
}; };
@@ -288,7 +286,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(httpMethod in response.paths[path]) { for(httpMethod in response.paths[path]) {
var operation = response.paths[path][httpMethod]; var operation = response.paths[path][httpMethod];
var tags = operation.tags; var tags = operation.tags;
if(typeof tags === undefined) if(typeof tags === 'undefined')
tags = []; tags = [];
var operationId = this.idFromOp(path, httpMethod, operation); var operationId = this.idFromOp(path, httpMethod, operation);
var operation = new Operation ( var operation = new Operation (
@@ -404,8 +402,7 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
this.summary = args.summary || ''; this.summary = args.summary || '';
this.responses = (args.responses||{}); this.responses = (args.responses||{});
this.type = null; this.type = null;
this.security = args.security;
// this.authorizations = authorizations;
var i; var i;
for(i = 0; i < this.parameters.length; i++) { for(i = 0; i < this.parameters.length; i++) {
@@ -436,8 +433,6 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
this.type = response.schema.type; this.type = response.schema.type;
} }
} }
// else
// this.responseClassSignature = '';
if (errors.length > 0) if (errors.length > 0)
this.resource.api.fail(errors); this.resource.api.fail(errors);
@@ -472,9 +467,8 @@ Operation.prototype.getType = function (param) {
str = 'string'; str = 'string';
else if(type === 'array') { else if(type === 'array') {
isArray = true; isArray = true;
if(param.items) { if(param.items)
str = this.getType(param.items); str = this.getType(param.items);
}
} }
if(param['$ref']) if(param['$ref'])
str = param['$ref']; str = param['$ref'];
@@ -485,7 +479,7 @@ Operation.prototype.getType = function (param) {
if(ref) { if(ref) {
ref = simpleRef(ref); ref = simpleRef(ref);
if(isArray) if(isArray)
return [ref]; return [ ref ];
else else
return ref; return ref;
} }
@@ -493,7 +487,7 @@ Operation.prototype.getType = function (param) {
return this.getType(schema); return this.getType(schema);
} }
if(isArray) if(isArray)
return [str]; return [ str ];
else else
return str; return str;
} }
@@ -510,16 +504,6 @@ Operation.prototype.resolveModel = function (schema, definitions) {
return new ArrayModel(schema); return new ArrayModel(schema);
else else
return null; return null;
// return new PrimitiveModel(schema);
// else
// var ref = schema.items['$ref'];
// if(ref.indexOf('#/definitions/') === 0)
// ref = ref.substring('#/definitions/'.length);
// return new Model('name', models[ref]);
// }
// else
// return new Model('name', schema);
} }
Operation.prototype.help = function() { Operation.prototype.help = function() {
@@ -538,7 +522,6 @@ Operation.prototype.getSignature = function(type, models) {
type = type[0]; type = type[0];
} }
// listType = this.isListType(type);
if(type === 'string') if(type === 'string')
isPrimitive = true isPrimitive = true
else else
@@ -664,7 +647,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
var obj = { var obj = {
url: url, url: url,
method: this.method, method: args.method,
useJQuery: this.useJQuery, useJQuery: this.useJQuery,
headers: headers, headers: headers,
on: { on: {
@@ -676,6 +659,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
} }
} }
}; };
var status = e.authorizations.apply(obj, this.operation.security);
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj);
} }

View File

@@ -237,12 +237,10 @@ SwaggerClient.prototype.build = function() {
if(responseObj.swagger && responseObj.swagger === 2.0) { if(responseObj.swagger && responseObj.swagger === 2.0) {
self.swaggerVersion = responseObj.swagger; self.swaggerVersion = responseObj.swagger;
self.buildFromSpec(responseObj); self.buildFromSpec(responseObj);
self.isValid = true; this.isValid = true;
}
else {
self.isValid = false;
self.failure()
} }
else
this.isValid = false;
} }
} }
}; };
@@ -288,7 +286,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(httpMethod in response.paths[path]) { for(httpMethod in response.paths[path]) {
var operation = response.paths[path][httpMethod]; var operation = response.paths[path][httpMethod];
var tags = operation.tags; var tags = operation.tags;
if(typeof tags === undefined) if(typeof tags === 'undefined')
tags = []; tags = [];
var operationId = this.idFromOp(path, httpMethod, operation); var operationId = this.idFromOp(path, httpMethod, operation);
var operation = new Operation ( var operation = new Operation (
@@ -404,8 +402,7 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
this.summary = args.summary || ''; this.summary = args.summary || '';
this.responses = (args.responses||{}); this.responses = (args.responses||{});
this.type = null; this.type = null;
this.security = args.security;
// this.authorizations = authorizations;
var i; var i;
for(i = 0; i < this.parameters.length; i++) { for(i = 0; i < this.parameters.length; i++) {
@@ -436,8 +433,6 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
this.type = response.schema.type; this.type = response.schema.type;
} }
} }
// else
// this.responseClassSignature = '';
if (errors.length > 0) if (errors.length > 0)
this.resource.api.fail(errors); this.resource.api.fail(errors);
@@ -472,9 +467,8 @@ Operation.prototype.getType = function (param) {
str = 'string'; str = 'string';
else if(type === 'array') { else if(type === 'array') {
isArray = true; isArray = true;
if(param.items) { if(param.items)
str = this.getType(param.items); str = this.getType(param.items);
}
} }
if(param['$ref']) if(param['$ref'])
str = param['$ref']; str = param['$ref'];
@@ -485,7 +479,7 @@ Operation.prototype.getType = function (param) {
if(ref) { if(ref) {
ref = simpleRef(ref); ref = simpleRef(ref);
if(isArray) if(isArray)
return [ref]; return [ ref ];
else else
return ref; return ref;
} }
@@ -493,7 +487,7 @@ Operation.prototype.getType = function (param) {
return this.getType(schema); return this.getType(schema);
} }
if(isArray) if(isArray)
return [str]; return [ str ];
else else
return str; return str;
} }
@@ -510,16 +504,6 @@ Operation.prototype.resolveModel = function (schema, definitions) {
return new ArrayModel(schema); return new ArrayModel(schema);
else else
return null; return null;
// return new PrimitiveModel(schema);
// else
// var ref = schema.items['$ref'];
// if(ref.indexOf('#/definitions/') === 0)
// ref = ref.substring('#/definitions/'.length);
// return new Model('name', models[ref]);
// }
// else
// return new Model('name', schema);
} }
Operation.prototype.help = function() { Operation.prototype.help = function() {
@@ -538,7 +522,6 @@ Operation.prototype.getSignature = function(type, models) {
type = type[0]; type = type[0];
} }
// listType = this.isListType(type);
if(type === 'string') if(type === 'string')
isPrimitive = true isPrimitive = true
else else
@@ -664,7 +647,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
var obj = { var obj = {
url: url, url: url,
method: this.method, method: args.method,
useJQuery: this.useJQuery, useJQuery: this.useJQuery,
headers: headers, headers: headers,
on: { on: {
@@ -676,6 +659,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
} }
} }
}; };
var status = e.authorizations.apply(obj, this.operation.security);
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj);
} }