Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

now using basePath returned by the apis #13

Merged
merged 1 commit into from

2 participants

@ayush

No description provided.

@fehguy fehguy merged commit eb9e31e into swagger-api:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2012
  1. @ayush

    using basePath from the apis

    ayush authored
This page is out of date. Refresh to see the latest.
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) {
Something went wrong with that request. Please try again.