added response check for swagger 2.0/1.2 client
This commit is contained in:
6
dist/lib/swagger-client.js
vendored
6
dist/lib/swagger-client.js
vendored
@@ -184,6 +184,7 @@ var SwaggerClient = function(url, options) {
|
||||
this.basePath = null;
|
||||
this.authorizations = null;
|
||||
this.authorizationScheme = null;
|
||||
this.isValid = false;
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
|
||||
@@ -236,6 +237,11 @@ SwaggerClient.prototype.build = function() {
|
||||
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
||||
self.swaggerVersion = responseObj.swagger;
|
||||
self.buildFromSpec(responseObj);
|
||||
self.isValid = true;
|
||||
}
|
||||
else {
|
||||
self.isValid = false;
|
||||
self.failure()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
dist/lib/swagger.js
vendored
3
dist/lib/swagger.js
vendored
@@ -99,6 +99,7 @@ var SwaggerApi = function(url, options) {
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
this.modelsArray = [];
|
||||
this.isValid;
|
||||
|
||||
options = (options||{});
|
||||
if (url)
|
||||
@@ -213,6 +214,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
this.apisArray.push(res);
|
||||
}
|
||||
}
|
||||
this.isValid = true;
|
||||
if (this.success) {
|
||||
this.success();
|
||||
}
|
||||
@@ -260,6 +262,7 @@ SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
|
||||
this.apisArray.push(res);
|
||||
}
|
||||
}
|
||||
this.isValid = true;
|
||||
if (this.success) {
|
||||
this.success();
|
||||
}
|
||||
|
||||
19
dist/swagger-ui.js
vendored
19
dist/swagger-ui.js
vendored
@@ -1258,7 +1258,13 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return _this.showMessage(d);
|
||||
};
|
||||
this.options.failure = function(d) {
|
||||
return _this.onLoadFailure(d);
|
||||
if (_this.api && _this.api.isValid === false) {
|
||||
log("not a valid 2.0 spec, loading legacy client");
|
||||
_this.api = new SwaggerApi(_this.options);
|
||||
return _this.api.build();
|
||||
} else {
|
||||
return _this.onLoadFailure(d);
|
||||
}
|
||||
};
|
||||
this.headerView = new HeaderView({
|
||||
el: $('#header')
|
||||
@@ -1284,15 +1290,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
}
|
||||
this.options.url = url;
|
||||
this.headerView.update(url);
|
||||
if (url.indexOf('swagger.json') > 0) {
|
||||
this.api = new SwaggerClient(this.options);
|
||||
this.api.build();
|
||||
return this.api;
|
||||
} else {
|
||||
this.api = new SwaggerApi(this.options);
|
||||
this.api.build();
|
||||
return this.api;
|
||||
}
|
||||
this.api = new SwaggerClient(this.options);
|
||||
return this.api.build();
|
||||
};
|
||||
|
||||
SwaggerUi.prototype.render = function() {
|
||||
|
||||
2
dist/swagger-ui.min.js
vendored
2
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -184,6 +184,7 @@ var SwaggerClient = function(url, options) {
|
||||
this.basePath = null;
|
||||
this.authorizations = null;
|
||||
this.authorizationScheme = null;
|
||||
this.isValid = false;
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
|
||||
@@ -236,6 +237,11 @@ SwaggerClient.prototype.build = function() {
|
||||
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
||||
self.swaggerVersion = responseObj.swagger;
|
||||
self.buildFromSpec(responseObj);
|
||||
self.isValid = true;
|
||||
}
|
||||
else {
|
||||
self.isValid = false;
|
||||
self.failure()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ var SwaggerApi = function(url, options) {
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
this.modelsArray = [];
|
||||
this.isValid;
|
||||
|
||||
options = (options||{});
|
||||
if (url)
|
||||
@@ -213,6 +214,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
this.apisArray.push(res);
|
||||
}
|
||||
}
|
||||
this.isValid = true;
|
||||
if (this.success) {
|
||||
this.success();
|
||||
}
|
||||
@@ -260,6 +262,7 @@ SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
|
||||
this.apisArray.push(res);
|
||||
}
|
||||
}
|
||||
this.isValid = true;
|
||||
if (this.success) {
|
||||
this.success();
|
||||
}
|
||||
|
||||
@@ -22,9 +22,16 @@ class SwaggerUi extends Backbone.Router
|
||||
@options = options
|
||||
|
||||
# Set the callbacks
|
||||
@options.success = => @render()
|
||||
@options.success = =>
|
||||
@render()
|
||||
@options.progress = (d) => @showMessage(d)
|
||||
@options.failure = (d) => @onLoadFailure(d)
|
||||
@options.failure = (d) =>
|
||||
if @api and @api.isValid is false
|
||||
log "not a valid 2.0 spec, loading legacy client"
|
||||
@api = new SwaggerApi(@options)
|
||||
@api.build()
|
||||
else
|
||||
@onLoadFailure(d)
|
||||
|
||||
# Create view to handle the header inputs
|
||||
@headerView = new HeaderView({el: $('#header')})
|
||||
@@ -48,15 +55,8 @@ class SwaggerUi extends Backbone.Router
|
||||
@options.url = url
|
||||
@headerView.update(url)
|
||||
|
||||
if url.indexOf('swagger.json') > 0
|
||||
@api = new SwaggerClient(@options)
|
||||
@api.build()
|
||||
@api
|
||||
else
|
||||
@api = new SwaggerApi(@options)
|
||||
@api.build()
|
||||
@api
|
||||
|
||||
@api = new SwaggerClient(@options)
|
||||
@api.build()
|
||||
|
||||
# This is bound to success handler for SwaggerApi
|
||||
# so it gets called when SwaggerApi completes loading
|
||||
|
||||
Reference in New Issue
Block a user