diff --git a/gulpfile.js b/gulpfile.js
index 8799d5697..c6ce10d67 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -21,7 +21,7 @@ var banner = ['/**',
var basename = 'swagger-client';
var paths = {
sources: ['src/js/*.js'],
- tests: ['test/*.js'],
+ tests: ['test/*.js', 'test/compat/*.js'],
dist: 'lib'
};
diff --git a/lib/swagger-client.js b/lib/swagger-client.js
index eac794f11..02a283d96 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.2-M1
+ * @version v2.1.3-M1
* @link http://swagger.io
* @license apache 2.0
*/
@@ -82,10 +82,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
var status = null;
- var key, value, result;
+ var key, name, value, result;
// if the "authorizations" key is undefined, or has an empty array, add all keys
- if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
+ if (typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
for (key in this.authz) {
value = this.authz[key];
result = value.apply(obj, authorizations);
@@ -280,6 +280,10 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) {
}
return returnVal;
};
+var addModel = function(name, model) {
+ models[name] = model;
+};
+
var SwaggerClient = function(url, options) {
this.isBuilt = false;
this.url = null;
@@ -291,13 +295,14 @@ var SwaggerClient = function(url, options) {
this.isValid = false;
this.info = null;
this.useJQuery = false;
+ this.resourceCount = 0;
if(typeof url !== 'undefined')
return this.initialize(url, options);
};
SwaggerClient.prototype.initialize = function (url, options) {
- this.models = models;
+ this.models = models = {};
options = (options||{});
@@ -386,7 +391,6 @@ SwaggerClient.prototype.build = function(mock) {
return obj;
new SwaggerHttp().execute(obj);
}
-
return this;
};
@@ -502,8 +506,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
}
}
this.isBuilt = true;
- if (this.success)
+ if (this.success) {
+ this.isValid = true;
+ this.isBuilt = true;
this.success();
+ }
return this;
};
@@ -592,18 +599,18 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
}
}
+ var i, model;
+
if(definitions) {
// add to global models
var key;
for(key in this.definitions) {
- var model = new Model(key, definitions[key]);
+ model = new Model(key, definitions[key]);
if(model) {
models[key] = model;
}
}
}
-
- var i;
for(i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
if(param.type === 'array') {
@@ -641,7 +648,7 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.responseClassSignature = param.signature;
}
- var defaultResponseCode, response, model, responses = this.responses;
+ var defaultResponseCode, response, responses = this.responses;
if(responses['200']) {
response = responses['200'];
@@ -995,9 +1002,9 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
var allHeaders = this.getHeaderParams(args);
var contentTypeHeaders = this.setContentTypes(args, opts);
- var headers = {};
- for (var attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
- for (var attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
+ var headers = {}, attrname;
+ for (attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
+ for (attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
var body = this.getBody(headers, args);
var url = this.urlify(args);
@@ -1439,7 +1446,7 @@ Property.prototype.toString = function() {
type = '';
}
else {
- this.schema.type;
+ type = this.schema.type;
}
if (this.default)
@@ -1500,7 +1507,7 @@ Property.prototype.toString = function() {
optionHtml = function(label, value) {
return '
| ' + label + ': | ' + value + ' |
';
-}
+};
typeFromJsonSchema = function(type, format) {
var str;
@@ -1533,7 +1540,7 @@ var cookies = {};
var models = {};
SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
- if (response.apiVersion != null) {
+ if (response.apiVersion !== null) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
@@ -1569,6 +1576,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
this.apisArray.push(res);
} else {
var k;
+ this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
var resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -1577,15 +1585,21 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
}
}
this.isValid = true;
+ return this;
+};
+
+SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
+ this.isValid = true;
+ this.isBuilt = true;
+ this.selfReflect();
this.success();
- }
- return this;
+ }
};
SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info');
- if (response.apiVersion != null)
+ if (response.apiVersion !== null)
this.apiVersion = response.apiVersion;
this.apis = {};
this.apisArray = [];
@@ -1631,7 +1645,7 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
SwaggerClient.prototype.convertInfo = function (resp) {
if(typeof resp == 'object') {
- var info = {}
+ var info = {};
info.title = resp.title;
info.description = resp.description;
@@ -1660,9 +1674,6 @@ SwaggerClient.prototype.selfReflect = function () {
}
this.setConsolidatedModels();
this.ready = true;
- if (typeof this.success === 'function') {
- return this.success();
- }
};
SwaggerClient.prototype.setConsolidatedModels = function () {
@@ -1702,7 +1713,7 @@ var SwaggerResource = function (resourceObj, api) {
this.operations = {};
this.operationsArray = [];
this.modelsArray = [];
- this.models = {};
+ this.models = api.models || {};
this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null;
@@ -1728,9 +1739,11 @@ var SwaggerResource = function (resourceObj, api) {
on: {
response: function (resp) {
var responseObj = resp.obj || JSON.parse(resp.data);
+ _this.api.resourceCount += 1;
return _this.addApiDeclaration(responseObj);
},
error: function (response) {
+ _this.api.resourceCount += 1;
return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
}
@@ -1784,7 +1797,9 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
}
this.api[this.name] = this;
this.ready = true;
- return this.api.selfReflect();
+ if(this.api.resourceCount === this.api.expectedResourceCount)
+ this.api.finish();
+ return this;
};
SwaggerResource.prototype.addModels = function (models) {
@@ -2077,7 +2092,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.path = this.path.replace('{format}', 'json');
this.method = this.method.toLowerCase();
- this.isGetMethod = this.method === 'GET';
+ this.isGetMethod = this.method === 'get';
var i, j, v;
this.resourceName = this.resource.name;
@@ -2128,17 +2143,17 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
}
}
}
- else if (param.allowableValues != null) {
+ else if (param.allowableValues) {
if (param.allowableValues.valueType === 'RANGE')
param.isRange = true;
else
param.isList = true;
- if (param.allowableValues != null) {
+ if (param.allowableValues) {
param.allowableValues.descriptiveValues = [];
if (param.allowableValues.values) {
for (j = 0; j < param.allowableValues.values.length; j++) {
v = param.allowableValues.values[j];
- if (param.defaultValue != null) {
+ if (param.defaultValue !== null) {
param.allowableValues.descriptiveValues.push({
value: String(v),
isDefault: (v === param.defaultValue)
@@ -2208,7 +2223,7 @@ SwaggerOperation.prototype.getSampleJSON = function (type, models) {
var isPrimitive, listType, val;
listType = this.isListType(type);
isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true;
- val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
+ val = isPrimitive ? void 0 : (listType ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) {
val = listType ? [val] : val;
if (typeof val == 'string')
@@ -2243,7 +2258,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
callback = function (response) {
var content;
content = null;
- if (response != null) {
+ if (response !== null) {
content = response.data;
} else {
content = 'no data';
@@ -2254,7 +2269,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
params = {};
params.headers = [];
- if (args.headers != null) {
+ if (args.headers) {
params.headers = args.headers;
delete args.headers;
}
@@ -2375,7 +2390,7 @@ SwaggerOperation.prototype.urlify = function (args) {
}
}
}
- if ((queryParams != null) && queryParams.length > 0)
+ if ((queryParams) && queryParams.length > 0)
url += '?' + queryParams;
return url;
};
@@ -2584,7 +2599,7 @@ var SwaggerRequest = function (type, url, params, opts, successCallback, errorCa
}
var obj;
- if (!((this.headers != null) && (this.headers.mock != null))) {
+ if (!((this.headers) && (this.headers.mock))) {
obj = {
url: this.url,
method: this.type,
@@ -2953,7 +2968,9 @@ e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization;
e.SwaggerClient = SwaggerClient;
+e.SwaggerApi = SwaggerClient;
e.Operation = Operation;
e.Model = Model;
-e.models = models;
+e.addModel = addModel;
+
})();
\ No newline at end of file
diff --git a/lib/swagger-client.min.js b/lib/swagger-client.min.js
index d5d8557b8..73a2cf8a4 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=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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t"+h.getMockSignature(e))}return p};var h=function(e,t){return this.isBuilt=!1,this.url=null,this.debug=!1,this.basePath=null,this.modelsArray=[],this.authorizations=null,this.authorizationScheme=null,this.isValid=!1,this.info=null,this.useJQuery=!1,"undefined"!=typeof e?this.initialize(e,t):void 0};h.prototype.initialize=function(e,t){if(this.models=y,t=t||{},"string"==typeof e?this.url=e:"object"==typeof e&&(t=e,this.url=t.url),this.swaggerRequstHeaders=t.swaggerRequstHeaders||"application/json;charset=utf-8,*/*",this.defaultSuccessCallback=t.defaultSuccessCallback||null,this.defaultErrorCallback=t.defaultErrorCallback||null,"function"==typeof t.success&&(this.success=t.success),t.useJQuery&&(this.useJQuery=t.useJQuery),t.authorizations)this.clientAuthorizations=t.authorizations;else{var s="undefined"!=typeof window?window:exports;this.clientAuthorizations=s.authorizations}this.supportedSubmitMethods=t.supportedSubmitMethods||[],this.failure=t.failure||function(){},this.progress=t.progress||function(){},this.spec=t.spec,this.options=t,"function"==typeof t.success&&this.build()},h.prototype.build=function(e){if(this.isBuilt)return this;var t=this;this.progress("fetching resource list: "+this.url);var s={useJQuery:this.useJQuery,url:this.url,method:"get",headers:{accept:this.swaggerRequstHeaders},on:{error:function(e){return t.fail("http"!==t.url.substring(0,4)?"Please specify the protocol for "+t.url:0===e.status?"Can't read from server. It may not have the appropriate access-control-origin settings.":404===e.status?"Can't read swagger JSON from "+t.url:e.status+" : "+e.statusText+" "+t.url)},response:function(e){var s=e.obj||JSON.parse(e.data);return t.swaggerVersion=s.swaggerVersion,s.swagger&&2===parseInt(s.swagger)?(t.swaggerVersion=s.swagger,t.buildFromSpec(s),t.isValid=!0,void 0):"1.2"===t.swaggerVersion?t.buildFrom1_2Spec(s):t.buildFrom1_1Spec(s)}}};if(this.spec)setTimeout(function(){t.buildFromSpec(t.spec)},10);else{{var r="undefined"!=typeof window?window:exports;r.authorizations.apply(s)}if(e)return s;(new x).execute(s)}return this},h.prototype.buildFromSpec=function(e){if(this.isBuilt)return this;this.info=e.info||{},this.title=e.title||"",this.host=e.host||"",this.schemes=e.schemes||[],this.basePath=e.basePath||"",this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.securityDefinitions=e.securityDefinitions,this.authSchemes=e.securityDefinitions;var t;"string"==typeof this.url&&(t=this.parseUri(this.url)),this.scheme="undefined"==typeof this.schemes||0===this.schemes.length?t.scheme||"http":this.schemes[0],("undefined"==typeof this.host||""===this.host)&&(this.host=t.host,t.port&&(this.host=this.host+":"+t.port)),this.definitions=e.definitions;var s;for(s in this.definitions){var r=new d(s,this.definitions[s]);r&&(y[s]=r)}var i;for(i in e.paths)if("object"==typeof e.paths[i]){var n;for(n in e.paths[i])if(-1!==["delete","get","head","options","patch","post","put"].indexOf(n)){var a=e.paths[i][n],o=a.tags;"undefined"==typeof o&&(a.tags=["default"],o=a.tags);var p=this.idFromOp(i,n,a),u=new f(this,a.scheme,p,n,i,a,this.definitions);if(o.length>0){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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t"+h.getMockSignature(e))}return p};var c=function(e,t,s){this.schema=t,this.required=s,t.$ref?this.$ref=simpleRef(t.$ref):"array"===t.type&&t.items&&(t.items.$ref?this.$ref=simpleRef(t.items.$ref):t=t.items),this.name=e,this.description=t.description,this.obj=t,this.optional=!0,this.optional=!s,this["default"]=t["default"]||null,this.example=t.example||null,this.collectionFormat=t.collectionFormat||null,this.maximum=t.maximum||null,this.exclusiveMaximum=t.exclusiveMaximum||null,this.minimum=t.minimum||null,this.exclusiveMinimum=t.exclusiveMinimum||null,this.maxLength=t.maxLength||null,this.minLength=t.minLength||null,this.pattern=t.pattern||null,this.maxItems=t.maxItems||null,this.minItems=t.minItems||null,this.uniqueItems=t.uniqueItems||null,this["enum"]=t["enum"]||null,this.multipleOf=t.multipleOf||null};c.prototype.getSampleValue=function(e){return this.sampleValue(!1,e)},c.prototype.isArray=function(){var e=this.schema;return"array"===e.type?!0:!1},c.prototype.sampleValue=function(e,t){e=e||this.isArray(),t=t||{};var s,r=getStringSignature(this.obj,!0);if(this.$ref){var i=simpleRef(this.$ref),n=y[i];n&&"undefined"==typeof t[r]?(t[r]=this,s=n.getSampleValue(t)):s=i}else s=this.example?this.example:this["default"]?this["default"]:"date-time"===r?(new Date).toISOString():"date"===r?(new Date).toISOString().split("T")[0]:"string"===r?"string":"integer"===r?0:"long"===r?0:"float"===r?0:"double"===r?0:"boolean"===r?!0:{};return t[r]=s,e?[s]:s},getStringSignature=function(e,t){var s="";return"undefined"!=typeof e.$ref?s+=simpleRef(e.$ref):"undefined"==typeof e.type?s+="object":"array"===e.type?t?s+=getStringSignature(e.items||e.$ref||{}):(s+="Array[",s+=getStringSignature(e.items||e.$ref||{}),s+="]"):s+="integer"===e.type&&"int32"===e.format?"integer":"integer"===e.type&&"int64"===e.format?"long":"integer"===e.type&&"undefined"==typeof e.format?"long":"string"===e.type&&"date-time"===e.format?"date-time":"string"===e.type&&"date"===e.format?"date":"string"===e.type&&"undefined"==typeof e.format?"string":"number"===e.type&&"float"===e.format?"float":"number"===e.type&&"double"===e.format?"double":"number"===e.type&&"undefined"==typeof e.format?"double":"boolean"===e.type?"boolean":e.$ref?simpleRef(e.$ref):e.type,s},simpleRef=function(e){return"undefined"==typeof e?null:0===e.indexOf("#/definitions/")?e.substring("#/definitions/".length):e},c.prototype.toString=function(){var e=getStringSignature(this.obj);""!==e?(e=''+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+'"),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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+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
+!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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t"+h.getMockSignature(e))}return p};var h=function(e,t){g[e]=t},l=function(e,t){return this.isBuilt=!1,this.url=null,this.debug=!1,this.basePath=null,this.modelsArray=[],this.authorizations=null,this.authorizationScheme=null,this.isValid=!1,this.info=null,this.useJQuery=!1,this.resourceCount=0,"undefined"!=typeof e?this.initialize(e,t):void 0};l.prototype.initialize=function(e,t){if(this.models=g={},t=t||{},"string"==typeof e?this.url=e:"object"==typeof e&&(t=e,this.url=t.url),this.swaggerRequstHeaders=t.swaggerRequstHeaders||"application/json;charset=utf-8,*/*",this.defaultSuccessCallback=t.defaultSuccessCallback||null,this.defaultErrorCallback=t.defaultErrorCallback||null,"function"==typeof t.success&&(this.success=t.success),t.useJQuery&&(this.useJQuery=t.useJQuery),t.authorizations)this.clientAuthorizations=t.authorizations;else{var s="undefined"!=typeof window?window:exports;this.clientAuthorizations=s.authorizations}this.supportedSubmitMethods=t.supportedSubmitMethods||[],this.failure=t.failure||function(){},this.progress=t.progress||function(){},this.spec=t.spec,this.options=t,"function"==typeof t.success&&this.build()},l.prototype.build=function(e){if(this.isBuilt)return this;var t=this;this.progress("fetching resource list: "+this.url);var s={useJQuery:this.useJQuery,url:this.url,method:"get",headers:{accept:this.swaggerRequstHeaders},on:{error:function(e){return t.fail("http"!==t.url.substring(0,4)?"Please specify the protocol for "+t.url:0===e.status?"Can't read from server. It may not have the appropriate access-control-origin settings.":404===e.status?"Can't read swagger JSON from "+t.url:e.status+" : "+e.statusText+" "+t.url)},response:function(e){var s=e.obj||JSON.parse(e.data);return t.swaggerVersion=s.swaggerVersion,s.swagger&&2===parseInt(s.swagger)?(t.swaggerVersion=s.swagger,t.buildFromSpec(s),t.isValid=!0,void 0):"1.2"===t.swaggerVersion?t.buildFrom1_2Spec(s):t.buildFrom1_1Spec(s)}}};if(this.spec)setTimeout(function(){t.buildFromSpec(t.spec)},10);else{{var r="undefined"!=typeof window?window:exports;r.authorizations.apply(s)}if(e)return s;(new C).execute(s)}return this},l.prototype.buildFromSpec=function(e){if(this.isBuilt)return this;this.info=e.info||{},this.title=e.title||"",this.host=e.host||"",this.schemes=e.schemes||[],this.basePath=e.basePath||"",this.apis={},this.apisArray=[],this.consumes=e.consumes,this.produces=e.produces,this.securityDefinitions=e.securityDefinitions,this.authSchemes=e.securityDefinitions;var t;"string"==typeof this.url&&(t=this.parseUri(this.url)),this.scheme="undefined"==typeof this.schemes||0===this.schemes.length?t.scheme||"http":this.schemes[0],("undefined"==typeof this.host||""===this.host)&&(this.host=t.host,t.port&&(this.host=this.host+":"+t.port)),this.definitions=e.definitions;var s;for(s in this.definitions){var r=new c(s,this.definitions[s]);r&&(g[s]=r)}var i;for(i in e.paths)if("object"==typeof e.paths[i]){var n;for(n in e.paths[i])if(-1!==["delete","get","head","options","patch","post","put"].indexOf(n)){var a=e.paths[i][n],o=a.tags;"undefined"==typeof o&&(a.tags=["default"],o=a.tags);var p=this.idFromOp(i,n,a),u=new d(this,a.scheme,p,n,i,a,this.definitions);if(o.length>0){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)}}};O.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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+r.join(",
")+"
"+o;for(e||(e={}),e[this.name]=this,t=0;t"+h.getMockSignature(e))}return p};var m=function(e,t,s){this.schema=t,this.required=s,t.$ref?this.$ref=simpleRef(t.$ref):"array"===t.type&&t.items&&(t.items.$ref?this.$ref=simpleRef(t.items.$ref):t=t.items),this.name=e,this.description=t.description,this.obj=t,this.optional=!0,this.optional=!s,this["default"]=t["default"]||null,this.example=t.example||null,this.collectionFormat=t.collectionFormat||null,this.maximum=t.maximum||null,this.exclusiveMaximum=t.exclusiveMaximum||null,this.minimum=t.minimum||null,this.exclusiveMinimum=t.exclusiveMinimum||null,this.maxLength=t.maxLength||null,this.minLength=t.minLength||null,this.pattern=t.pattern||null,this.maxItems=t.maxItems||null,this.minItems=t.minItems||null,this.uniqueItems=t.uniqueItems||null,this["enum"]=t["enum"]||null,this.multipleOf=t.multipleOf||null};m.prototype.getSampleValue=function(e){return this.sampleValue(!1,e)},m.prototype.isArray=function(){var e=this.schema;return"array"===e.type?!0:!1},m.prototype.sampleValue=function(e,t){e=e||this.isArray(),t=t||{};var s,r=getStringSignature(this.obj,!0);if(this.$ref){var i=simpleRef(this.$ref),n=g[i];n&&"undefined"==typeof t[r]?(t[r]=this,s=n.getSampleValue(t)):s=i}else s=this.example?this.example:this["default"]?this["default"]:"date-time"===r?(new Date).toISOString():"date"===r?(new Date).toISOString().split("T")[0]:"string"===r?"string":"integer"===r?0:"long"===r?0:"float"===r?0:"double"===r?0:"boolean"===r?!0:{};return t[r]=s,e?[s]:s},getStringSignature=function(e,t){var s="";return"undefined"!=typeof e.$ref?s+=simpleRef(e.$ref):"undefined"==typeof e.type?s+="object":"array"===e.type?t?s+=getStringSignature(e.items||e.$ref||{}):(s+="Array[",s+=getStringSignature(e.items||e.$ref||{}),s+="]"):s+="integer"===e.type&&"int32"===e.format?"integer":"integer"===e.type&&"int64"===e.format?"long":"integer"===e.type&&"undefined"==typeof e.format?"long":"string"===e.type&&"date-time"===e.format?"date-time":"string"===e.type&&"date"===e.format?"date":"string"===e.type&&"undefined"==typeof e.format?"string":"number"===e.type&&"float"===e.format?"float":"number"===e.type&&"double"===e.format?"double":"number"===e.type&&"undefined"==typeof e.format?"double":"boolean"===e.type?"boolean":e.$ref?simpleRef(e.$ref):e.type,s},simpleRef=function(e){return"undefined"==typeof e?null:0===e.indexOf("#/definitions/")?e.substring("#/definitions/".length):e},m.prototype.toString=function(){var e=getStringSignature(this.obj);""!==e?(e=''+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+'"),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",a=i+this.name+" {"+n,o=i+"}"+n,p=a+""+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 P).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||{}}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 P=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)};P.prototype.initShred=function(){this.isInitialized=!0,this.registerProcessors(this.shred)},P.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})},P.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=l,O.SwaggerApi=l,O.Operation=d,O.Model=c,O.addModel=h}();
\ No newline at end of file
diff --git a/package.json b/package.json
index 9d36ca23c..d7683085e 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.2-M1",
+ "version": "2.1.3-M1",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
diff --git a/src/js/auth.js b/src/js/auth.js
index e5945a4e9..5454c54e0 100644
--- a/src/js/auth.js
+++ b/src/js/auth.js
@@ -17,10 +17,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
var status = null;
- var key, value, result;
+ var key, name, value, result;
// if the "authorizations" key is undefined, or has an empty array, add all keys
- if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
+ if (typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
for (key in this.authz) {
value = this.authz[key];
result = value.apply(obj, authorizations);
diff --git a/src/js/swagger-a.js b/src/js/swagger-a.js
index 8e9455091..4426ca533 100644
--- a/src/js/swagger-a.js
+++ b/src/js/swagger-a.js
@@ -1,3 +1,7 @@
+var addModel = function(name, model) {
+ models[name] = model;
+};
+
var SwaggerClient = function(url, options) {
this.isBuilt = false;
this.url = null;
@@ -9,13 +13,14 @@ var SwaggerClient = function(url, options) {
this.isValid = false;
this.info = null;
this.useJQuery = false;
+ this.resourceCount = 0;
if(typeof url !== 'undefined')
return this.initialize(url, options);
};
SwaggerClient.prototype.initialize = function (url, options) {
- this.models = models;
+ this.models = models = {};
options = (options||{});
@@ -104,7 +109,6 @@ SwaggerClient.prototype.build = function(mock) {
return obj;
new SwaggerHttp().execute(obj);
}
-
return this;
};
@@ -220,8 +224,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
}
}
this.isBuilt = true;
- if (this.success)
+ if (this.success) {
+ this.isValid = true;
+ this.isBuilt = true;
this.success();
+ }
return this;
};
@@ -310,18 +317,18 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
}
}
+ var i, model;
+
if(definitions) {
// add to global models
var key;
for(key in this.definitions) {
- var model = new Model(key, definitions[key]);
+ model = new Model(key, definitions[key]);
if(model) {
models[key] = model;
}
}
}
-
- var i;
for(i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
if(param.type === 'array') {
@@ -359,7 +366,7 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.responseClassSignature = param.signature;
}
- var defaultResponseCode, response, model, responses = this.responses;
+ var defaultResponseCode, response, responses = this.responses;
if(responses['200']) {
response = responses['200'];
@@ -713,9 +720,9 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
var allHeaders = this.getHeaderParams(args);
var contentTypeHeaders = this.setContentTypes(args, opts);
- var headers = {};
- for (var attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
- for (var attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
+ var headers = {}, attrname;
+ for (attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
+ for (attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
var body = this.getBody(headers, args);
var url = this.urlify(args);
@@ -1157,7 +1164,7 @@ Property.prototype.toString = function() {
type = '';
}
else {
- this.schema.type;
+ type = this.schema.type;
}
if (this.default)
@@ -1218,7 +1225,7 @@ Property.prototype.toString = function() {
optionHtml = function(label, value) {
return '| ' + label + ': | ' + value + ' |
';
-}
+};
typeFromJsonSchema = function(type, format) {
var str;
diff --git a/src/js/swagger-compat.js b/src/js/swagger-compat.js
index 651e77dd8..1045f1538 100644
--- a/src/js/swagger-compat.js
+++ b/src/js/swagger-compat.js
@@ -1,5 +1,5 @@
SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
- if (response.apiVersion != null) {
+ if (response.apiVersion !== null) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
@@ -35,6 +35,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
this.apisArray.push(res);
} else {
var k;
+ this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
var resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -43,15 +44,21 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
}
}
this.isValid = true;
+ return this;
+};
+
+SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
+ this.isValid = true;
+ this.isBuilt = true;
+ this.selfReflect();
this.success();
- }
- return this;
+ }
};
SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info');
- if (response.apiVersion != null)
+ if (response.apiVersion !== null)
this.apiVersion = response.apiVersion;
this.apis = {};
this.apisArray = [];
@@ -97,7 +104,7 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
SwaggerClient.prototype.convertInfo = function (resp) {
if(typeof resp == 'object') {
- var info = {}
+ var info = {};
info.title = resp.title;
info.description = resp.description;
@@ -126,9 +133,6 @@ SwaggerClient.prototype.selfReflect = function () {
}
this.setConsolidatedModels();
this.ready = true;
- if (typeof this.success === 'function') {
- return this.success();
- }
};
SwaggerClient.prototype.setConsolidatedModels = function () {
@@ -168,7 +172,7 @@ var SwaggerResource = function (resourceObj, api) {
this.operations = {};
this.operationsArray = [];
this.modelsArray = [];
- this.models = {};
+ this.models = api.models || {};
this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null;
@@ -194,9 +198,11 @@ var SwaggerResource = function (resourceObj, api) {
on: {
response: function (resp) {
var responseObj = resp.obj || JSON.parse(resp.data);
+ _this.api.resourceCount += 1;
return _this.addApiDeclaration(responseObj);
},
error: function (response) {
+ _this.api.resourceCount += 1;
return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
}
@@ -250,7 +256,9 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
}
this.api[this.name] = this;
this.ready = true;
- return this.api.selfReflect();
+ if(this.api.resourceCount === this.api.expectedResourceCount)
+ this.api.finish();
+ return this;
};
SwaggerResource.prototype.addModels = function (models) {
@@ -543,7 +551,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.path = this.path.replace('{format}', 'json');
this.method = this.method.toLowerCase();
- this.isGetMethod = this.method === 'GET';
+ this.isGetMethod = this.method === 'get';
var i, j, v;
this.resourceName = this.resource.name;
@@ -594,17 +602,17 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
}
}
}
- else if (param.allowableValues != null) {
+ else if (param.allowableValues) {
if (param.allowableValues.valueType === 'RANGE')
param.isRange = true;
else
param.isList = true;
- if (param.allowableValues != null) {
+ if (param.allowableValues) {
param.allowableValues.descriptiveValues = [];
if (param.allowableValues.values) {
for (j = 0; j < param.allowableValues.values.length; j++) {
v = param.allowableValues.values[j];
- if (param.defaultValue != null) {
+ if (param.defaultValue !== null) {
param.allowableValues.descriptiveValues.push({
value: String(v),
isDefault: (v === param.defaultValue)
@@ -674,7 +682,7 @@ SwaggerOperation.prototype.getSampleJSON = function (type, models) {
var isPrimitive, listType, val;
listType = this.isListType(type);
isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true;
- val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
+ val = isPrimitive ? void 0 : (listType ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) {
val = listType ? [val] : val;
if (typeof val == 'string')
@@ -709,7 +717,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
callback = function (response) {
var content;
content = null;
- if (response != null) {
+ if (response !== null) {
content = response.data;
} else {
content = 'no data';
@@ -720,7 +728,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
params = {};
params.headers = [];
- if (args.headers != null) {
+ if (args.headers) {
params.headers = args.headers;
delete args.headers;
}
@@ -841,7 +849,7 @@ SwaggerOperation.prototype.urlify = function (args) {
}
}
}
- if ((queryParams != null) && queryParams.length > 0)
+ if ((queryParams) && queryParams.length > 0)
url += '?' + queryParams;
return url;
};
@@ -1050,7 +1058,7 @@ var SwaggerRequest = function (type, url, params, opts, successCallback, errorCa
}
var obj;
- if (!((this.headers != null) && (this.headers.mock != null))) {
+ if (!((this.headers) && (this.headers.mock))) {
obj = {
url: this.url,
method: this.type,
diff --git a/src/js/zexports.js b/src/js/zexports.js
index 84e3d7352..c2ec0e772 100644
--- a/src/js/zexports.js
+++ b/src/js/zexports.js
@@ -6,6 +6,7 @@ e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization;
e.SwaggerClient = SwaggerClient;
+e.SwaggerApi = SwaggerClient;
e.Operation = Operation;
e.Model = Model;
-e.models = models;
\ No newline at end of file
+e.addModel = addModel;
diff --git a/test/auth.js b/test/auth.js
index 1b7bd9af6..099f58035 100644
--- a/test/auth.js
+++ b/test/auth.js
@@ -14,7 +14,6 @@ describe('2.0 authorizations', function() {
after(function(done){
instance.close();
-
swagger.authorizations.authz = {};
done();
});
@@ -50,7 +49,7 @@ describe('2.0 authorizations', function() {
var req = petApi.getPetById(params, opts);
expect(req.url).toBe('http://localhost:8000/v2/api/pet/1');
- expect(req.headers['api_key']).toBe('abc123');
+ expect(req.headers.api_key).toBe('abc123');
swagger.authorizations.authz = {};
});
diff --git a/test/compat/auth.js b/test/compat/auth.js
index 55066bb5e..dbef5b2fa 100644
--- a/test/compat/auth.js
+++ b/test/compat/auth.js
@@ -1,10 +1,10 @@
-var test = require('unit.js')
-var expect = require('expect')
+var test = require('unit.js');
+var expect = require('expect');
var mock = require('../../test/compat/mock');
var swagger = require('../../lib/swagger-client');
var sample, instance;
-describe('api key authorizations', function() {
+describe('1.2 api key authorizations', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -51,7 +51,7 @@ describe('api key authorizations', function() {
var req = petApi.getPetById(params, opts);
expect(req.url).toBe('http://localhost:8000/v1/api/pet/1');
- expect(req.headers['api_key']).toBe('abc123');
+ expect(req.headers.api_key).toBe('abc123');
swagger.authorizations.authz = {};
});
diff --git a/test/compat/defaultCallbacks.js b/test/compat/defaultCallbacks.js
index 723f76f3e..eac0b25f7 100644
--- a/test/compat/defaultCallbacks.js
+++ b/test/compat/defaultCallbacks.js
@@ -4,7 +4,7 @@ var mock = require('../../test/compat/mock');
var swagger = require('../../lib/swagger-client');
var sample, instance;
-describe('default success callback', function() {
+describe('1.2 default success callback', function() {
var opts = {};
var finished;
opts.defaultSuccessCallback = function(data) {
diff --git a/test/compat/http.js b/test/compat/http.js
index 02e9d95b8..b72f95f25 100644
--- a/test/compat/http.js
+++ b/test/compat/http.js
@@ -3,7 +3,7 @@ var expect = require('expect');
var mock = require('../../test/compat/mock');
var sample, instance;
-describe('http', function() {
+describe('1.2 http', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -62,10 +62,10 @@ describe('http', function() {
var petApi = sample.pet;
var success = function(data) {
done();
- }
+ };
var failure = function(data) {
done();
- }
+ };
var req = petApi.getPetById({petId: 0}, {responseContentType: 'invalid'}, success, failure);
});
@@ -73,10 +73,10 @@ describe('http', function() {
var petApi = sample.pet;
var success = function(data) {
fail();
- }
+ };
var failure = function(data) {
done();
- }
+ };
var req = petApi.getPetById({petId: 0}, success, failure);
});
});
diff --git a/test/compat/macros.js b/test/compat/macros.js
index 97c141e57..8614bc103 100644
--- a/test/compat/macros.js
+++ b/test/compat/macros.js
@@ -3,7 +3,7 @@ var expect = require('expect');
var mock = require('../../test/compat/mock');
var sample, instance;
-describe('macro overrides', function() {
+describe('1.2 macro overrides', function() {
before(function(done) {
var macros = {
parameter: function(operation, parameter) {
@@ -15,7 +15,7 @@ describe('macro overrides', function() {
modelProperty: function(model, property) {
return property.defaultValue;
}
- }
+ };
mock.petstore(done, function(petstore, server){
sample = petstore;
instance = server;
diff --git a/test/compat/mock.js b/test/compat/mock.js
index 9a053351a..e2131b3f8 100644
--- a/test/compat/mock.js
+++ b/test/compat/mock.js
@@ -8,9 +8,9 @@ var sample;
exports.swagger = swagger;
exports.petstore = function(arg1, arg2, arg3, arg4) {
- var done = arg1, opts = arg2, callback = arg3, macros = arg4;
+ var done = arg1, opts = arg2 || {}, callback = arg3, macros = arg4;
if(typeof arg2 === 'function') {
- opts = null;
+ opts = {};
callback = arg2;
macros = arg3;
}
@@ -28,7 +28,7 @@ exports.petstore = function(arg1, arg2, arg3, arg4) {
else {
fs.exists(filename, function(exists) {
if(exists) {
- var accept = req.headers['accept'];
+ var accept = req.headers.accept;
if(typeof accept !== 'undefined') {
if(accept === 'invalid') {
res.writeHead(500);
@@ -59,8 +59,6 @@ exports.petstore = function(arg1, arg2, arg3, arg4) {
}).listen(8000);
instance.on("listening", function() {
- var self = {}; self.stop = done;
-
if(macros) {
if(macros.parameter) {
console.log(' warn: set parameter macro');
@@ -71,17 +69,12 @@ exports.petstore = function(arg1, arg2, arg3, arg4) {
swagger.modelPropertyMacro = macros.modelProperty;
}
}
- var sample = new swagger.SwaggerClient('http://localhost:8000/v1/api-docs.json', opts);
- sample.build();
- var count = 0, isDone = false;
- var f = function () {
- if(!isDone) {
- isDone = true;
- self.stop();
- }
+ opts.success = function() {
+ done();
callback(sample, instance);
return;
};
- setTimeout(f, 50);
+ opts.url = 'http://localhost:8000/v1/api-docs.json';
+ var sample = new swagger.SwaggerClient(opts);
});
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/test/compat/modelSignatures.js b/test/compat/modelSignatures.js
index 4c1dd2ac8..d7ba6c356 100644
--- a/test/compat/modelSignatures.js
+++ b/test/compat/modelSignatures.js
@@ -1,9 +1,9 @@
-var test = require('unit.js')
-var expect = require('expect')
+var test = require('unit.js');
+var expect = require('expect');
var mock = require('../../test/compat/mock');
var sample, instance;
-describe('model signatures', function() {
+describe('1.2 model signatures', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -17,7 +17,7 @@ describe('model signatures', function() {
});
it('returns the json representation of a pet with repeating models', function() {
- var pet = sample.models['Animals'];
+ var pet = sample.models.Animals;
test.object(pet);
// verify that each instance of `Pet` is represented
@@ -29,5 +29,5 @@ describe('model signatures', function() {
model += '"mouse":' + petModel + '}';
expect(JSON.stringify(pet.createJSONSample())).toBe(model);
- })
+ });
});
diff --git a/test/compat/models.js b/test/compat/models.js
index 37206b46d..d527eb5a5 100644
--- a/test/compat/models.js
+++ b/test/compat/models.js
@@ -4,7 +4,7 @@ var mock = require('../../test/compat/mock');
var swagger = require('../../lib/swagger-client');
var sample, instance;
-describe('get model operations', function() {
+describe('1.2 get model operations', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -19,29 +19,29 @@ describe('get model operations', function() {
});
it('verifies the Pet model', function(done) {
- var pet = sample.pet.models['Pet'];
+ var pet = sample.pet.models.Pet;
expect(pet.name).toBe('Pet');
var props = pet.properties;
expect(props[0].name).toBe('id');
expect(props[0].dataType).toBe('integer');
- expect(props[1].name).toBe('category')
- expect(props[1].dataType).toBe('Category')
+ expect(props[1].name).toBe('category');
+ expect(props[1].dataType).toBe('Category');
- expect(props[2].name).toBe('name')
- expect(props[2].dataType).toBe('string')
+ expect(props[2].name).toBe('name');
+ expect(props[2].dataType).toBe('string');
- expect(props[3].name).toBe('photoUrls')
- expect(props[3].dataType).toBe('array')
- expect(props[3].refDataType).toBe('string')
+ expect(props[3].name).toBe('photoUrls');
+ expect(props[3].dataType).toBe('array');
+ expect(props[3].refDataType).toBe('string');
- expect(props[4].name).toBe('tags')
- expect(props[4].dataType).toBe('array')
- expect(props[4].refDataType).toBe('Tag')
+ expect(props[4].name).toBe('tags');
+ expect(props[4].dataType).toBe('array');
+ expect(props[4].refDataType).toBe('Tag');
- expect(props[5].name).toBe('status')
- expect(props[5].dataType).toBe('string')
+ expect(props[5].name).toBe('status');
+ expect(props[5].dataType).toBe('string');
done();
});
@@ -59,4 +59,4 @@ describe('get model operations', function() {
done();
});
-})
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/test/compat/operation.js b/test/compat/operation.js
index 64167baf8..048ed0d04 100644
--- a/test/compat/operation.js
+++ b/test/compat/operation.js
@@ -1,9 +1,9 @@
-var test = require('unit.js')
-var expect = require('expect')
+var test = require('unit.js');
+var expect = require('expect');
var mock = require('../../test/compat/mock');
var sample, instance;
-describe('verifies the nickname is sanitized', function() {
+describe('1.2 verifies the nickname is sanitized', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -13,7 +13,6 @@ describe('verifies the nickname is sanitized', function() {
after(function(done){
instance.close();
-
done();
});
@@ -63,7 +62,6 @@ describe('verifies the get pet operation', function() {
after(function(done){
instance.close();
-
done();
});
@@ -81,7 +79,7 @@ describe('verifies the get pet operation', function() {
operation = sample.pet.operations.getPetById;
operation.resource.basePath = 'http://foo.bar/api/';
var url = operation.urlify({petId: 129298});
- expect(url).toBe('http://foo.bar/api/pet/129298')
+ expect(url).toBe('http://foo.bar/api/pet/129298');
});
it('verifies the default value from the get operation', function() {
@@ -96,7 +94,7 @@ describe('verifies the get pet operation', function() {
});
it('verifies the get pet operation', function() {
- operation = sample.pet.operations.getPetById
+ operation = sample.pet.operations.getPetById;
expect(operation.method).toBe('get');
parameters = operation.parameters;
@@ -104,7 +102,7 @@ describe('verifies the get pet operation', function() {
test.object(parameters);
expect(parameters.length).toBe(1);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('petId');
expect(param.type).toBe('integer');
expect(param.paramType).toBe('path');
@@ -112,15 +110,15 @@ describe('verifies the get pet operation', function() {
});
it('verifies the post pet operation', function() {
- operation = sample.pet.operations.addPet
+ operation = sample.pet.operations.addPet;
expect(operation.method).toBe('post');
- parameters = operation.parameters
+ parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(1);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('body');
expect(param.type).toBe('Pet');
expect(param.paramType).toBe('body');
@@ -128,15 +126,15 @@ describe('verifies the get pet operation', function() {
});
it('verifies the put pet operation', function() {
- operation = sample.pet.operations.updatePet
+ operation = sample.pet.operations.updatePet;
expect(operation.method).toBe('put');
- parameters = operation.parameters
+ parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(1);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('body');
expect(param.type).toBe('Pet');
expect(param.paramType).toBe('body');
@@ -144,15 +142,15 @@ describe('verifies the get pet operation', function() {
});
it('verifies the findByTags operation', function() {
- operation = sample.pet.operations.findPetsByTags
+ operation = sample.pet.operations.findPetsByTags;
expect(operation.method).toBe('get');
- parameters = operation.parameters
+ parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(1);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('tags');
expect(param.type).toBe('string');
@@ -161,25 +159,25 @@ describe('verifies the get pet operation', function() {
});
it('verifies the patch pet operation', function() {
- operation = sample.pet.operations.partialUpdate
+ operation = sample.pet.operations.partialUpdate;
expect(operation.method).toBe('patch');
- produces = operation.produces
+ produces = operation.produces;
expect(produces.length).toBe(2);
expect(produces[0]).toBe('application/json');
expect(produces[1]).toBe('application/xml');
- parameters = operation.parameters
+ parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(2);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('petId');
expect(param.type).toBe('string');
expect(param.paramType).toBe('path');
test.value(param.description);
- param = parameters[1]
+ param = parameters[1];
expect(param.name).toBe('body');
expect(param.type).toBe('Pet');
expect(param.paramType).toBe('body');
@@ -187,31 +185,31 @@ describe('verifies the get pet operation', function() {
});
it('verifies the post pet operation with form', function() {
- operation = sample.pet.operations.updatePetWithForm
+ operation = sample.pet.operations.updatePetWithForm;
expect(operation.method).toBe('post');
- consumes = operation.consumes
+ consumes = operation.consumes;
expect(consumes.length).toBe(1);
expect(consumes[0]).toBe('application/x-www-form-urlencoded');
- parameters = operation.parameters
+ parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(3);
- param = parameters[0]
+ param = parameters[0];
expect(param.name).toBe('petId');
expect(param.type).toBe('string');
expect(param.paramType).toBe('path');
test.value(param.description);
- param = parameters[1]
+ param = parameters[1];
expect(param.name).toBe('name');
expect(param.type).toBe('string');
expect(param.paramType).toBe('form');
test.value(param.description);
expect(param.required).toBe(false);
- param = parameters[2]
+ param = parameters[2];
expect(param.name).toBe('status');
expect(param.type).toBe('string');
expect(param.paramType).toBe('form');
@@ -220,25 +218,25 @@ describe('verifies the get pet operation', function() {
});
it('verifies a file upload', function() {
- var operation = sample.pet.operations.uploadFile
+ var operation = sample.pet.operations.uploadFile;
expect(operation.method).toBe('post');
- var consumes = operation.consumes
+ var consumes = operation.consumes;
expect(consumes.length).toBe(1);
expect(consumes[0]).toBe('multipart/form-data');
- var parameters = operation.parameters
+ var parameters = operation.parameters;
test.object(parameters);
expect(parameters.length).toBe(2);
- var param = parameters[0]
+ var param = parameters[0];
expect(param.name).toBe('additionalMetadata');
expect(param.type).toBe('string');
expect(param.paramType).toBe('form');
expect(param.required).toBe(false);
test.value(param.description);
- param = parameters[1]
+ param = parameters[1];
expect(param.name).toBe('file');
expect(param.type).toBe('File');
expect(param.paramType).toBe('body');
@@ -252,12 +250,12 @@ describe('verifies the get pet operation', function() {
});
it('gets operations for the pet api', function() {
- var ops = sample.pet.operations
+ var ops = sample.pet.operations;
test.object(ops);
});
it('gets help() from the file upload operation', function() {
- operation = sample.pet.operations.uploadFile
+ operation = sample.pet.operations.uploadFile;
expect(operation.help()).toBe('* additionalMetadata - Additional data to pass to server\n* file - file to upload');
});
-})
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/test/compat/request.js b/test/compat/request.js
index 7728ad21a..ba23dbf63 100644
--- a/test/compat/request.js
+++ b/test/compat/request.js
@@ -1,10 +1,10 @@
-var test = require('unit.js')
-var expect = require('expect')
+var test = require('unit.js');
+var expect = require('expect');
var mock = require('../../test/compat/mock');
var swagger = require('../../lib/swagger-client');
var sample, instance;
-describe('request operations', function() {
+describe('1.2 request operations', function() {
before(function(done) {
mock.petstore(done, function(petstore, server){
sample = petstore;
@@ -14,7 +14,6 @@ describe('request operations', function() {
after(function(done){
instance.close();
-
done();
});
@@ -38,7 +37,7 @@ describe('request operations', function() {
test.object(req);
expect(req.method).toBe('GET');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
expect(req.url).toBe('http://localhost:8000/v1/api/pet/1');
});
@@ -59,7 +58,7 @@ describe('request operations', function() {
var req = petApi.findPetsByStatus(params, opts);
expect(req.method).toBe("GET");
- expect(req.headers["Accept"]).toBe("application/json");
+ expect(req.headers.Accept).toBe("application/json");
expect(req.url).toBe("http://localhost:8000/v1/api/pet/findByStatus?status=available");
});
@@ -78,7 +77,7 @@ describe('request operations', function() {
var req = petApi.addPet(params, opts);
expect(req.method).toBe("POST");
- expect(req.headers["Accept"]).toBe("application/json");
+ expect(req.headers.Accept).toBe("application/json");
expect(req.headers["Content-Type"]).toBe("application/json");
expect(req.body).toBe('{"id":100,"name":"monster","status":"dead"}');
expect(req.url).toBe("http://localhost:8000/v1/api/pet");
@@ -97,7 +96,7 @@ describe('request operations', function() {
var req = petApi.updatePetWithForm(params, opts);
expect(req.method).toBe('POST');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
expect(req.headers['Content-Type']).toBe('application/x-www-form-urlencoded');
expect(req.body).toBe('name=dog&status=very%20happy');
expect(req.url).toBe('http://localhost:8000/v1/api/pet/1');
@@ -118,7 +117,7 @@ describe('request operations', function() {
var req = petApi.updatePet(params, opts);
expect(req.method).toBe('PUT');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
expect(req.headers['Content-Type']).toBe('application/json');
expect(req.body).toBe('{\"id\":100,\"name\":\"monster\",\"status\":\"dead\"}');
expect(req.url).toBe('http://localhost:8000/v1/api/pet');
@@ -135,7 +134,7 @@ describe('request operations', function() {
var req = petApi.deletePet(params, opts);
expect(req.method).toBe('DELETE');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
expect(req.headers['Content-Type']).toBe('application/json');
expect(req.url).toBe('http://localhost:8000/v1/api/pet/100');
});
@@ -151,7 +150,7 @@ describe('request operations', function() {
var req = petApi.findPetsByStatus(params, opts);
expect(req.method).toBe('GET');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
test.value(req.headers['Content-Type']).isUndefined();
expect(req.url).toBe('http://localhost:8000/v1/api/pet/findByStatus?status=a%20b%20c%20d%20e');
});
@@ -167,16 +166,16 @@ describe('request operations', function() {
var req = petApi.getPetById(params, opts);
expect(req.method).toBe('GET');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
test.value(req.headers['Content-Type']).isUndefined();
expect(req.url).toBe('http://localhost:8000/v1/api/pet/false');
});
it('tests the urlify function', function() {
- var op = sample.apis['pet'].operations.getPetById
+ var op = sample.apis.pet.operations.getPetById;
op.pathJson = function() {
- return "/entities/{id:([a-z0-9-]{36})}"
- }
+ return "/entities/{id:([a-z0-9-]{36})}";
+ };
// console.log(op.urlify({petId: 1, 'id:\(\[a\-z0\-9\-\]\{36\}\)': 'ok'}));
});
@@ -191,7 +190,7 @@ describe('request operations', function() {
});
it('tests the body param when name is not `body`, per #168', function() {
- var op = sample.apis['pet'].operations.addPet
+ var op = sample.apis.pet.operations.addPet;
op.parameters[0].name = 'pet';
var params = {
@@ -206,7 +205,7 @@ describe('request operations', function() {
it('verifies headers when fetching the swagger specification', function() {
var sample = new swagger.SwaggerClient('http://localhost:8000/api-docs.json');
var req = sample.build(true);
- expect(req.headers['accept']).toBe('application/json;charset=utf-8,*/*');
+ expect(req.headers.accept).toBe('application/json;charset=utf-8,*/*');
});
it('allows override of headers when fetching the swagger specification', function() {
@@ -215,7 +214,7 @@ describe('request operations', function() {
};
var sample = new swagger.SwaggerClient('http://localhost:8000/api-docs.json', opts);
var req = sample.build(true);
- expect(req.headers['accept']).toBe('foo/bar');
+ expect(req.headers.accept).toBe('foo/bar');
});
it('verifies the http request object for a GET with email address query params per https://github.com/swagger-api/swagger-ui/issues/814', function() {
@@ -229,7 +228,7 @@ describe('request operations', function() {
var req = petApi.findPetsByStatus(params, opts);
expect(req.method).toBe("GET");
- expect(req.headers["Accept"]).toBe("application/json");
+ expect(req.headers.Accept).toBe("application/json");
expect(req.url).toBe("http://localhost:8000/v1/api/pet/findByStatus?status=fehguy%40gmail.com");
});
@@ -241,7 +240,7 @@ describe('request operations', function() {
var req = petApi.findPetsByTags(params, opts);
expect(req.method).toBe('GET');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
test.value(req.headers['Content-Type']).isUndefined();
expect(req.url).toBe('http://localhost:8000/v1/api/pet/findByTags');
});
@@ -254,8 +253,8 @@ describe('request operations', function() {
var req = petApi.findPetsByTags(params, opts);
expect(req.method).toBe('GET');
- expect(req.headers['Accept']).toBe('application/json');
+ expect(req.headers.Accept).toBe('application/json');
test.value(req.headers['Content-Type']).isUndefined();
expect(req.url).toBe('http://localhost:8000/v1/api/pet/findByTags');
});
-})
\ No newline at end of file
+});
diff --git a/test/mock.js b/test/mock.js
index 70d84f5b2..344f06086 100644
--- a/test/mock.js
+++ b/test/mock.js
@@ -8,7 +8,7 @@ var sample;
exports.petstore = function(arg1, arg2, arg3, arg4) {
var done = arg1, opts = arg2, callback = arg3, macros = arg4;
if(typeof arg2 === 'function') {
- opts = null;
+ opts = {};
callback = arg2;
macros = arg3;
}
@@ -57,8 +57,6 @@ exports.petstore = function(arg1, arg2, arg3, arg4) {
}).listen(8000);
instance.on("listening", function() {
- var self = {}; self.stop = done;
-
if(macros) {
if(macros.parameter) {
console.log(' warn: set parameter macro');
@@ -69,17 +67,12 @@ exports.petstore = function(arg1, arg2, arg3, arg4) {
swagger.modelPropertyMacro = macros.modelProperty;
}
}
- var sample = new swagger.SwaggerClient({url: 'http://localhost:8000/v2/petstore.json', opts: opts});
- sample.build();
- var count = 0, isDone = false;
- var f = function () {
- if(!isDone) {
- isDone = true;
- self.stop();
- }
+ opts.url = 'http://localhost:8000/v2/petstore.json';
+ opts.success = function() {
+ done();
callback(sample, instance);
return;
};
- setTimeout(f, 50);
+ var sample = new swagger.SwaggerClient(opts);
});
};
\ No newline at end of file
diff --git a/test/models.js b/test/models.js
index 300c69083..003fdc568 100644
--- a/test/models.js
+++ b/test/models.js
@@ -14,9 +14,9 @@ describe('models', function() {
type: "string"
}
}
- }
+ };
var model = new swagger.Model('Tag', definition);
- expect(model.createJSONSample()).toEqual({ id: 0, name: 'string' })
+ expect(model.createJSONSample()).toEqual({ id: 0, name: 'string' });
});
it('should verify the JSON sample for a primitive array', function() {
@@ -25,7 +25,7 @@ describe('models', function() {
items: {
type: "string"
}
- }
+ };
var model = new swagger.Model('Tag', definition);
expect(model.createJSONSample()).toEqual(['string']);
});
@@ -45,7 +45,7 @@ describe('models', function() {
type: 'array'
}
}
- }
+ };
var model = new swagger.Model('Sample', definition);
expect(model.createJSONSample()).toEqual({ id: 0, name: 'string', photos: [ {} ] });
});
@@ -65,7 +65,7 @@ describe('models', function() {
type: 'array'
}
}
- }
+ };
var model = new swagger.Model('Sample', definition);
expect(model.getMockSignature()).toEqual('Sample {id (integer, optional),
name (string, optional),
photos (Array[object], optional)
}');
});
@@ -82,11 +82,11 @@ describe('models', function() {
}
}
}
- }
+ };
var model = new swagger.Model('Sample', definition);
var property = model.properties[0];
// TODO: verify that enums are represented in the mock signature
- console.log(model.createJSONSample());
+ // console.log(model.createJSONSample());
});
it('should not get infinite recursion', function() {
@@ -112,9 +112,9 @@ describe('models', function() {
}
}
}
- }
+ };
var model = new swagger.Model('Component', definition);
- swagger.models['Component'] = model;
+ swagger.addModel('Component', model);
expect(model.createJSONSample()).toEqual(
{
pendingComponents: [
@@ -138,7 +138,7 @@ describe('models', function() {
}
};
var model = new swagger.Model('ListOfSelf', definition);
- swagger.models['ListOfSelf'] = model;
+ swagger.addModel('ListOfSelf', model);
expect(model.createJSONSample()).toEqual(
[ 'ListOfSelf' ]
);
@@ -151,8 +151,9 @@ describe('models', function() {
$ref: 'DictionaryOfSelf'
}
};
+
var model = new swagger.Model('DictionaryOfSelf', definition);
- swagger.models['DictionaryOfSelf'] = model;
+ swagger.addModel.DictionaryOfSelf = model;
// console.log(model.createJSONSample());
// TODO add support for this
});
diff --git a/test/request.js b/test/request.js
index 2583863fb..c08aaf0dc 100644
--- a/test/request.js
+++ b/test/request.js
@@ -116,7 +116,7 @@ describe('swagger request functions', function() {
it('return a json sample in array', function() {
var successResponse = sample.pet.operations.findPetsByTags.successResponse;
- expect(typeof successResponse['200']).toBe('object')
+ expect(typeof successResponse['200']).toBe('object');
expect(successResponse['200'].createJSONSample()).toEqual([
{
"id": 0,
@@ -141,7 +141,7 @@ describe('swagger request functions', function() {
it('return a json sample from an array model', function() {
var successResponse = sample.pet.operations.findPetsByStatus.successResponse;
- expect(typeof successResponse['200']).toBe('object')
+ expect(typeof successResponse['200']).toBe('object');
expect(successResponse['200'].createJSONSample()).toEqual([
{
"id": 0,
diff --git a/test/responses.js b/test/responses.js
index f01aa8048..6e05b8cf6 100644
--- a/test/responses.js
+++ b/test/responses.js
@@ -25,11 +25,11 @@ describe('response types', function() {
200: MonsterResponse,
201: StringResponse,
'default': BasicResponseModel
- }
+ };
var definitions = {
Monster: MonsterModel,
ResponseModel: ResponseModel
- }
+ };
var op = new swagger.Operation(
{},
@@ -44,7 +44,7 @@ describe('response types', function() {
var responseModel = op.successResponse['200'];
expect(op.successResponse['200'].createJSONSample()).toEqual({ id: 0, name: 'string' });
- var responses = op.responses;
+ responses = op.responses;
expect(typeof responses['201']).toBe('object');
expect(typeof responses['default']).toBe('object');
});