diff --git a/lib/swagger-client.js b/lib/swagger-client.js index b895541ae..ff5588154 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -578,6 +578,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de this.description = args.description; this.useJQuery = parent.useJQuery; + if(typeof this.deprecated === 'string') { + switch(this.deprecated.toLowerCase()) { + case 'true': case 'yes': case '1': { + this.deprecated = true; + break; + } + case 'false': case 'no': case '0': case null: { + this.deprecated = false; + break; + } + default: this.deprecated = Boolean(this.deprecated); + } + } + if(definitions) { // add to global models var key; @@ -810,9 +824,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; } } @@ -1683,6 +1695,7 @@ var SwaggerResource = function (resourceObj, api) { this.description = resourceObj.description; this.authorizations = (resourceObj.authorizations || {}); + var parts = this.path.split('/'); this.name = parts[parts.length - 1].replace('.{format}', ''); this.basePath = this.api.basePath; @@ -1761,7 +1774,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) { this.consumes = response.consumes; if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0) this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath; - + this.resourcePath = response.resourcePath; this.addModels(response.models); if (response.apis) { for (var i = 0 ; i < response.apis.length; i++) { @@ -2040,9 +2053,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no this.consumes = consumes; this.produces = produces; this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations; - this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated); + this.deprecated = deprecated; this['do'] = __bind(this['do'], this); + if(typeof this.deprecated === 'string') { + switch(this.deprecated.toLowerCase()) { + case 'true': case 'yes': case '1': { + this.deprecated = true; + break; + } + case 'false': case 'no': case '0': case null: { + this.deprecated = false; + break; + } + default: this.deprecated = Boolean(this.deprecated); + } + } + if (errors.length > 0) { console.error('SwaggerOperation errors', errors, arguments); this.resource.api.fail(errors); diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js index cf932b523..d5d8557b8 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 r=simpleRef(this.ref);if("undefined"!=typeof e[r])return r;e[r]=this,t=y[r].createJSONSample(e)}return[t]},e.prototype.getSampleValue=function(e){var t;if(e=e||{},this.type)t=type;else if(this.ref){var r=simpleRef(this.ref);t=y[r].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 r,s,i,n=null;if("undefined"==typeof t||0==Object.keys(t).length)for(r in this.authz)s=this.authz[r],i=s.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,r){this.name=e,this.username=t,this.password=r,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 r=t||0,s=this.length;s>r;r++)if(this[r]===e)return r;return-1});var o=function(e,t){var r="undefined"!=typeof window?window:exports;return r.parameterMacro?r.parameterMacro(e,t):t.defaultValue},p=function(e,t){var r="undefined"!=typeof window?window:exports;return r.modelPropertyMacro?r.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,r,s=[];for(t=0;t"+s.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,r=e.type,s=e.format,i=!1;"integer"===r&&"int32"===s?t="integer":"integer"===r&&"int64"===s?t="long":"integer"===r?t="integer":"string"===r&&"date-time"===s?t="date-time":"string"===r&&"date"===s?t="date":"number"===r&&"float"===s?t="float":"number"===r&&"double"===s?t="double":"number"===r?t="double":"boolean"===r?t="boolean":"string"===r?t="string":"array"===r&&(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,r){if("undefined"!=typeof t.$ref){var s=t.$ref;if(0===s.indexOf("#/definitions/")&&(s=s.substring("#/definitions/".length)),r[s])return new d(s,r[s])}return"array"===t.type?new e(t):null},f.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",r=0;r0&&(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,r,s,i){return this.execute(e,t,r,s,i)},f.prototype.execute=function(e,t,r,s,i){var n,a,o=e||{},p={};"object"==typeof t&&(p=t,n=r,a=s),"function"==typeof t&&(n=t,a=r),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),f=this.setContentTypes(o,p),d={};for(var c in l)d[c]=l[c];for(var c in f)d[c]=f[c];{var m=this.getBody(d,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:d,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 x).execute(g)},f.prototype.setContentTypes=function(e,t){var r,s,i="application/json",n=e.parameterContentType||"application/json",a=this.parameters,o=[],p=[],u={};for(s=0;s0?n=t.requestContentType?t.requestContentType:p.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"==this.type?r="{}":"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&&""!==r||"application/x-www-form-urlencoded"===n)&&(u["Content-Type"]=n),i&&(u.Accept=i),u},f.prototype.asCurl=function(e){var t=[],r=this.getHeaderParams(e);if(r){var s;for(s in r)t.push('--header "'+s+": "+r[s]+'"')}return"curl "+t.join(" ")+" "+this.urlify(e)},f.prototype.encodePathCollection=function(e,t,r){var s,i="",n="";for(n="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",s=0;s0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(r[s]);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(s=0;ss;s++)t.push(encodeURIComponent(r[s]));return t.join("/")};var d=function(t,r){this.name=t,this.definition=r||{},this.properties=[];var s=r.required||[];if("array"===r.type){var i=new e(r);return i}var n,a=r.properties;if(a)for(n in a){var o=!1,p=a[n];s.indexOf(n)>=0&&(o=!0),this.properties.push(new c(n,p,o))}};d.prototype.createJSONSample=function(e){var t,r={};for(e=e||{},e[this.name]=this,t=0;t"+s.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,r="",s="array"===this.schema.type;switch(s?t=this.schema.items?this.schema.items.type:"":this.schema.type,this["default"]&&(r+=optionHtml("Default",this["default"])),t){case"string":this.minLength&&(r+=optionHtml("Min. Length",this.minLength)),this.maxLength&&(r+=optionHtml("Max. Length",this.maxLength)),this.pattern&&(r+=optionHtml("Reg. Exp.",this.pattern));break;case"integer":case"number":this.minimum&&(r+=optionHtml("Min. Value",this.minimum)),this.exclusiveMinimum&&(r+=optionHtml("Exclusive Min.","true")),this.maximum&&(r+=optionHtml("Max. Value",this.maximum)),this.exclusiveMaximum&&(r+=optionHtml("Exclusive Max.","true")),this.multipleOf&&(r+=optionHtml("Multiple Of",this.multipleOf))}if(s&&(this.minItems&&(r+=optionHtml("Min. Items",this.minItems)),this.maxItems&&(r+=optionHtml("Max. Items",this.maxItems)),this.uniqueItems&&(r+=optionHtml("Unique Items","true")),this.collectionFormat&&(r+=optionHtml("Coll. Format",this.collectionFormat))),this["enum"]){var i;i="number"===t||"integer"===t?this["enum"].join(", "):'"'+this["enum"].join('", "')+'"',r+=optionHtml("Enum",i)}return r.length>0&&(e=''+e+'"+r+"
'+this.name+"
"),e},optionHtml=function(e,t){return''+e+":"+t+""},typeFromJsonSchema=function(e,t){var r;return"integer"===e&&"int32"===t?r="integer":"integer"===e&&"int64"===t?r="long":"integer"===e&&"undefined"==typeof t?r="long":"string"===e&&"date-time"===t?r="date-time":"string"===e&&"date"===t?r="date":"number"===e&&"float"===t?r="float":"number"===e&&"double"===t?r="double":"number"===e&&"undefined"==typeof t?r="double":"boolean"===e?r="boolean":"string"===e&&(r="string"),r};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,r,s=!1;for(t=0;t0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,s){var a=e.resourcePath.replace(/\//g,"");this.resourcePath=e.resourcePath,r=new g(e,this),this.apis[a]=r,this.apisArray.push(r)}else{var o;for(o=0;o0?this.url.substring(0,this.url.lastIndexOf("?")):this.url,r){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 r;for(r in t.properties){if(t.required){var s;for(s in t.required)r===t.required[s]&&(t.properties[r].required=!0)}var i=new b(r,t.properties[r],this);this.properties.push(i)}};v.prototype.setReferencedModels=function(e){for(var t=[],r=0;r"+s.join(",
")+"
"+o;for(e||(e=[]),e.push(this.name),t=0;t"+r.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 r=0;r'+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,r,s,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=r||y.push("SwaggerOperation "+e+" is missing method."),this.parameters=s?s:[],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 r,s;return s=this.isListType(e),r="undefined"!=typeof s&&t[s]||"undefined"!=typeof t[e]?!1:!0,r?e:"undefined"!=typeof s?t[s].getMockSignature():t[e].getMockSignature()},w.prototype.getSampleJSON=function(e,t){var r,s,i;if(s=this.isListType(e),r="undefined"!=typeof s&&t[s]||"undefined"!=typeof t[e]?!1:!0,i=r?void 0:null!=s?t[s].createJSONSample():t[e].createJSONSample()){if(i=s?[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,r,s){var i,n,a,o,p,u=[];"function"!=typeof s&&(s=function(e,t,r){return log(e,t,r)}),"function"!=typeof r&&(r=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++)r=s[i],t.push(encodeURIComponent(r));return t.join("/")},w.prototype.urlify=function(e){var t,r,s,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(s[r]);o+=encodeURIComponent(s.name)+"="+p}else if("undefined"!=typeof e[s.name])o+=encodeURIComponent(s.name)+"="+encodeURIComponent(e[s.name]);else if(s.required)throw""+s.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 r={},s=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,r="",n=e.split("\n"),s=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="",s+=u[t],o=function(){var e,t,r;for(r=[],n=e=0,t=s;t>=0?t>e:e>t;n=t>=0?++e:--e)r.push(" ");return r}().join(""),"opening->closing"===t?r=r.substr(0,r.length-1)+e+"\n":r+=o+e+"\n"},f=0,d=n.length;d>f;f++)a=n[f],l(a);return r};var S=function(e,t,r,s,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=r,this.opts=s,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=r.headers||{},u.length>0)throw u;this.type=this.type.toUpperCase();var h=this.setHeaders(r,s,this.operation),l=r.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&&r.produces&&-1===r.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,r=e;return e.type=e.method,e.cache=!1,e.beforeSend=function(t){var r,s;if(e.headers){s=[];for(r in e.headers)s.push("content-type"===r.toLowerCase()?e.contentType=e.headers[r]:"accept"===r.toLowerCase()?e.accepts=e.headers[r]:t.setRequestHeader(r,e.headers[r]));return s}},e.data=e.body,e.complete=function(e){for(var s={},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,r=e.on,s=function(e){var t={headers:e._headers,url:e.request.url,method:e.request.method,status:e.status,data:e.content.data},r=e._headers.normalized||e._headers,s=r["content-type"]||r["Content-Type"]||null;if(s&&(0===s.indexOf("application/json")||s.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?r.error(s(t)):void 0},request_error:function(t){return e?r.error(i(t)):void 0},response:function(t){return e?r.response(s(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);if("undefined"!=typeof e[s])return s;e[s]=this,t=y[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=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),f=this.setContentTypes(o,p),d={};for(var c in l)d[c]=l[c];for(var c in f)d[c]=f[c];{var m=this.getBody(d,o),y=this.urlify(o),g={url:y,method:this.method.toUpperCase(),body:m,useJQuery:this.useJQuery,headers:d,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 x).execute(g)},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,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(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.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 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=[];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},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 diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js index 706a89043..8e9455091 100644 --- a/src/js/swagger-a.js +++ b/src/js/swagger-a.js @@ -296,6 +296,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de this.description = args.description; this.useJQuery = parent.useJQuery; + if(typeof this.deprecated === 'string') { + switch(this.deprecated.toLowerCase()) { + case 'true': case 'yes': case '1': { + this.deprecated = true; + break; + } + case 'false': case 'no': case '0': case null: { + this.deprecated = false; + break; + } + default: this.deprecated = Boolean(this.deprecated); + } + } + if(definitions) { // add to global models var key; @@ -528,9 +542,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/src/js/swagger-compat.js b/src/js/swagger-compat.js index 288a646c4..651e77dd8 100644 --- a/src/js/swagger-compat.js +++ b/src/js/swagger-compat.js @@ -161,6 +161,7 @@ var SwaggerResource = function (resourceObj, api) { this.description = resourceObj.description; this.authorizations = (resourceObj.authorizations || {}); + var parts = this.path.split('/'); this.name = parts[parts.length - 1].replace('.{format}', ''); this.basePath = this.api.basePath; @@ -239,7 +240,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) { this.consumes = response.consumes; if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0) this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath; - + this.resourcePath = response.resourcePath; this.addModels(response.models); if (response.apis) { for (var i = 0 ; i < response.apis.length; i++) { @@ -518,9 +519,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no this.consumes = consumes; this.produces = produces; this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations; - this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated); + this.deprecated = deprecated; this['do'] = __bind(this['do'], this); + if(typeof this.deprecated === 'string') { + switch(this.deprecated.toLowerCase()) { + case 'true': case 'yes': case '1': { + this.deprecated = true; + break; + } + case 'false': case 'no': case '0': case null: { + this.deprecated = false; + break; + } + default: this.deprecated = Boolean(this.deprecated); + } + } + if (errors.length > 0) { console.error('SwaggerOperation errors', errors, arguments); this.resource.api.fail(errors); diff --git a/test/compat/request.js b/test/compat/request.js index a93b4d73d..7728ad21a 100644 --- a/test/compat/request.js +++ b/test/compat/request.js @@ -45,7 +45,6 @@ describe('request operations', function() { it('generate a get request', function() { var petApi = sample.pet; var req = petApi.getPetById({petId: 1}, {mock: true}); - expect(petApi.operations.getPetById.deprecated).toBe(true); }); 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 = [ { diff --git a/test/operation.js b/test/operation.js index 354a812f7..f36a960b7 100644 --- a/test/operation.js +++ b/test/operation.js @@ -248,6 +248,38 @@ describe('operations', function() { var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters }); expect(op.parameters[0].signature).toEqual('Array[date-time]'); }); + + it('should process the deprecated flag as boolean true', function() { + var parameters = [ + { in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: true }); + expect(op.deprecated).toEqual(true); + }); + + it('should process the deprecated flag as boolean false', function() { + var parameters = [ + { in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: false }); + expect(op.deprecated).toEqual(false); + }); + + it('should process the deprecated flag as string true', function() { + var parameters = [ + { in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'true' }); + expect(op.deprecated).toEqual(true); + }); + + it('should process the deprecated flag as string false', function() { + var parameters = [ + { in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} } + ]; + var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'false' }); + expect(op.deprecated).toEqual(false); + }); }); var quantityQP = {