added ignore of baseUrl if not defined or valid
This commit is contained in:
@@ -11,7 +11,8 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
discoveryUrl = ("http://" + discoveryUrl);
|
discoveryUrl = ("http://" + discoveryUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalBasePath = null;
|
var baseDiscoveryUrl = "";
|
||||||
|
var globalBasePath = "";
|
||||||
var formatString = ".{format}";
|
var formatString = ".{format}";
|
||||||
var statusListener = statusCallback;
|
var statusListener = statusCallback;
|
||||||
var apiKey = _apiKey;
|
var apiKey = _apiKey;
|
||||||
@@ -361,7 +362,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
|
|
||||||
fetchEndpoints: function() {
|
fetchEndpoints: function() {
|
||||||
updateStatus("Fetching API List...");
|
updateStatus("Fetching API List...");
|
||||||
var baseDiscoveryUrl = endsWith(discoveryUrl, "/") ? discoveryUrl.substr(0, discoveryUrl.length - 1) : discoveryUrl;
|
baseDiscoveryUrl = endsWith(discoveryUrl, "/") ? discoveryUrl.substr(0, discoveryUrl.length - 1) : discoveryUrl;
|
||||||
if(endsWith(baseDiscoveryUrl, "/resources.json"))
|
if(endsWith(baseDiscoveryUrl, "/resources.json"))
|
||||||
baseDiscoveryUrl = baseDiscoveryUrl.substr(0, baseDiscoveryUrl.length - "/resources.json".length);
|
baseDiscoveryUrl = baseDiscoveryUrl.substr(0, baseDiscoveryUrl.length - "/resources.json".length);
|
||||||
else if(endsWith(baseDiscoveryUrl, "/resources"))
|
else if(endsWith(baseDiscoveryUrl, "/resources"))
|
||||||
@@ -389,8 +390,14 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
$.getJSON(url + apiKeySuffix, function(response) {
|
$.getJSON(url + apiKeySuffix, function(response) {
|
||||||
})
|
})
|
||||||
.success(function(response) {
|
.success(function(response) {
|
||||||
log("Setting globalBasePath to " + response.basePath);
|
if(response.basePath && response.basePath.slice(0,4) == "http") {
|
||||||
globalBasePath = response.basePath;
|
log("Setting globalBasePath to " + response.basePath);
|
||||||
|
globalBasePath = response.basePath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
globalBasePath = baseDiscoveryUrl;
|
||||||
|
}
|
||||||
|
|
||||||
ApiResource.createAll(response.apis);
|
ApiResource.createAll(response.apis);
|
||||||
controller.fetchResources(response.basePath);
|
controller.fetchResources(response.basePath);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
discoveryUrl = ("http://" + discoveryUrl);
|
discoveryUrl = ("http://" + discoveryUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalBasePath = null;
|
var baseDiscoveryUrl = "";
|
||||||
|
var globalBasePath = "";
|
||||||
var formatString = ".{format}";
|
var formatString = ".{format}";
|
||||||
var statusListener = statusCallback;
|
var statusListener = statusCallback;
|
||||||
var apiKey = _apiKey;
|
var apiKey = _apiKey;
|
||||||
@@ -175,7 +176,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
return "{" + this.path_json + "| " + this.nickname + paramsString + ": " + this.summary + "}";
|
return "{" + this.path_json + "| " + this.nickname + paramsString + ": " + this.summary + "}";
|
||||||
},
|
},
|
||||||
|
|
||||||
invocationData: function(formValues) {
|
invocationUrl: function(formValues) {
|
||||||
var formValuesMap = new Object();
|
var formValuesMap = new Object();
|
||||||
for (var i = 0; i < formValues.length; i++) {
|
for (var i = 0; i < formValues.length; i++) {
|
||||||
var formValue = formValues[i];
|
var formValue = formValues[i];
|
||||||
@@ -189,23 +190,21 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
var url = $.tmpl(urlTemplate, formValuesMap)[0].data;
|
var url = $.tmpl(urlTemplate, formValuesMap)[0].data;
|
||||||
// log("url with path params = " + url);
|
// log("url with path params = " + url);
|
||||||
|
|
||||||
var queryParams = {};
|
var queryParams = apiKeySuffix;
|
||||||
if (apiKey) {
|
|
||||||
apiKey = jQuery.trim(apiKey);
|
|
||||||
if (apiKey.length > 0)
|
|
||||||
queryParams['api_key'] = apiKey;
|
|
||||||
}
|
|
||||||
this.parameters.each(function(param) {
|
this.parameters.each(function(param) {
|
||||||
var paramValue = jQuery.trim(formValuesMap[param.name]);
|
var paramValue = jQuery.trim(formValuesMap[param.name]);
|
||||||
if (param.paramType == "query" && paramValue.length > 0) {
|
if (param.paramType == "query" && paramValue.length > 0) {
|
||||||
queryParams[param.name] = formValuesMap[param.name];
|
queryParams += queryParams.length > 0 ? "&": "?";
|
||||||
|
queryParams += param.name;
|
||||||
|
queryParams += "=";
|
||||||
|
queryParams += formValuesMap[param.name];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
url = this.baseUrl + url;
|
url = this.baseUrl + url + queryParams;
|
||||||
// log("final url with query params and base url = " + url);
|
// log("final url with query params and base url = " + url);
|
||||||
|
|
||||||
return {url: url, queryParams: queryParams};
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -363,7 +362,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
|
|
||||||
fetchEndpoints: function() {
|
fetchEndpoints: function() {
|
||||||
updateStatus("Fetching API List...");
|
updateStatus("Fetching API List...");
|
||||||
var baseDiscoveryUrl = endsWith(discoveryUrl, "/") ? discoveryUrl.substr(0, discoveryUrl.length - 1) : discoveryUrl;
|
baseDiscoveryUrl = endsWith(discoveryUrl, "/") ? discoveryUrl.substr(0, discoveryUrl.length - 1) : discoveryUrl;
|
||||||
if(endsWith(baseDiscoveryUrl, "/resources.json"))
|
if(endsWith(baseDiscoveryUrl, "/resources.json"))
|
||||||
baseDiscoveryUrl = baseDiscoveryUrl.substr(0, baseDiscoveryUrl.length - "/resources.json".length);
|
baseDiscoveryUrl = baseDiscoveryUrl.substr(0, baseDiscoveryUrl.length - "/resources.json".length);
|
||||||
else if(endsWith(baseDiscoveryUrl, "/resources"))
|
else if(endsWith(baseDiscoveryUrl, "/resources"))
|
||||||
@@ -391,8 +390,14 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
$.getJSON(url + apiKeySuffix, function(response) {
|
$.getJSON(url + apiKeySuffix, function(response) {
|
||||||
})
|
})
|
||||||
.success(function(response) {
|
.success(function(response) {
|
||||||
log("Setting globalBasePath to " + response.basePath);
|
if(response.basePath && response.basePath.slice(0,4) == "http") {
|
||||||
globalBasePath = response.basePath;
|
log("Setting globalBasePath to " + response.basePath);
|
||||||
|
globalBasePath = response.basePath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
globalBasePath = baseDiscoveryUrl;
|
||||||
|
}
|
||||||
|
|
||||||
ApiResource.createAll(response.apis);
|
ApiResource.createAll(response.apis);
|
||||||
controller.fetchResources(response.basePath);
|
controller.fetchResources(response.basePath);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user