From fd93ac3ea8d68726116f471225602f025f81505e Mon Sep 17 00:00:00 2001 From: Michael Stewart Date: Wed, 11 Feb 2015 12:53:43 -0800 Subject: [PATCH 01/11] regex pattern matching fix --- src/js/swagger-compat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/swagger-compat.js b/src/js/swagger-compat.js index 288a646c4..551f9ac3d 100644 --- a/src/js/swagger-compat.js +++ b/src/js/swagger-compat.js @@ -792,7 +792,7 @@ SwaggerOperation.prototype.urlify = function (args) { if (param.paramType === 'path') { if (typeof args[param.name] !== 'undefined') { // apply path params and remove from args - var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi'); + var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi'); url = url.replace(reg, this.encodePathParam(args[param.name])); delete args[param.name]; } From a1da99aa5fdb95b2ce31c8f71588a7cf5adcf3a9 Mon Sep 17 00:00:00 2001 From: Cagdas Bayram Date: Wed, 18 Feb 2015 17:09:39 -0600 Subject: [PATCH 02/11] Adding response.statusText to the response out object to support custom statusText. --- src/js/swaggerHttp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/swaggerHttp.js b/src/js/swaggerHttp.js index 8b202a26c..fc3010afb 100644 --- a/src/js/swaggerHttp.js +++ b/src/js/swaggerHttp.js @@ -93,6 +93,7 @@ JQueryHttpClient.prototype.execute = function(obj) { url: request.url, method: request.method, status: response.status, + statusText: response.statusText, data: response.responseText, headers: headers }; From 7ff7aac79573f8e9fb8915cccc6ca44161e8f664 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:00:53 -0800 Subject: [PATCH 03/11] fix for #238, set ready on completion --- src/js/swagger-a.js | 1 + src/js/swagger-compat.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index 4426ca533..b72bb8258 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -54,6 +54,7 @@ SwaggerClient.prototype.initialize = function (url, options) { this.options = options; if (typeof options.success === 'function') { + this.ready = true; this.build(); } }; diff --git a/src/js/swagger-compat.js b/src/js/swagger-compat.js index 00a1c66f7..82b55923f 100644 --- a/src/js/swagger-compat.js +++ b/src/js/swagger-compat.js @@ -50,6 +50,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) { SwaggerClient.prototype.finish = function() { if (typeof this.success === 'function') { this.isValid = true; + this.ready = true; this.isBuilt = true; this.selfReflect(); this.success(); From 561a37920c551a1f7f966164fe9f9901fee48fbe Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:01:20 -0800 Subject: [PATCH 04/11] added model signature, removed overflow on self references --- src/js/arrayModel.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/js/arrayModel.js b/src/js/arrayModel.js index 1612413e1..33f734044 100644 --- a/src/js/arrayModel.js +++ b/src/js/arrayModel.js @@ -50,8 +50,29 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) { ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { var propertiesStr = []; + var i, prop; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + propertiesStr.push(prop.toString()); + } + + var strong = ''; + var stronger = ''; + var strongClose = ''; + var classOpen = strong + 'array' + ' {' + strongClose; + var classClose = strong + '}' + strongClose; + var returnVal = classOpen + '
' + propertiesStr.join(',
') + '
' + classClose; - if(this.ref) { - return models[simpleRef(this.ref)].getMockSignature(); + if (!modelsToIgnore) + modelsToIgnore = {}; + modelsToIgnore[this.name] = this; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + var ref = prop.$ref; + var model = models[ref]; + if (model && typeof modelsToIgnore[ref] === 'undefined') { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } } + return returnVal; }; From 6a3187cedf8640145cda278387476da6cf4aac27 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:01:51 -0800 Subject: [PATCH 05/11] test for overflow on self-referencing array models --- test/models.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/test/models.js b/test/models.js index 003fdc568..23ba6c9d1 100644 --- a/test/models.js +++ b/test/models.js @@ -89,7 +89,7 @@ describe('models', function() { // console.log(model.createJSONSample()); }); - it('should not get infinite recursion', function() { + it('should not get infinite for sample JSON recursion', function() { var definition = { type: 'object', properties: { @@ -130,7 +130,7 @@ describe('models', function() { ); }); - it('should not get infinite recursion case 2', function() { + it('should not get infinite recursion for sample JSON case 2', function() { var definition = { type: "array", items: { @@ -144,7 +144,7 @@ describe('models', function() { ); }); - it('should not get infinite recursion case 3', function() { + it('should not get infinite recursion for sample JSON case 3', function() { definition = { type: 'object', additionalProperties: { @@ -157,4 +157,47 @@ describe('models', function() { // console.log(model.createJSONSample()); // TODO add support for this }); + + + it('should not get infinite for mock signature recursion', function() { + var definition = { + type: 'object', + properties: { + pendingComponents: { + type: 'array', + items: { + $ref: 'Component' + } + }, + receivedComponents: { + type: 'array', + items: { + $ref: 'Component' + } + }, + rejectedComponents: { + type: 'array', + items: { + $ref: 'Component' + } + } + } + }; + var model = new swagger.Model('Component', definition); + swagger.addModel('Component', model); + var sig = model.getMockSignature(); + }); + + it('should not get infinite recursion for mock signature case 2', function() { + var definition = { + type: "array", + items: { + $ref: "ListOfSelf" + } + }; + var model = new swagger.Model('ListOfSelf', definition); + swagger.addModel('ListOfSelf', model); + var sig = model.getMockSignature(); + expect(sig).toEqual('array {
}'); + }); }); From f360f7eb8cb6c3c606a6544abad67c4c094f6851 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:02:07 -0800 Subject: [PATCH 06/11] updated version, rebuilt --- lib/swagger-client.js | 29 +++++++++++++++++++++++++---- lib/swagger-client.min.js | 4 ++-- package.json | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 6ff00aea6..8a73dc825 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -1,6 +1,6 @@ /** * swagger-client - swagger.js is a javascript client for use with swaggering APIs. - * @version v2.1.3-M1 + * @version v2.1.5-M1 * @link http://swagger.io * @license apache 2.0 */ @@ -57,10 +57,31 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) { ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { var propertiesStr = []; + var i, prop; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + propertiesStr.push(prop.toString()); + } + + var strong = ''; + var stronger = ''; + var strongClose = ''; + var classOpen = strong + 'array' + ' {' + strongClose; + var classClose = strong + '}' + strongClose; + var returnVal = classOpen + '
' + propertiesStr.join(',
') + '
' + classClose; - if(this.ref) { - return models[simpleRef(this.ref)].getMockSignature(); + if (!modelsToIgnore) + modelsToIgnore = {}; + modelsToIgnore[this.name] = this; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + var ref = prop.$ref; + var model = models[ref]; + if (model && typeof modelsToIgnore[ref] === 'undefined') { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } } + return returnVal; }; @@ -2356,7 +2377,7 @@ SwaggerOperation.prototype.urlify = function (args) { if (param.paramType === 'path') { if (typeof args[param.name] !== 'undefined') { // apply path params and remove from args - var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi'); + var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi'); url = url.replace(reg, this.encodePathParam(args[param.name])); delete args[param.name]; } diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index c21506fb7..c2e181c70 100644 --- a/lib/swagger-client.min.js +++ b/lib/swagger-client.min.js @@ -1,2 +1,2 @@ -!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(){return this.ref?g[simpleRef(this.ref)].getMockSignature():void 0};var t=function(){this.authz={}};t.prototype.add=function(e,t){return this.authz[e]=t,t},t.prototype.remove=function(e){return delete this.authz[e]},t.prototype.apply=function(e,t){var s,r,i,n,a=null;if("undefined"==typeof t||0===Object.keys(t).length)for(s in this.authz)i=this.authz[s],n=i.apply(e,t),n===!0&&(a=!0);else if(Array.isArray(t))for(var o=0;o0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s&&"date-time"===r?t="date-time":"string"===s&&"date"===r?t="date":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"string"===s?t="string":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+'
('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+'
('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0; -break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?(new T).execute(e):(new O).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.options=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file +!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s&&"date-time"===r?t="date-time":"string"===s&&"date"===r?t="date":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"string"===s?t="string":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0; +break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?(new T).execute(e):(new O).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.options=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file diff --git a/package.json b/package.json index 120d0bc0e..7e12e0858 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "swagger-client", "author": "Tony Tam ", "description": "swagger.js is a javascript client for use with swaggering APIs.", - "version": "2.1.4-M1", + "version": "2.1.5-M1", "homepage": "http://swagger.io", "repository": { "type": "git", From f5d3a311d095e32bcac6e0d400499b841535b839 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:06:53 -0800 Subject: [PATCH 07/11] fix from https://github.com/swagger-api/swagger-ui/pull/939 merged to proper repo --- src/js/swagger-a.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index b72bb8258..dddf1382c 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -1007,7 +1007,7 @@ var Property = function(name, obj, required) { this.optional = true; this.optional = !required; this.default = obj.default || null; - this.example = obj.example || null; + this.example = obj.example !== undefined ? obj.example : null; this.collectionFormat = obj.collectionFormat || null; this.maximum = obj.maximum || null; this.exclusiveMaximum = obj.exclusiveMaximum || null; From 57b52bf1318605c1c1551d7fe263e608eeea5749 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:20:15 -0800 Subject: [PATCH 08/11] tests for #225 --- test/operation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/operation.js b/test/operation.js index f36a960b7..a3bccfaf7 100644 --- a/test/operation.js +++ b/test/operation.js @@ -280,6 +280,18 @@ describe('operations', function() { var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'false' }); expect(op.deprecated).toEqual(false); }); + + it('should not encode parameters of type header', function() { + var parameters = [ + { in: 'header', name: 'user name', type: 'string' } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'false' }); + var args = {'user name': 'Tony Tam'}; + var opts = {mock: true}; + var obj = op.execute(args, opts); + expect(typeof obj.headers['user name'] === 'string').toBe(true); + expect(obj.headers['user name']).toEqual('Tony Tam'); + }); }); var quantityQP = { From 5b20e78420e616e765de75b2ca8fca7b43f842d0 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 17:25:30 -0800 Subject: [PATCH 09/11] added opts to pass to underlying http client, #229 --- lib/swagger-client.js | 4 +++- lib/swagger-client.min.js | 4 ++-- src/js/swagger-a.js | 2 +- src/js/swaggerHttp.js | 12 ++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 8a73dc825..42a7945c0 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -357,6 +357,7 @@ SwaggerClient.prototype.initialize = function (url, options) { this.options = options; if (typeof options.success === 'function') { + this.ready = true; this.build(); } }; @@ -1309,7 +1310,7 @@ var Property = function(name, obj, required) { this.optional = true; this.optional = !required; this.default = obj.default || null; - this.example = obj.example || null; + this.example = obj.example !== undefined ? obj.example : null; this.collectionFormat = obj.collectionFormat || null; this.maximum = obj.maximum || null; this.exclusiveMaximum = obj.exclusiveMaximum || null; @@ -1612,6 +1613,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) { SwaggerClient.prototype.finish = function() { if (typeof this.success === 'function') { this.isValid = true; + this.ready = true; this.isBuilt = true; this.selfReflect(); this.success(); diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index c2e181c70..333979b4b 100644 --- a/lib/swagger-client.min.js +++ b/lib/swagger-client.min.js @@ -1,2 +1,2 @@ -!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s&&"date-time"===r?t="date-time":"string"===s&&"date"===r?t="date":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"string"===s?t="string":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0; -break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?(new T).execute(e):(new O).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.options=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file +!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s&&"date-time"===r?t="date-time":"string"===s&&"date"===r?t="date":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"string"===s?t="string":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[]; +if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?(new T).execute(e):(new O).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.options=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index dddf1382c..2ed47114e 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -747,7 +747,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { if(opts.mock === true) return obj; else - new SwaggerHttp().execute(obj); + new SwaggerHttp().execute(obj, opts); }; Operation.prototype.setContentTypes = function(args, opts) { diff --git a/src/js/swaggerHttp.js b/src/js/swaggerHttp.js index 8b202a26c..296e7f020 100644 --- a/src/js/swaggerHttp.js +++ b/src/js/swaggerHttp.js @@ -3,7 +3,7 @@ */ var SwaggerHttp = function() {}; -SwaggerHttp.prototype.execute = function(obj) { +SwaggerHttp.prototype.execute = function(obj, opts) { if(obj && (typeof obj.useJQuery === 'boolean')) this.useJQuery = obj.useJQuery; else @@ -14,9 +14,9 @@ SwaggerHttp.prototype.execute = function(obj) { } if(this.useJQuery) - return new JQueryHttpClient().execute(obj); + return new JQueryHttpClient(opts).execute(obj); else - return new ShredHttpClient().execute(obj); + return new ShredHttpClient(opts).execute(obj); }; SwaggerHttp.prototype.isIE8 = function() { @@ -124,8 +124,8 @@ JQueryHttpClient.prototype.execute = function(obj) { /* * ShredHttpClient is a light-weight, node or browser HTTP client */ -var ShredHttpClient = function(options) { - this.options = (options||{}); +var ShredHttpClient = function(opts) { + this.opts = (opts||{}); this.isInitialized = false; var identity, toString; @@ -136,7 +136,7 @@ var ShredHttpClient = function(options) { } else this.Shred = require("shred"); - this.shred = new this.Shred(options); + this.shred = new this.Shred(opts); }; ShredHttpClient.prototype.initShred = function () { From fdf2f1a5360e987729e6440054289a27eb1edeca Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 19:41:20 -0800 Subject: [PATCH 10/11] fix for #243 --- lib/swagger-client.js | 31 +++++++++++++++---------------- lib/swagger-client.min.js | 4 ++-- src/js/swagger-a.js | 17 ++++++++--------- test/request.js | 7 +++++++ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 42a7945c0..f92f91895 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -576,8 +576,6 @@ var OperationGroup = function(tag, operation) { this.name = tag; this.operation = operation; this.operationsArray = []; - - this.description = operation.description || ""; }; var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { @@ -742,10 +740,14 @@ Operation.prototype.getType = function (param) { str = 'long'; else if(type === 'integer') str = 'integer'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; + else if(type === 'string') { + if(format === 'date-time') + str = 'date-time'; + else if(format === 'date') + str = 'date'; + else + str = 'string'; + } else if(type === 'number' && format === 'float') str = 'float'; else if(type === 'number' && format === 'double') @@ -754,8 +756,6 @@ Operation.prototype.getType = function (param) { str = 'double'; else if(type === 'boolean') str = 'boolean'; - else if(type === 'string') - str = 'string'; else if(type === 'array') { isArray = true; if(param.items) @@ -1050,14 +1050,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { if(opts.mock === true) return obj; else - new SwaggerHttp().execute(obj); + new SwaggerHttp().execute(obj, opts); }; Operation.prototype.setContentTypes = function(args, opts) { // default type var accepts = 'application/json'; var consumes = args.parameterContentType || 'application/json'; - var allDefinedParams = this.parameters; var definedFormParams = []; var definedFileParams = []; @@ -2747,7 +2746,7 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) { */ var SwaggerHttp = function() {}; -SwaggerHttp.prototype.execute = function(obj) { +SwaggerHttp.prototype.execute = function(obj, opts) { if(obj && (typeof obj.useJQuery === 'boolean')) this.useJQuery = obj.useJQuery; else @@ -2758,9 +2757,9 @@ SwaggerHttp.prototype.execute = function(obj) { } if(this.useJQuery) - return new JQueryHttpClient().execute(obj); + return new JQueryHttpClient(opts).execute(obj); else - return new ShredHttpClient().execute(obj); + return new ShredHttpClient(opts).execute(obj); }; SwaggerHttp.prototype.isIE8 = function() { @@ -2868,8 +2867,8 @@ JQueryHttpClient.prototype.execute = function(obj) { /* * ShredHttpClient is a light-weight, node or browser HTTP client */ -var ShredHttpClient = function(options) { - this.options = (options||{}); +var ShredHttpClient = function(opts) { + this.opts = (opts||{}); this.isInitialized = false; var identity, toString; @@ -2880,7 +2879,7 @@ var ShredHttpClient = function(options) { } else this.Shred = require("shred"); - this.shred = new this.Shred(options); + this.shred = new this.Shred(opts); }; ShredHttpClient.prototype.initShred = function () { diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index 333979b4b..495b06fc1 100644 --- a/lib/swagger-client.min.js +++ b/lib/swagger-client.min.js @@ -1,2 +1,2 @@ -!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s&&"date-time"===r?t="date-time":"string"===s&&"date"===r?t="date":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"string"===s?t="string":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[]; -if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?(new T).execute(e):(new O).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.options=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file +!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s?t="date-time"===r?"date-time":"date"===r?"date":"string":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g,p)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0; +break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e,t){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?new T(t).execute(e):new O(t).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.opts=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index 2ed47114e..d042c4ae0 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -273,8 +273,6 @@ var OperationGroup = function(tag, operation) { this.name = tag; this.operation = operation; this.operationsArray = []; - - this.description = operation.description || ""; }; var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { @@ -439,10 +437,14 @@ Operation.prototype.getType = function (param) { str = 'long'; else if(type === 'integer') str = 'integer'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; + else if(type === 'string') { + if(format === 'date-time') + str = 'date-time'; + else if(format === 'date') + str = 'date'; + else + str = 'string'; + } else if(type === 'number' && format === 'float') str = 'float'; else if(type === 'number' && format === 'double') @@ -451,8 +453,6 @@ Operation.prototype.getType = function (param) { str = 'double'; else if(type === 'boolean') str = 'boolean'; - else if(type === 'string') - str = 'string'; else if(type === 'array') { isArray = true; if(param.items) @@ -754,7 +754,6 @@ Operation.prototype.setContentTypes = function(args, opts) { // default type var accepts = 'application/json'; var consumes = args.parameterContentType || 'application/json'; - var allDefinedParams = this.parameters; var definedFormParams = []; var definedFileParams = []; diff --git a/test/request.js b/test/request.js index c08aaf0dc..97038cc5c 100644 --- a/test/request.js +++ b/test/request.js @@ -19,6 +19,13 @@ describe('swagger request functions', function() { done(); }); + it('gets the resource description', function() { + var storeApi = sample.apisArray[1]; + var req = storeApi.description; + + expect(req).toBe.undefined; + }); + it('generate a get request', function() { var petApi = sample.pet; var req = petApi.getPetById({petId: 1}, {mock: true}); From 935252bc573fd7516fd84c711bca1adeeaa80bc5 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 18 Feb 2015 20:56:14 -0800 Subject: [PATCH 11/11] added tags description support for #243 --- lib/swagger-client.js | 21 ++++++++++++++++++--- lib/swagger-client.min.js | 4 ++-- src/js/swagger-a.js | 21 ++++++++++++++++++--- test/request.js | 10 +++++++--- test/spec/v2/petstore.json | 10 ++++++++++ 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index f92f91895..5173335d9 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -433,8 +433,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) { // legacy support this.authSchemes = response.securityDefinitions; - var location; + var definedTags = {}; + if(Array.isArray(response.tags)) { + definedTags = {}; + for(k = 0; k < response.tags.length; k++) { + var t = response.tags[k]; + definedTags[t.name] = t; + } + } + var location; if(typeof this.url === 'string') { location = this.parseUri(this.url); } @@ -500,8 +508,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) { operationGroup.operations = {}; operationGroup.label = tag; operationGroup.apis = []; + var tagObject = definedTags[tag]; + if(typeof tagObject === 'object') { + operationGroup.description = tagObject.description; + operationGroup.externalDocs = tagObject.externalDocs; + } this[tag].help = this.help.bind(operationGroup); - this.apisArray.push(new OperationGroup(tag, operationObject)); + this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject)); } operationGroup[operationId] = operationObject.execute.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject); @@ -570,9 +583,11 @@ SwaggerClient.prototype.fail = function(message) { throw message; }; -var OperationGroup = function(tag, operation) { +var OperationGroup = function(tag, description, externalDocs, operation) { this.tag = tag; this.path = tag; + this.description = description; + this.externalDocs = externalDocs; this.name = tag; this.operation = operation; this.operationsArray = []; diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index 495b06fc1..7fee78976 100644 --- a/lib/swagger-client.min.js +++ b/lib/swagger-client.min.js @@ -1,2 +1,2 @@ -!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var h;for(h=0;h0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s?t="date-time"===r?"date-time":"date"===r?"date":"string":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g,p)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0; -break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e,t){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?new T(t).execute(e):new O(t).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.opts=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file +!function(){var e=function(e){this.name="arrayModel",this.definition=e||{},this.properties=[];var t=(e["enum"]||[],e.items);return t&&(t.type?this.type=typeFromJsonSchema(t.type,t.format):this.ref=t.$ref),this};e.prototype.createJSONSample=function(e){var t;if(e=e||{},this.type)t=this.type;else if(this.ref){var s=simpleRef(this.ref);if("undefined"!=typeof e[s])return s;e[s]=this,t=g[s].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var s=simpleRef(this.ref);t=g[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var i=function(e){this.cookie=e};i.prototype.apply=function(e){return e.cookieJar=e.cookieJar||CookieJar(),e.cookieJar.setCookie(this.cookie),!0};var n=function(e,t,s){this.name=e,this.username=t,this.password=s,this._btoa=null,this._btoa="undefined"!=typeof window?btoa:require("btoa")};n.prototype.apply=function(e){var t=this._btoa;return e.headers.Authorization="Basic "+t(this.username+":"+this.password),!0};var a=function(e,t){return function(){return e.apply(t,arguments)}};fail=function(e){log(e)},log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var s=t||0,r=this.length;r>s;s++)if(this[s]===e)return s;return-1});var o=function(e,t){var s="undefined"!=typeof window?window:exports;return s.parameterMacro?s.parameterMacro(e,t):t.defaultValue},p=function(e,t){var s="undefined"!=typeof window?window:exports;return s.modelPropertyMacro?s.modelPropertyMacro(e,t):t.defaultValue},u=function(e){this.name="name",this.definition=e||{},this.properties=[];e["enum"]||[];this.type=typeFromJsonSchema(e.type,e.format)};u.prototype.createJSONSample=function(){var e=this.type;return e},u.prototype.getSampleValue=function(){this.type;return null},u.prototype.getMockSignature=function(e){var t,s,r=[];for(t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t0){var m;for(m=0;m0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(o),this};f.prototype.sort=function(){},d.prototype.getType=function(e){var t,s=e.type,r=e.format,i=!1;"integer"===s&&"int32"===r?t="integer":"integer"===s&&"int64"===r?t="long":"integer"===s?t="integer":"string"===s?t="date-time"===r?"date-time":"date"===r?"date":"string":"number"===s&&"float"===r?t="float":"number"===s&&"double"===r?t="double":"number"===s?t="double":"boolean"===s?t="boolean":"array"===s&&(i=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var n=e.schema;if(n){var a=n.$ref;return a?(a=simpleRef(a),i?[a]:a):this.getType(n)}return i?[t]:t},d.prototype.resolveModel=function(t,s){if("undefined"!=typeof t.$ref){var r=t.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),s[r])return new c(r,s[r])}return"array"===t.type?new e(t):null},d.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",s=0;s0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},d.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},d.prototype.execute=function(e,t,s,r,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=s,a=r),"function"==typeof t&&(n=t,a=s),n=n||log,a=a||log,"boolean"==typeof p.useJQuery&&(this.useJQuery=p.useJQuery);var u=this.getMissingParams(o);if(u.length>0){var h="missing required params: "+u;return void fail(h)}var l,f=this.getHeaderParams(o),d=this.setContentTypes(o,p),c={};for(l in f)c[l]=f[l];for(l in d)c[l]=d[l];{var m=this.getBody(c,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:c,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(g,this.operation.security)}return p.mock===!0?g:void(new C).execute(g,p)},d.prototype.setContentTypes=function(e,t){var s,r,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(r=0;r0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?s="{}":"DELETE"!=this.type&&(n=null):t.requestContentType&&(n=t.requestContentType),n&&this.consumes&&-1===this.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),i=t.responseContentType?t.responseContentType:"application/json",i&&this.produces&&-1===this.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==s||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},d.prototype.asCurl=function(e){var t=[],s=this.getHeaderParams(e);if(s){var r;for(r in s)t.push('--header "'+r+": "+s[r]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},d.prototype.encodePathCollection=function(e,t,s){var r,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(s[r]);else{var n="";if("csv"===e)n=",";else if("ssv"===e)n="%20";else if("tsv"===e)n="\\t";else if("pipes"===e)n="|";else if("brackets"===e)for(r=0;rr;r++)t.push(encodeURIComponent(s[r]));return t.join("/")};var c=function(t,s){this.name=t,this.definition=s||{},this.properties=[];var r=s.required||[];if("array"===s.type){var i=new e(s);return i}var n,a=s.properties;if(a)for(n in a){var o=!1,p=a[n];r.indexOf(n)>=0&&(o=!0),this.properties.push(new m(n,p,o))}};c.prototype.createJSONSample=function(e){var t,s={};for(e=e||{},e[this.name]=this,t=0;t"+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t'+this.name+' ('+e+"",this.required||(e+=', optional'),e+=")"):e=this.name+" ("+JSON.stringify(this.obj)+")","undefined"!=typeof this.description&&(e+=": "+this.description),this["enum"]&&(e+=' = [\''+this["enum"].join("' or '")+"']"),this.descr&&(e+=': '+this.descr+"");var t,s="",r="array"===this.schema.type;switch(t=r?this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(s+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(s+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(s+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(s+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(s+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(s+=optionHtml("Exclusive Min.","true")),this.maximum&&(s+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(s+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(s+=optionHtml("Multiple Of",this.multipleOf))}if(r&&(this.minItems&&(s+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(s+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(s+=optionHtml("Unique Items","true")),this.collectionFormat&&(s+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',s+=optionHtml("Enum",i)}return s.length>0&&(e=''+e+'"+s+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var s;return"integer"===e&&"int32"===t?s="integer":"integer"===e&&"int64"===t?s="long":"integer"===e&&"undefined"==typeof t?s="long":"string"===e&&"date-time"===t?s="date-time":"string"===e&&"date"===t?s="date":"number"===e&&"float"===t?s="float":"number"===e&&"double"===t?s="double":"number"===e&&"undefined"==typeof t?s="double":"boolean"===e?s="boolean":"string"===e&&(s="string"),s};var y={},g={};l.prototype.buildFrom1_2Spec=function(e){null!==e.apiVersion&&(this.apiVersion=e.apiVersion),this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.authSchemes=e.authorizations,this.info=this.convertInfo(e.info);var t,s,r=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,s=new v(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(this.expectedResourceCount=e.apis.length,o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,t=new v(e,this),this.apis[a]=t,this.apisArray.push(t)}else for(k=0;k0&&(this.basePath=-1===e.basePath.indexOf("http")?this.getAbsoluteBasePath(e.basePath):e.basePath),this.resourcePath=e.resourcePath,this.addModels(e.models),e.apis)for(var t=0;t|.\/?,\\'""-]/g,"_"),t=t.replace(/((_){2,})/g,"_"),t=t.replace(/^(_)*/g,""),t=t.replace(/([_])*$/g,"")};var b=function(e,t){this.name="undefined"!=typeof t.id?t.id:e,this.properties=[];var s;for(s in t.properties){if(t.required){var r;for(r in t.required)s===t.required[r]&&(t.properties[s].required=!0)}var i=new w(s,t.properties[s],this);this.properties.push(i)}};b.prototype.setReferencedModels=function(e){for(var t=[],s=0;s"+r.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+s.refModel.getMockSignature(e));return p},b.prototype.createJSONSample=function(e){if(y[this.name])return y[this.name];var t={};e=e||[],e.push(this.name);for(var s=0;s'+this.name+' ('+this.dataTypeWithRef+"";return this.required||(t+=', optional'),t+=")",this.values&&(t+=' = [\''+this.values.join("' or '")+"']"),this.descr&&(t+=': '+this.descr+""),t +};var S=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];if(this.nickname=e||y.push("SwaggerOperations must have a nickname."),this.path=t||y.push("SwaggerOperation "+e+" is missing path."),this.method=s||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=r?r:[],this.summary=i,this.notes=n,this.type=p,this.responseMessages=u||[],this.resource=h||y.push("Resource is required"),this.consumes=l,this.produces=f,this.authorizations="undefined"!=typeof d?d:h.authorizations,this.deprecated=c,this["do"]=a(this["do"],this),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}y.length>0&&(console.error("SwaggerOperation errors",y,arguments),this.resource.api.fail(y)),this.path=this.path.replace("{format}","json"),this.method=this.method.toLowerCase(),this.isGetMethod="get"===this.method;var g,v,b;for(this.resourceName=this.resource.name,"undefined"!=typeof this.type&&"void"===this.type?this.type=null:(this.responseClassSignature=this.getSignature(this.type,this.resource.models),this.responseSampleJSON=this.getSampleJSON(this.type,this.resource.models)),g=0;g=0?e.substring(e.indexOf("[")+1,e.indexOf("]")):void 0},S.prototype.getSignature=function(e,t){var s,r;return r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,s?e:"undefined"!=typeof r?t[r].getMockSignature():t[e].getMockSignature()},S.prototype.getSampleJSON=function(e,t){var s,r,i;if(r=this.isListType(e),s="undefined"!=typeof r&&t[r]||"undefined"!=typeof t[e]?!1:!0,i=s?void 0:r?t[r].createJSONSample():t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName){var a=(new XMLSerializer).serializeToString(n);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},S.prototype["do"]=function(e,t,s,r){var i,n,a,o,p,u=[];"function"!=typeof r&&(r=function(e,t,s){return log(e,t,s)}),"function"!=typeof s&&(s=function(e){var t;return t=null,t=null!==e?e.data:"no data",log("default callback: "+t)}),a={},a.headers=[],e.headers&&(a.headers=e.headers,delete e.headers),t&&t.responseContentType&&(a.headers["Content-Type"]=t.responseContentType),t&&t.requestContentType&&(a.headers.Accept=t.requestContentType);for(var h=0;hi;i++)s=r[i],t.push(encodeURIComponent(s));return t.join("/")},S.prototype.urlify=function(e){var t,s,r,i;i=this.resource.basePath.length>1&&"/"===this.resource.basePath.slice(-1)&&"/"===this.pathJson().charAt(0)?this.resource.basePath+this.pathJson().substring(1):this.resource.basePath+this.pathJson();var n=this.parameters;for(t=0;t0&&(p+=","),p+=encodeURIComponent(r[s]);o+=encodeURIComponent(r.name)+"="+p}else if("undefined"!=typeof e[r.name])o+=encodeURIComponent(r.name)+"="+encodeURIComponent(e[r.name]);else if(r.required)throw""+r.name+" is a required query param.";return o&&o.length>0&&(i+="?"+o),i},S.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},S.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},S.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},S.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},S.prototype.getMatchingParams=function(e,t){for(var s={},r=this.parameters,i=0;i)(<)(\/*)/g,h=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(h,"$1\n").replace(t,"$1\n$2"),o=0,s="",n=e.split("\n"),r=0,i="other",u={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},l=function(e){var t,n,a,o,p,h,l;h={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},p=function(){var e;e=[];for(a in h)l=h[a],l&&e.push(a);return e}()[0],p=void 0===p?"other":p,t=i+"->"+p,i=p,o="",r+=u[t],o=function(){var e,t,s;for(s=[],n=e=0,t=r;t>=0?t>e:e>t;n=t>=0?++e:--e)s.push(" ");return s}().join(""),"opening->closing"===t?s=s.substr(0,s.length-1)+e+"\n":s+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return s};var x=function(e,t,s,r,i,n,a,o){var p=this,u=[];if(this.useJQuery="undefined"!=typeof a.resource.useJQuery?a.resource.useJQuery:null,this.type=e||u.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."),this.url=t||u.push("SwaggerRequest url is required."),this.params=s,this.opts=r,this.successCallback=i||u.push("SwaggerRequest successCallback is required."),this.errorCallback=n||u.push("SwaggerRequest error callback is required."),this.operation=a||u.push("SwaggerRequest operation is required."),this.execution=o,this.headers=s.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(s,r,this.operation),l=s.body;if(h["Content-Type"]){var f,d,c,m={},y=this.operation.parameters;for(c=0;c0?n=p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?u="{}":"DELETE"!=this.type&&(n=null):this.opts.requestContentType&&(n=this.opts.requestContentType),n&&this.operation.consumes&&-1===this.operation.consumes.indexOf(n)&&log("server doesn't consume "+n+", try "+JSON.stringify(this.operation.consumes)),i=this.opts&&this.opts.responseContentType?this.opts.responseContentType:"application/json",i&&s.produces&&-1===s.produces.indexOf(i)&&log("server can't produce "+i),(n&&""!==u||"application/x-www-form-urlencoded"===n)&&(h["Content-Type"]=n),i&&(h.Accept=i),h};var C=function(){};C.prototype.execute=function(e,t){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body=JSON.stringify(e.body)),this.useJQuery?new T(t).execute(e):new O(t).execute(e)},C.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent&&(nav=navigator.userAgent.toLowerCase(),-1!==nav.indexOf("msie"))){var t=parseInt(nav.split("msie")[1]);8>=t&&(e=!0)}return e};var T=function(){"use strict";if(!e)var e=window.jQuery};T.prototype.execute=function(e){var t=e.on,s=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var s,r;if(e.headers){r=[];for(s in e.headers)r.push("content-type"===s.toLowerCase()?e.contentType=e.headers[s]:"accept"===s.toLowerCase()?e.accepts=e.headers[s]:t.setRequestHeader(s,e.headers[s]));return r}},e.data=e.body,e.complete=function(e){for(var r={},i=e.getAllResponseHeaders().split("\n"),n=0;n0))try{h.obj=e.responseJSON||JSON.parse(h.data)||{}}catch(f){log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(h);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(h);t.error(h)}},jQuery.support.cors=!0,jQuery.ajax(e)};var O=function(e){this.opts=e||{},this.isInitialized=!1;"undefined"!=typeof window?(this.Shred=require("./shred"),this.content=require("./shred/content")):this.Shred=require("shred"),this.shred=new this.Shred(e)};O.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},O.prototype.registerProcessors=function(){var e=function(e){return e},t=function(e){return e.toString()};"undefined"!=typeof window?this.content.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t}):this.Shred.registerProcessor(["application/json; charset=utf-8","application/json","json"],{parser:e,stringify:t})},O.prototype.execute=function(e){this.isInitialized||this.initShred();var t,s=e.on,r=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},s=e._headers.normalized||e._headers,r=s["content-type"]||s["Content-Type"]||null;if(r&&(0===r.indexOf("application/json")||r.indexOf("+json")>0))if(e.content.data&&""!==e.content.data)try{t.obj=JSON.parse(e.content.data)}catch(i){}else t.obj={};return t},i=function(e){var t={status:0,data:e.message||e};return e.code&&(t.obj=e,("ENOTFOUND"===e.code||"ECONNREFUSED"===e.code)&&(t.status=404)),t};return t={error:function(t){return e?s.error(r(t)):void 0},request_error:function(t){return e?s.error(i(t)):void 0},response:function(t){return e?s.response(r(t)):void 0}},e&&(e.on=t),this.shred.request(e)};var P="undefined"!=typeof window?window:exports;P.authorizations=new t,P.ApiKeyAuthorization=s,P.PasswordAuthorization=n,P.CookieAuthorization=i,P.SwaggerClient=l,P.SwaggerApi=l,P.Operation=d,P.Model=c,P.addModel=h}(); \ No newline at end of file diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index d042c4ae0..d3c0c3347 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -130,8 +130,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) { // legacy support this.authSchemes = response.securityDefinitions; - var location; + var definedTags = {}; + if(Array.isArray(response.tags)) { + definedTags = {}; + for(k = 0; k < response.tags.length; k++) { + var t = response.tags[k]; + definedTags[t.name] = t; + } + } + var location; if(typeof this.url === 'string') { location = this.parseUri(this.url); } @@ -197,8 +205,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) { operationGroup.operations = {}; operationGroup.label = tag; operationGroup.apis = []; + var tagObject = definedTags[tag]; + if(typeof tagObject === 'object') { + operationGroup.description = tagObject.description; + operationGroup.externalDocs = tagObject.externalDocs; + } this[tag].help = this.help.bind(operationGroup); - this.apisArray.push(new OperationGroup(tag, operationObject)); + this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject)); } operationGroup[operationId] = operationObject.execute.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject); @@ -267,9 +280,11 @@ SwaggerClient.prototype.fail = function(message) { throw message; }; -var OperationGroup = function(tag, operation) { +var OperationGroup = function(tag, description, externalDocs, operation) { this.tag = tag; this.path = tag; + this.description = description; + this.externalDocs = externalDocs; this.name = tag; this.operation = operation; this.operationsArray = []; diff --git a/test/request.js b/test/request.js index 97038cc5c..4b0b6c82f 100644 --- a/test/request.js +++ b/test/request.js @@ -20,10 +20,14 @@ describe('swagger request functions', function() { }); it('gets the resource description', function() { - var storeApi = sample.apisArray[1]; - var req = storeApi.description; + var userApi = sample.user; + expect(userApi.description).toEqual('All about the Users'); + }); - expect(req).toBe.undefined; + it('gets the resource external docs', function() { + var petApi = sample.pet; + expect(petApi.description).toEqual('Pet Operations'); + expect(petApi.externalDocs).toEqual('http://swagger.io'); }); it('generate a get request', function() { diff --git a/test/spec/v2/petstore.json b/test/spec/v2/petstore.json index f61bcfe11..cd309ee66 100644 --- a/test/spec/v2/petstore.json +++ b/test/spec/v2/petstore.json @@ -18,6 +18,16 @@ "schemes": [ "http" ], + "tags" : [ + { + "name": "pet", + "description": "Pet Operations", + "externalDocs": "http://swagger.io" + }, { + "name": "user", + "description": "All about the Users" + } + ], "paths": { "/pet": { "post": {