updated swagger-js

This commit is contained in:
Tony Tam
2014-09-14 14:06:31 -07:00
parent 66718f23dd
commit 0395bf3eb3
2 changed files with 32 additions and 15 deletions

View File

@@ -186,7 +186,6 @@ var SwaggerClient = function(url, options) {
this.authorizationScheme = null; this.authorizationScheme = null;
this.info = null; this.info = null;
this.useJQuery = false; this.useJQuery = false;
this.blocked = false;
options = (options||{}); options = (options||{});
if (url) if (url)
@@ -211,14 +210,13 @@ var SwaggerClient = function(url, options) {
SwaggerClient.prototype.build = function() { SwaggerClient.prototype.build = function() {
var self = this; var self = this;
this.blocked = false;
this.progress('fetching resource list: ' + this.url); this.progress('fetching resource list: ' + this.url);
var obj = { var obj = {
useJQuery: this.useJQuery, useJQuery: this.useJQuery,
url: this.url, url: this.url,
method: "get", method: "get",
headers: { headers: {
accept: "application/json" accept: "application/json, */*"
}, },
on: { on: {
error: function(response) { error: function(response) {
@@ -233,7 +231,6 @@ SwaggerClient.prototype.build = function() {
}, },
response: function(resp) { response: function(resp) {
var responseObj = resp.obj || JSON.parse(resp.data); var responseObj = resp.obj || JSON.parse(resp.data);
self.blocked = false;
self.swaggerVersion = responseObj.swaggerVersion; self.swaggerVersion = responseObj.swaggerVersion;
if(responseObj.swagger && responseObj.swagger === 2.0) { if(responseObj.swagger && responseObj.swagger === 2.0) {
@@ -245,20 +242,10 @@ SwaggerClient.prototype.build = function() {
}; };
var e = (typeof window !== 'undefined' ? window : exports); var e = (typeof window !== 'undefined' ? window : exports);
e.authorizations.apply(obj); e.authorizations.apply(obj);
blocked = true;
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj);
function waitABit(obj) {
if(obj.blocked)
setTimeout(waitABit(obj), 5);
};
setTimeout(waitABit(this), 5);
return this; return this;
}; };
function blocking(obj) {
}
SwaggerClient.prototype.buildFromSpec = function(response) { SwaggerClient.prototype.buildFromSpec = function(response) {
if(this.isBuilt) if(this.isBuilt)
return this; return this;
@@ -273,6 +260,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this.produces = response.produces; this.produces = response.produces;
this.authSchemes = response.authorizations; this.authSchemes = response.authorizations;
if(typeof this.host === 'undefined' || this.host === '') {
var location = this.parseUri(this.url);
this.host = location.host;
}
this.definitions = response.definitions; this.definitions = response.definitions;
var key; var key;
for(key in this.definitions) { for(key in this.definitions) {
@@ -343,6 +335,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
return this; return this;
} }
SwaggerClient.prototype.parseUri = function(uri) {
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var parts = urlParseRE.exec(uri);
return {
scheme: parts[4].replace(':',''),
host: parts[11],
path: parts[15]
};
}
SwaggerClient.prototype.help = function() { SwaggerClient.prototype.help = function() {
var i; var i;
log('operations for the "' + this.label + '" tag'); log('operations for the "' + this.label + '" tag');

View File

@@ -216,7 +216,7 @@ SwaggerClient.prototype.build = function() {
url: this.url, url: this.url,
method: "get", method: "get",
headers: { headers: {
accept: "application/json" accept: "application/json, */*"
}, },
on: { on: {
error: function(response) { error: function(response) {
@@ -260,6 +260,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this.produces = response.produces; this.produces = response.produces;
this.authSchemes = response.authorizations; this.authSchemes = response.authorizations;
if(typeof this.host === 'undefined' || this.host === '') {
var location = this.parseUri(this.url);
this.host = location.host;
}
this.definitions = response.definitions; this.definitions = response.definitions;
var key; var key;
for(key in this.definitions) { for(key in this.definitions) {
@@ -330,6 +335,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
return this; return this;
} }
SwaggerClient.prototype.parseUri = function(uri) {
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var parts = urlParseRE.exec(uri);
return {
scheme: parts[4].replace(':',''),
host: parts[11],
path: parts[15]
};
}
SwaggerClient.prototype.help = function() { SwaggerClient.prototype.help = function() {
var i; var i;
log('operations for the "' + this.label + '" tag'); log('operations for the "' + this.label + '" tag');