Merge pull request #13 from ayush/master
now using basePath returned by the apis
This commit is contained in:
@@ -72,9 +72,12 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
this.modelList = ApiModel.sub();
|
this.modelList = ApiModel.sub();
|
||||||
},
|
},
|
||||||
|
|
||||||
addApis: function(apiObjects) {
|
addApis: function(apiObjects, basePath) {
|
||||||
// log("apiObjects: %o", apiObjects);
|
// log("apiObjects: %o", apiObjects);
|
||||||
this.apiList.createAll(apiObjects);
|
this.apiList.createAll(apiObjects);
|
||||||
|
this.apiList.each(function(api) {
|
||||||
|
api.setBaseUrl(basePath);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
addModel: function(modelObject) {
|
addModel: function(modelObject) {
|
||||||
@@ -92,8 +95,6 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
init: function(atts) {
|
init: function(atts) {
|
||||||
if (atts) this.load(atts);
|
if (atts) this.load(atts);
|
||||||
|
|
||||||
this.baseUrl = globalBasePath;
|
|
||||||
|
|
||||||
var secondPathSeperatorIndex = this.path.indexOf("/", 1);
|
var secondPathSeperatorIndex = this.path.indexOf("/", 1);
|
||||||
if (secondPathSeperatorIndex > 0) {
|
if (secondPathSeperatorIndex > 0) {
|
||||||
var prefix = this.path.substr(0, secondPathSeperatorIndex);
|
var prefix = this.path.substr(0, secondPathSeperatorIndex);
|
||||||
@@ -138,6 +139,13 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setBaseUrl: function(u) {
|
||||||
|
this.baseUrl = u;
|
||||||
|
this.operations.each(function(o) {
|
||||||
|
o.baseUrl = u;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
var opsString = "";
|
var opsString = "";
|
||||||
for (var i = 0; i < this.operations.all().length; i++) {
|
for (var i = 0; i < this.operations.all().length; i++) {
|
||||||
@@ -159,7 +167,6 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
init: function(atts) {
|
init: function(atts) {
|
||||||
if (atts) this.load(atts);
|
if (atts) this.load(atts);
|
||||||
|
|
||||||
this.baseUrl = globalBasePath;
|
|
||||||
this.httpMethodLowercase = this.httpMethod.toLowerCase();
|
this.httpMethodLowercase = this.httpMethod.toLowerCase();
|
||||||
|
|
||||||
var value = this.parameters;
|
var value = this.parameters;
|
||||||
@@ -396,8 +403,8 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
$.getJSON(url + apiKeySuffix, function(response) {
|
$.getJSON(url + apiKeySuffix, function(response) {
|
||||||
})
|
})
|
||||||
.success(function(response) {
|
.success(function(response) {
|
||||||
globalBasePath = url.substr(0, url.lastIndexOf("/"));
|
log("Setting globalBasePath to " + response.basePath);
|
||||||
log("Setting globalBasePath to " + globalBasePath);
|
globalBasePath = response.basePath;
|
||||||
ApiResource.createAll(response.apis);
|
ApiResource.createAll(response.apis);
|
||||||
controller.fetchResources(response.basePath);
|
controller.fetchResources(response.basePath);
|
||||||
})
|
})
|
||||||
@@ -429,7 +436,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
var controller = this;
|
var controller = this;
|
||||||
updateStatus("Fetching " + apiResource.name + "...");
|
updateStatus("Fetching " + apiResource.name + "...");
|
||||||
var resourceUrl = globalBasePath + apiResource.path_json + apiKeySuffix;
|
var resourceUrl = globalBasePath + apiResource.path_json + apiKeySuffix;
|
||||||
// log("resourceUrl: %o", resourceUrl);
|
log("resourceUrl: %o", resourceUrl);
|
||||||
$.getJSON(resourceUrl,
|
$.getJSON(resourceUrl,
|
||||||
function(response) {
|
function(response) {
|
||||||
controller.loadResources(response, apiResource);
|
controller.loadResources(response, apiResource);
|
||||||
@@ -440,9 +447,9 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
|
|||||||
try {
|
try {
|
||||||
this.countLoaded++;
|
this.countLoaded++;
|
||||||
// log(response);
|
// log(response);
|
||||||
// if (response.apis) {
|
if (response.apis) {
|
||||||
apiResource.addApis(response.apis);
|
apiResource.addApis(response.apis, response.basePath);
|
||||||
// }
|
}
|
||||||
// updateStatus("Parsed Apis");
|
// updateStatus("Parsed Apis");
|
||||||
//log(response.models);
|
//log(response.models);
|
||||||
if (response.models) {
|
if (response.models) {
|
||||||
|
|||||||
Reference in New Issue
Block a user