Ver código fonte

added response check for swagger 2.0/1.2 client

bubble
Tony Tam 10 anos atrás
pai
commit
91822035ef
7 arquivos alterados com 39 adições e 22 exclusões
  1. +6
    -0
      dist/lib/swagger-client.js
  2. +3
    -0
      dist/lib/swagger.js
  3. +9
    -10
      dist/swagger-ui.js
  4. +1
    -1
      dist/swagger-ui.min.js
  5. +6
    -0
      lib/swagger-client.js
  6. +3
    -0
      lib/swagger.js
  7. +11
    -11
      src/main/coffeescript/SwaggerUi.coffee

+ 6
- 0
dist/lib/swagger-client.js Ver arquivo

@@ -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
- 0
dist/lib/swagger.js Ver arquivo

@@ -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();
}


+ 9
- 10
dist/swagger-ui.js Ver arquivo

@@ -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() {


+ 1
- 1
dist/swagger-ui.min.js
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 6
- 0
lib/swagger-client.js Ver arquivo

@@ -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
- 0
lib/swagger.js Ver arquivo

@@ -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();
}


+ 11
- 11
src/main/coffeescript/SwaggerUi.coffee Ver arquivo

@@ -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


Carregando…
Cancelar
Salvar