diff --git a/lib/swagger-client.js b/lib/swagger-client.js index c078b2f78..a5f00c0fe 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.0-alpha.7 + * @version v2.1.0-M1 * @link http://swagger.io * @license apache 2.0 */ @@ -795,9 +795,7 @@ Operation.prototype.getHeaderParams = function (args) { if (param.in === 'header') { var value = args[param.name]; if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); + value = value.toString(); headers[param.name] = value; } } diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index a366aba12..b4207d15e 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);t=y[s].createJSONSample()}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=y[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(){return this.ref?y[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=null;if("undefined"==typeof t||0==Object.keys(t).length)for(s in this.authz)r=this.authz[s],i=r.apply(e,t),i===!0&&(n=!0);else if(Array.isArray(t))for(var a=0;a0?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};l.prototype.sort=function(){},f.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},f.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 d(r,s[r])}return"array"===t.type?new e(t):null},f.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}},f.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},f.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=this.getHeaderParams(o);l=this.setContentTypes(o,p);{var f=this.getBody(l,o),d=this.urlify(o),c={url:d,method:this.method.toUpperCase(),body:f,useJQuery:this.useJQuery,headers:l,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};P.authorizations.apply(c,this.operation.security)}return p.mock===!0?c:void(new x).execute(c)},f.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},f.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)},f.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 d=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 c(n,p,o))}};d.prototype.createJSONSample=function(e){var t={};e=e||{},e[this.name]=this;var s;for(s=0;s"+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(r?t=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 m={},y={};h.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 g(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(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 g(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.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 v=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 b(s,t.properties[s],this);this.properties.push(i)}};v.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},v.prototype.createJSONSample=function(e){if(m[this.name])return m[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 w=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];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="string"==typeof c?Boolean(c):c,this["do"]=a(this["do"],this),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},w.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()},w.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:null!=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}},w.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=[],null!=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("/")},w.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 null!=o&&o.length>0&&(i+="?"+o),i},w.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},w.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},w.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},w.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},w.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 S=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 x=function(){};x.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 C).execute(e)},x.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||{}}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 C=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)};C.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},C.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})},C.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=h,P.Operation=f,P.Model=d,P.models=y}(); \ 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);t=y[s].createJSONSample()}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=y[s].getSampleValue(e)}return[t]},e.prototype.getMockSignature=function(){return this.ref?y[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=null;if("undefined"==typeof t||0==Object.keys(t).length)for(s in this.authz)r=this.authz[s],i=r.apply(e,t),i===!0&&(n=!0);else if(Array.isArray(t))for(var a=0;a0?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};l.prototype.sort=function(){},f.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},f.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 d(r,s[r])}return"array"===t.type?new e(t):null},f.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}},f.prototype["do"]=function(e,t,s,r,i){return this.execute(e,t,s,r,i)},f.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=this.getHeaderParams(o);l=this.setContentTypes(o,p);{var f=this.getBody(l,o),d=this.urlify(o),c={url:d,method:this.method.toUpperCase(),body:f,useJQuery:this.useJQuery,headers:l,on:{response:function(e){return n(e,i)},error:function(e){return a(e,i)}}};O.authorizations.apply(c,this.operation.security)}return p.mock===!0?c:void(new x).execute(c)},f.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},f.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)},f.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 d=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 c(n,p,o))}};d.prototype.createJSONSample=function(e){var t={};e=e||{},e[this.name]=this;var s;for(s=0;s"+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(r?t=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 m={},y={};h.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 g(e,this),this.apis[a]=s,this.apisArray.push(s)}else{var o;for(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 g(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.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 v=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 b(s,t.properties[s],this);this.properties.push(i)}};v.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},v.prototype.createJSONSample=function(e){if(m[this.name])return m[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 w=function(e,t,s,r,i,n,p,u,h,l,f,d,c){var m=this,y=[];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="string"==typeof c?Boolean(c):c,this["do"]=a(this["do"],this),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},w.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()},w.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:null!=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}},w.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=[],null!=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("/")},w.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 null!=o&&o.length>0&&(i+="?"+o),i},w.prototype.supportHeaderParams=function(){return this.resource.api.supportHeaderParams},w.prototype.supportedSubmitMethods=function(){return this.resource.api.supportedSubmitMethods},w.prototype.getQueryParams=function(e){return this.getMatchingParams(["query"],e)},w.prototype.getHeaderParams=function(e){return this.getMatchingParams(["header"],e)},w.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 S=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 x=function(){};x.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 C).execute(e)},x.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||{}}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 C=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)};C.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},C.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})},C.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 O="undefined"!=typeof window?window:exports;O.authorizations=new t,O.ApiKeyAuthorization=s,O.PasswordAuthorization=n,O.CookieAuthorization=i,O.SwaggerClient=h,O.Operation=f,O.Model=d,O.models=y}(); \ No newline at end of file diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index 3782865db..2ab9bdb15 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -520,9 +520,7 @@ Operation.prototype.getHeaderParams = function (args) { if (param.in === 'header') { var value = args[param.name]; if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); + value = value.toString(); headers[param.name] = value; } } diff --git a/test/headers.js b/test/headers.js index 699e9b2e0..226a7267a 100644 --- a/test/headers.js +++ b/test/headers.js @@ -23,6 +23,50 @@ describe('header extraction', function() { expect(headers.myHeader).toBe('tony'); }); + + it('should not URL encode header string values', function() { + var parameters = [ + { + in: 'header', + name: 'myHeader', + type: 'string' + } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters }); + var args = { + myHeader: 'someKey=someValue' + }; + + var url = op.urlify(args); + var headers = op.getHeaderParams(args); + + expect(url).toBe('http://localhost/path'); + expect(headers.myHeader).toBe('someKey=someValue'); + }); + + it('should not URL encode header string array values', function() { + var parameters = [ + { + in: 'header', + name: 'myHeader', + type: 'array', + items: { + type: 'string' + } + } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters }); + var args = { + myHeader: ['firstParam=firstValue', 'secondParam=secondValue'] + }; + + var url = op.urlify(args); + var headers = op.getHeaderParams(args); + + expect(url).toBe('http://localhost/path'); + expect(headers.myHeader).toBe('firstParam=firstValue,secondParam=secondValue'); + }); + it('should extract header params with string array with default collectionFormat', function() { var parameters = [ {