From a6855057a29d84e3582da4777c0646d9a0f02196 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 9 Dec 2014 22:24:38 -0800 Subject: [PATCH] fix for https://github.com/swagger-api/swagger-ui/issues/770, checking method instead of type --- lib/swagger-client.js | 126 ++++++++++++++--------------- package.json | 2 +- src/main/javascript/swagger.js | 2 +- src/main/javascript/swaggerHttp.js | 8 +- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 2f46af5c5..1f9ee6831 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -1,5 +1,61 @@ // swagger-client.js -// version 2.1.0-alpha.3 +// version 2.1.0-alpha.4 +/** + * Array Model + **/ +var ArrayModel = function(definition) { + this.name = "name"; + this.definition = definition || {}; + this.properties = []; + this.type; + this.ref; + + var requiredFields = definition.enum || []; + var items = definition.items; + if(items) { + var type = items.type; + if(items.type) { + this.type = typeFromJsonSchema(type.type, type.format); + } + else { + this.ref = items['$ref']; + } + } +} + +ArrayModel.prototype.createJSONSample = function(modelsToIgnore) { + var result; + modelsToIgnore = (modelsToIgnore||{}) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].createJSONSample(); + } + return [ result ]; +}; + +ArrayModel.prototype.getSampleValue = function(modelsToIgnore) { + var result; + modelsToIgnore = (modelsToIgnore || {}) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].getSampleValue(modelsToIgnore); + } + return [ result ]; +} + +ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + + if(this.ref) { + return models[simpleRef(this.ref)].getMockSignature(); + } +}; /** * SwaggerAuthorizations applys the correct authorization to an operation being executed @@ -101,63 +157,7 @@ PasswordAuthorization.prototype.apply = function(obj, authorizations) { var base64encoder = this._btoa; obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password); return true; -};/** - * Array Model - **/ -var ArrayModel = function(definition) { - this.name = "name"; - this.definition = definition || {}; - this.properties = []; - this.type; - this.ref; - - var requiredFields = definition.enum || []; - var items = definition.items; - if(items) { - var type = items.type; - if(items.type) { - this.type = typeFromJsonSchema(type.type, type.format); - } - else { - this.ref = items['$ref']; - } - } -} - -ArrayModel.prototype.createJSONSample = function(modelsToIgnore) { - var result; - modelsToIgnore = (modelsToIgnore||{}) - if(this.type) { - result = type; - } - else if (this.ref) { - var name = simpleRef(this.ref); - result = models[name].createJSONSample(); - } - return [ result ]; -}; - -ArrayModel.prototype.getSampleValue = function(modelsToIgnore) { - var result; - modelsToIgnore = (modelsToIgnore || {}) - if(this.type) { - result = type; - } - else if (this.ref) { - var name = simpleRef(this.ref); - result = models[name].getSampleValue(modelsToIgnore); - } - return [ result ]; -} - -ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { - var propertiesStr = []; - - if(this.ref) { - return models[simpleRef(this.ref)].getMockSignature(); - } -}; -var __bind = function(fn, me){ +};var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; @@ -936,7 +936,7 @@ Operation.prototype.setContentTypes = function(args, opts) { } // if there's a body, need to set the accepts header via requestContentType - if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) { + if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { if (opts.requestContentType) consumes = opts.requestContentType; } else { @@ -1350,7 +1350,7 @@ JQueryHttpClient.prototype.execute = function(obj) { obj.data = obj.body; obj.complete = function(response, textStatus, opts) { var headers = {}, - headerArray = response.getAllResponseHeaders().split("\n"); + headerArray = response.getAllResponseHeaders().split("\n"); for(var i = 0; i < headerArray.length; i++) { var toSplit = headerArray[i].trim(); @@ -1363,7 +1363,7 @@ JQueryHttpClient.prototype.execute = function(obj) { continue; } var name = toSplit.substring(0, separator).trim(), - value = toSplit.substring(separator + 1).trim(); + value = toSplit.substring(separator + 1).trim(); headers[name] = value; } @@ -1379,11 +1379,11 @@ JQueryHttpClient.prototype.execute = function(obj) { if(contentType != null) { if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { - if(response.responseText && response.responseText !== "") + if(response.responseText && response.responseText !== "") { try { out.obj = JSON.parse(response.content.data); } - catch () { + catch (ex) { // do not set out.obj log ("unable to parse JSON content"); } diff --git a/package.json b/package.json index aa1c31a45..1be826893 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ } ], "description": "swagger.js is a javascript client for use with swaggering APIs.", - "version": "2.1.0-alpha.3", + "version": "2.1.0-alpha.4", "homepage": "http://swagger.io", "repository": { "type": "git", diff --git a/src/main/javascript/swagger.js b/src/main/javascript/swagger.js index d23eb29d1..4292c2d9e 100644 --- a/src/main/javascript/swagger.js +++ b/src/main/javascript/swagger.js @@ -645,7 +645,7 @@ Operation.prototype.setContentTypes = function(args, opts) { } // if there's a body, need to set the accepts header via requestContentType - if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) { + if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { if (opts.requestContentType) consumes = opts.requestContentType; } else { diff --git a/src/main/javascript/swaggerHttp.js b/src/main/javascript/swaggerHttp.js index 4eca83dff..4c3ea0a23 100644 --- a/src/main/javascript/swaggerHttp.js +++ b/src/main/javascript/swaggerHttp.js @@ -69,7 +69,7 @@ JQueryHttpClient.prototype.execute = function(obj) { obj.data = obj.body; obj.complete = function(response, textStatus, opts) { var headers = {}, - headerArray = response.getAllResponseHeaders().split("\n"); + headerArray = response.getAllResponseHeaders().split("\n"); for(var i = 0; i < headerArray.length; i++) { var toSplit = headerArray[i].trim(); @@ -82,7 +82,7 @@ JQueryHttpClient.prototype.execute = function(obj) { continue; } var name = toSplit.substring(0, separator).trim(), - value = toSplit.substring(separator + 1).trim(); + value = toSplit.substring(separator + 1).trim(); headers[name] = value; } @@ -98,11 +98,11 @@ JQueryHttpClient.prototype.execute = function(obj) { if(contentType != null) { if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { - if(response.responseText && response.responseText !== "") + if(response.responseText && response.responseText !== "") { try { out.obj = JSON.parse(response.content.data); } - catch () { + catch (ex) { // do not set out.obj log ("unable to parse JSON content"); }