Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #13 from ayush/master

now using basePath returned by the apis
  • Loading branch information...
commit eb9e31eb89a5edc86a4ed6e7e1e09783a9aafa31 2 parents 9d12605 + 04dad6d
@fehguy fehguy authored
Showing with 18 additions and 11 deletions.
  1. +18 −11 source/javascripts/swagger-service.js
View
29 source/javascripts/swagger-service.js
@@ -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);
},
@@ -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);
@@ -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++) {
@@ -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;
@@ -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);
})
@@ -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);
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.