updated version

This commit is contained in:
Tony Tam
2015-02-19 22:55:36 -08:00
parent 75bb7e2521
commit 1447b865d2
5 changed files with 212 additions and 196 deletions

View File

@@ -1,6 +1,6 @@
/**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.6-M1
* @version v2.1.7-M1
* @link http://swagger.io
* @license apache 2.0
*/
@@ -1275,12 +1275,12 @@ var Model = function(name, definition) {
};
Model.prototype.createJSONSample = function(modelsToIgnore) {
var i, result = {};
var i, result = {}, representations = {};
modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
var sample = prop.getSampleValue(modelsToIgnore);
var sample = prop.getSampleValue(modelsToIgnore, representations);
result[prop.name] = sample;
}
delete modelsToIgnore[this.name];
@@ -1288,10 +1288,10 @@ Model.prototype.createJSONSample = function(modelsToIgnore) {
};
Model.prototype.getSampleValue = function(modelsToIgnore) {
var i, obj = {};
var i, obj = {}, representations = {};
for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore);
obj[property.name] = property.sampleValue(false, modelsToIgnore, representations);
}
return obj;
};
@@ -1356,8 +1356,8 @@ var Property = function(name, obj, required) {
this.multipleOf = obj.multipleOf || null;
};
Property.prototype.getSampleValue = function (modelsToIgnore) {
return this.sampleValue(false, modelsToIgnore);
Property.prototype.getSampleValue = function (modelsToIgnore, representations) {
return this.sampleValue(false, modelsToIgnore, representations);
};
Property.prototype.isArray = function () {
@@ -1368,21 +1368,29 @@ Property.prototype.isArray = function () {
return false;
};
Property.prototype.sampleValue = function(isArray, ignoredModels) {
Property.prototype.sampleValue = function(isArray, ignoredModels, representations) {
isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {});
// representations = (representations || {});
var type = getStringSignature(this.obj, true);
var output;
if(this.$ref) {
var refModelName = simpleRef(this.$ref);
var refModel = models[refModelName];
if(typeof representations[type] !== 'undefined') {
return representations[type];
}
else
if(refModel && typeof ignoredModels[type] === 'undefined') {
ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels);
output = refModel.getSampleValue(ignoredModels, representations);
representations[type] = output;
}
else {
output = refModelName;
output = (representations[type] || refModelName);
}
}
else if(this.example)