updated to latest swagger-js

This commit is contained in:
Tony Tam
2013-07-08 18:38:11 -07:00
parent 22e5f5ccc1
commit 8f7e8f9ee0
10 changed files with 159 additions and 129 deletions

View File

@@ -38,6 +38,7 @@
var obj,
_this = this;
this.progress('fetching resource list: ' + this.discoveryUrl);
console.log('getting ' + this.discoveryUrl);
obj = {
url: this.discoveryUrl,
method: "get",
@@ -79,7 +80,8 @@
}
}
};
return new SwaggerHttp().execute(obj);
new SwaggerHttp().execute(obj);
return this;
};
SwaggerApi.prototype.selfReflect = function() {
@@ -519,6 +521,9 @@
this.resource[this.nickname] = function(args, callback, error) {
return _this["do"](args, callback, error);
};
this.resource[this.nickname].help = function() {
return _this.help();
};
}
SwaggerOperation.prototype.isListType = function(dataType) {
@@ -555,18 +560,25 @@
}
};
SwaggerOperation.prototype["do"] = function(args, callback, error) {
var key, param, params, possibleParams, requestContentType, responseContentType, value;
SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
var key, param, params, possibleParams, req, requestContentType, responseContentType, value;
if (args == null) {
args = {};
}
if (opts == null) {
opts = {};
}
requestContentType = null;
responseContentType = null;
if ((typeof args) === "function") {
error = callback;
error = opts;
callback = args;
args = {};
}
if ((typeof opts) === "function") {
error = callback;
callback = opts;
}
if (error == null) {
error = function(xhr, textStatus, error) {
return console.log(xhr, textStatus, error);
@@ -574,16 +586,17 @@
}
if (callback == null) {
callback = function(data) {
return console.log("default callback: " + data);
var content;
content = null;
if (data.content != null) {
content = data.content.data;
} else {
content = "no data";
}
return console.log("default callback: " + content);
};
}
params = {};
if (args.requestContentType) {
requestContentType = args.requestContentType;
}
if (args.responseContentType) {
responseContentType = args.responseContentType;
}
if (args.headers != null) {
params.headers = args.headers;
delete args.headers;
@@ -612,11 +625,12 @@
}
}
}
if (args.mock != null) {
params.mock = args["mock"];
req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
if (opts.mock != null) {
return req;
} else {
return true;
}
params["parent"] = args["parent"];
return new SwaggerRequest(this.method, this.urlify(args), params, requestContentType, responseContentType, callback, error, this);
};
SwaggerOperation.prototype.pathJson = function() {
@@ -716,14 +730,13 @@
SwaggerRequest = (function() {
function SwaggerRequest(type, url, params, requestContentType, responseContentType, successCallback, errorCallback, operation, execution) {
var body, e, fields, headers, key, myHeaders, obj, param, parent, possibleParams, urlEncoded, value, values,
function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
var body, e, fields, headers, key, myHeaders, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
_this = this;
this.type = type;
this.url = url;
this.params = params;
this.requestContentType = requestContentType;
this.responseContentType = responseContentType;
this.opts = opts;
this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.operation = operation;
@@ -750,8 +763,8 @@
parent = params["parent"];
requestContentType = "application/json";
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
if (this.requestContentType) {
requestContentType = this.requestContentType;
if (this.opts.requestContentType) {
requestContentType = this.opts.requestContentType;
}
} else {
if (((function() {
@@ -777,14 +790,12 @@
if (this.requestContentType === null) {
requestContentType = this.operation.consumes[0];
}
} else {
console.log("it's ok to send " + requestContentType);
}
}
responseContentType = null;
if (this.type === "POST" || this.type === "GET") {
if (this.responseContentType) {
responseContentType = this.responseContentType;
if (this.opts.responseContentType) {
responseContentType = this.opts.responseContentType;
} else {
responseContentType = "application/json";
}
@@ -794,12 +805,9 @@
if (responseContentType && this.operation.produces) {
if (this.operation.produces.indexOf(responseContentType) === -1) {
console.log("server can't produce " + responseContentType);
} else {
console.log("get ready for " + responseContentType);
}
}
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
console.log("pulling fields");
fields = {};
possibleParams = (function() {
var _i, _len, _ref, _results;
@@ -813,7 +821,6 @@
}
return _results;
}).call(this);
console.log(possibleParams);
values = {};
for (key in possibleParams) {
value = possibleParams[key];
@@ -845,16 +852,16 @@
body: body,
on: {
error: function(response) {
return _this.errorCallback(response, _this.params["parent"]);
return _this.errorCallback(response, _this.opts.parent);
},
redirect: function(response) {
return _this.successCallback(response, _this.params["parent"]);
return _this.successCallback(response, _this.opts.parent);
},
307: function(response) {
return _this.successCallback(response, _this.params["parent"]);
return _this.successCallback(response, _this.opts.parent);
},
response: function(response) {
return _this.successCallback(response, _this.params["parent"]);
return _this.successCallback(response, _this.opts.parent);
}
}
};
@@ -865,9 +872,10 @@
e = exports;
}
e.authorizations.apply(obj);
if (params.mock == null) {
if (opts.mock == null) {
new SwaggerHttp().execute(obj);
} else {
console.log(obj);
return obj;
}
}
@@ -894,33 +902,42 @@
SwaggerHttp = (function() {
SwaggerHttp.prototype.Shred = null;
SwaggerHttp.prototype.shred = null;
function SwaggerHttp() {
var Shred;
Shred = null;
if (typeof window !== 'undefined') {
Shred = require("./shred");
} else {
Shred = require("shred");
}
this.shred = new Shred();
}
SwaggerHttp.prototype.content = null;
SwaggerHttp.prototype.execute = function(obj) {
var Content, identity, toString,
function SwaggerHttp() {
var identity, toString,
_this = this;
Content = require("./shred/content");
if (typeof window !== 'undefined') {
this.Shred = require("./shred");
} else {
this.Shred = require("shred");
}
this.shred = new this.Shred();
identity = function(x) {
return x;
};
toString = function(x) {
return x.toString;
};
Content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
if (typeof window !== 'undefined') {
this.content = require("./shred/content");
this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
} else {
this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
}
}
SwaggerHttp.prototype.execute = function(obj) {
return this.shred.request(obj);
};
@@ -997,8 +1014,6 @@
this.SwaggerModelProperty = SwaggerModelProperty;
this.SwaggerAuthorizations = new SwaggerAuthorizations();
this.ApiKeyAuthorization = ApiKeyAuthorization;
this.authorizations = new SwaggerAuthorizations();