updated js library to 2.1.1-M1

This commit is contained in:
Tony Tam
2015-02-02 20:19:06 -08:00
parent 0da7f8ba69
commit 59233adc9c
2 changed files with 102 additions and 56 deletions

View File

@@ -1,6 +1,6 @@
/** /**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.0-M1 * @version v2.1.1-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -31,7 +31,13 @@ ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
} }
else if (this.ref) { else if (this.ref) {
var name = simpleRef(this.ref); var name = simpleRef(this.ref);
result = models[name].createJSONSample(); if(typeof modelsToIgnore[name] === 'undefined') {
modelsToIgnore[name] = this;
result = models[name].createJSONSample(modelsToIgnore);
}
else {
return name;
}
} }
return [ result ]; return [ result ];
}; };
@@ -90,6 +96,7 @@ SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
else { else {
// 2.0 support // 2.0 support
if (Array.isArray(authorizations)) { if (Array.isArray(authorizations)) {
for (var i = 0; i < authorizations.length; i++) { for (var i = 0; i < authorizations.length; i++) {
var auth = authorizations[i]; var auth = authorizations[i];
for (name in auth) { for (name in auth) {
@@ -607,12 +614,15 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
} }
} }
if(param.type === 'array' && typeof param.allowableValues === 'undefined') { if(param.type === 'array') {
// can't show as a list if no values to select from innerType = [innerType];
delete param.isList; if(typeof param.allowableValues === 'undefined') {
delete param.allowMultiple; // can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
}
} }
param.signature = this.getModelSignature(innerType, models); param.signature = this.getModelSignature(innerType, models).toString();
param.sampleJSON = this.getModelSampleJSON(innerType, models); param.sampleJSON = this.getModelSampleJSON(innerType, models);
param.responseClassSignature = param.signature; param.responseClassSignature = param.signature;
} }
@@ -764,16 +774,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true; listType = true;
type = type[0]; type = type[0];
} }
else if(typeof type === 'undefined')
type = 'undefined';
if(type === 'string') if(type === 'string')
isPrimitive = true; isPrimitive = true;
else else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return type; if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else { } else {
if (listType) if (listType)
return definitions[type].getMockSignature(); return 'Array[' + definitions[type].getMockSignature() + ']';
else else
return definitions[type].getMockSignature(); return definitions[type].getMockSignature();
} }
@@ -965,8 +980,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
fail(message); fail(message);
return; return;
} }
var headers = this.getHeaderParams(args); var allHeaders = this.getHeaderParams(args);
headers = this.setContentTypes(args, opts); 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 body = this.getBody(headers, args); var body = this.getBody(headers, args);
var url = this.urlify(args); var url = this.urlify(args);
@@ -1013,10 +1033,10 @@ Operation.prototype.setContentTypes = function(args, opts) {
else else
definedFormParams.push(param); definedFormParams.push(param);
} }
else if(param.in === 'header' && this.headers) { else if(param.in === 'header' && opts) {
var key = param.name; var key = param.name;
var headerValue = this.headers[param.name]; var headerValue = opts[param.name];
if(typeof this.headers[param.name] !== 'undefined') if(typeof opts[param.name] !== 'undefined')
headers[key] = headerValue; headers[key] = headerValue;
} }
else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { else if(param.in === 'body' && typeof args[param.name] !== 'undefined') {
@@ -1184,21 +1204,20 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var result = {}; var i, result = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
var i;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
result[prop.name] = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore);
result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
return result; return result;
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i; var i, obj = {};
var obj = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore);
@@ -1207,8 +1226,7 @@ Model.prototype.getSampleValue = function(modelsToIgnore) {
}; };
Model.prototype.getMockSignature = function(modelsToIgnore) { Model.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var i, prop, propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
propertiesStr.push(prop.toString()); propertiesStr.push(prop.toString());
@@ -1282,7 +1300,7 @@ Property.prototype.isArray = function () {
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
var type = getStringSignature(this.obj); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
@@ -1292,8 +1310,9 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels);
} }
else else {
type = refModel; output = refModelName;
}
} }
else if(this.example) else if(this.example)
output = this.example; output = this.example;
@@ -1324,16 +1343,20 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
return output; return output;
}; };
getStringSignature = function(obj) { getStringSignature = function(obj, baseComponent) {
var str = ''; var str = '';
if(typeof obj.$ref !== 'undefined') if(typeof obj.$ref !== 'undefined')
str += simpleRef(obj.$ref); str += simpleRef(obj.$ref);
else if(typeof obj.type === 'undefined') else if(typeof obj.type === 'undefined')
str += 'object'; str += 'object';
else if(obj.type === 'array') { else if(obj.type === 'array') {
str += 'Array['; if(baseComponent)
str += getStringSignature((obj.items || obj.$ref || {})); str += getStringSignature((obj.items || obj.$ref || {}));
str += ']'; else {
str += 'Array[';
str += getStringSignature((obj.items || obj.$ref || {}));
str += ']';
}
} }
else if(obj.type === 'integer' && obj.format === 'int32') else if(obj.type === 'integer' && obj.format === 'int32')
str += 'integer'; str += 'integer';

View File

@@ -1,6 +1,6 @@
/** /**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.0-M1 * @version v2.1.1-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -31,7 +31,13 @@ ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
} }
else if (this.ref) { else if (this.ref) {
var name = simpleRef(this.ref); var name = simpleRef(this.ref);
result = models[name].createJSONSample(); if(typeof modelsToIgnore[name] === 'undefined') {
modelsToIgnore[name] = this;
result = models[name].createJSONSample(modelsToIgnore);
}
else {
return name;
}
} }
return [ result ]; return [ result ];
}; };
@@ -90,6 +96,7 @@ SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
else { else {
// 2.0 support // 2.0 support
if (Array.isArray(authorizations)) { if (Array.isArray(authorizations)) {
for (var i = 0; i < authorizations.length; i++) { for (var i = 0; i < authorizations.length; i++) {
var auth = authorizations[i]; var auth = authorizations[i];
for (name in auth) { for (name in auth) {
@@ -607,12 +614,15 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
} }
} }
if(param.type === 'array' && typeof param.allowableValues === 'undefined') { if(param.type === 'array') {
// can't show as a list if no values to select from innerType = [innerType];
delete param.isList; if(typeof param.allowableValues === 'undefined') {
delete param.allowMultiple; // can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
}
} }
param.signature = this.getModelSignature(innerType, models); param.signature = this.getModelSignature(innerType, models).toString();
param.sampleJSON = this.getModelSampleJSON(innerType, models); param.sampleJSON = this.getModelSampleJSON(innerType, models);
param.responseClassSignature = param.signature; param.responseClassSignature = param.signature;
} }
@@ -764,16 +774,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true; listType = true;
type = type[0]; type = type[0];
} }
else if(typeof type === 'undefined')
type = 'undefined';
if(type === 'string') if(type === 'string')
isPrimitive = true; isPrimitive = true;
else else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return type; if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else { } else {
if (listType) if (listType)
return definitions[type].getMockSignature(); return 'Array[' + definitions[type].getMockSignature() + ']';
else else
return definitions[type].getMockSignature(); return definitions[type].getMockSignature();
} }
@@ -965,8 +980,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
fail(message); fail(message);
return; return;
} }
var headers = this.getHeaderParams(args); var allHeaders = this.getHeaderParams(args);
headers = this.setContentTypes(args, opts); 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 body = this.getBody(headers, args); var body = this.getBody(headers, args);
var url = this.urlify(args); var url = this.urlify(args);
@@ -1013,10 +1033,10 @@ Operation.prototype.setContentTypes = function(args, opts) {
else else
definedFormParams.push(param); definedFormParams.push(param);
} }
else if(param.in === 'header' && this.headers) { else if(param.in === 'header' && opts) {
var key = param.name; var key = param.name;
var headerValue = this.headers[param.name]; var headerValue = opts[param.name];
if(typeof this.headers[param.name] !== 'undefined') if(typeof opts[param.name] !== 'undefined')
headers[key] = headerValue; headers[key] = headerValue;
} }
else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { else if(param.in === 'body' && typeof args[param.name] !== 'undefined') {
@@ -1184,21 +1204,20 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var result = {}; var i, result = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
var i;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
result[prop.name] = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore);
result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
return result; return result;
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i; var i, obj = {};
var obj = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore);
@@ -1207,8 +1226,7 @@ Model.prototype.getSampleValue = function(modelsToIgnore) {
}; };
Model.prototype.getMockSignature = function(modelsToIgnore) { Model.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var i, prop, propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
propertiesStr.push(prop.toString()); propertiesStr.push(prop.toString());
@@ -1282,7 +1300,7 @@ Property.prototype.isArray = function () {
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
var type = getStringSignature(this.obj); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
@@ -1292,8 +1310,9 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels);
} }
else else {
type = refModel; output = refModelName;
}
} }
else if(this.example) else if(this.example)
output = this.example; output = this.example;
@@ -1324,16 +1343,20 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
return output; return output;
}; };
getStringSignature = function(obj) { getStringSignature = function(obj, baseComponent) {
var str = ''; var str = '';
if(typeof obj.$ref !== 'undefined') if(typeof obj.$ref !== 'undefined')
str += simpleRef(obj.$ref); str += simpleRef(obj.$ref);
else if(typeof obj.type === 'undefined') else if(typeof obj.type === 'undefined')
str += 'object'; str += 'object';
else if(obj.type === 'array') { else if(obj.type === 'array') {
str += 'Array['; if(baseComponent)
str += getStringSignature((obj.items || obj.$ref || {})); str += getStringSignature((obj.items || obj.$ref || {}));
str += ']'; else {
str += 'Array[';
str += getStringSignature((obj.items || obj.$ref || {}));
str += ']';
}
} }
else if(obj.type === 'integer' && obj.format === 'int32') else if(obj.type === 'integer' && obj.format === 'int32')
str += 'integer'; str += 'integer';