Skip to content

Commit

Permalink
Merge pull request #13 from ayush/master
Browse files Browse the repository at this point in the history
now using basePath returned by the apis
  • Loading branch information
fehguy committed Feb 20, 2012
2 parents 9d12605 + 04dad6d commit eb9e31e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions source/javascripts/swagger-service.js
Expand Up @@ -72,11 +72,14 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
this.modelList = ApiModel.sub();
},

addApis: function(apiObjects) {
addApis: function(apiObjects, basePath) {
// log("apiObjects: %o", apiObjects);
this.apiList.createAll(apiObjects);
this.apiList.each(function(api) {
api.setBaseUrl(basePath);
});
},

addModel: function(modelObject) {
this.modelList.create(modelObject);
},
Expand All @@ -92,8 +95,6 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
init: function(atts) {
if (atts) this.load(atts);

this.baseUrl = globalBasePath;

var secondPathSeperatorIndex = this.path.indexOf("/", 1);
if (secondPathSeperatorIndex > 0) {
var prefix = this.path.substr(0, secondPathSeperatorIndex);
Expand Down Expand Up @@ -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() {
var opsString = "";
for (var i = 0; i < this.operations.all().length; i++) {
Expand All @@ -159,7 +167,6 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
init: function(atts) {
if (atts) this.load(atts);

this.baseUrl = globalBasePath;
this.httpMethodLowercase = this.httpMethod.toLowerCase();

var value = this.parameters;
Expand Down Expand Up @@ -396,8 +403,8 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
$.getJSON(url + apiKeySuffix, function(response) {
})
.success(function(response) {
globalBasePath = url.substr(0, url.lastIndexOf("/"));
log("Setting globalBasePath to " + globalBasePath);
log("Setting globalBasePath to " + response.basePath);
globalBasePath = response.basePath;
ApiResource.createAll(response.apis);
controller.fetchResources(response.basePath);
})
Expand Down Expand Up @@ -429,7 +436,7 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
var controller = this;
updateStatus("Fetching " + apiResource.name + "...");
var resourceUrl = globalBasePath + apiResource.path_json + apiKeySuffix;
// log("resourceUrl: %o", resourceUrl);
log("resourceUrl: %o", resourceUrl);
$.getJSON(resourceUrl,
function(response) {
controller.loadResources(response, apiResource);
Expand All @@ -440,9 +447,9 @@ function SwaggerService(discoveryUrl, _apiKey, statusCallback) {
try {
this.countLoaded++;
// log(response);
// if (response.apis) {
apiResource.addApis(response.apis);
// }
if (response.apis) {
apiResource.addApis(response.apis, response.basePath);
}
// updateStatus("Parsed Apis");
//log(response.models);
if (response.models) {
Expand Down

0 comments on commit eb9e31e

Please sign in to comment.