Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.3-M1
* @version v2.1.5-M1
* @link http://swagger.io
* @license apache 2.0
*/
Expand Down Expand Up @@ -57,10 +57,31 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {

ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
propertiesStr.push(prop.toString());
}

var strong = '<span class="strong">';
var stronger = '<span class="stronger">';
var strongClose = '</span>';
var classOpen = strong + 'array' + ' {' + strongClose;
var classClose = strong + '}' + strongClose;
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;

if(this.ref) {
return models[simpleRef(this.ref)].getMockSignature();
if (!modelsToIgnore)
modelsToIgnore = {};
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
var ref = prop.$ref;
var model = models[ref];
if (model && typeof modelsToIgnore[ref] === 'undefined') {
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
}
}
return returnVal;
};


Expand Down Expand Up @@ -2356,7 +2377,7 @@ SwaggerOperation.prototype.urlify = function (args) {
if (param.paramType === 'path') {
if (typeof args[param.name] !== 'undefined') {
// apply path params and remove from args
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi');
var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
url = url.replace(reg, this.encodePathParam(args[param.name]));
delete args[param.name];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/swagger-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "swagger-client",
"author": "Tony Tam <fehguy@gmail.com>",
"description": "swagger.js is a javascript client for use with swaggering APIs.",
"version": "2.1.4-M1",
"version": "2.1.5-M1",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
Expand Down
25 changes: 23 additions & 2 deletions src/js/arrayModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,29 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {

ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
propertiesStr.push(prop.toString());
}

var strong = '<span class="strong">';
var stronger = '<span class="stronger">';
var strongClose = '</span>';
var classOpen = strong + 'array' + ' {' + strongClose;
var classClose = strong + '}' + strongClose;
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;

if(this.ref) {
return models[simpleRef(this.ref)].getMockSignature();
if (!modelsToIgnore)
modelsToIgnore = {};
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
var ref = prop.$ref;
var model = models[ref];
if (model && typeof modelsToIgnore[ref] === 'undefined') {
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
}
}
return returnVal;
};
1 change: 1 addition & 0 deletions src/js/swagger-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
this.options = options;

if (typeof options.success === 'function') {
this.ready = true;
this.build();
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/js/swagger-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
this.isValid = true;
this.ready = true;
this.isBuilt = true;
this.selfReflect();
this.success();
Expand Down Expand Up @@ -815,7 +816,7 @@ SwaggerOperation.prototype.urlify = function (args) {
if (param.paramType === 'path') {
if (typeof args[param.name] !== 'undefined') {
// apply path params and remove from args
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi');
var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
url = url.replace(reg, this.encodePathParam(args[param.name]));
delete args[param.name];
}
Expand Down
49 changes: 46 additions & 3 deletions test/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('models', function() {
// console.log(model.createJSONSample());
});

it('should not get infinite recursion', function() {
it('should not get infinite for sample JSON recursion', function() {
var definition = {
type: 'object',
properties: {
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('models', function() {
);
});

it('should not get infinite recursion case 2', function() {
it('should not get infinite recursion for sample JSON case 2', function() {
var definition = {
type: "array",
items: {
Expand All @@ -144,7 +144,7 @@ describe('models', function() {
);
});

it('should not get infinite recursion case 3', function() {
it('should not get infinite recursion for sample JSON case 3', function() {
definition = {
type: 'object',
additionalProperties: {
Expand All @@ -157,4 +157,47 @@ describe('models', function() {
// console.log(model.createJSONSample());
// TODO add support for this
});


it('should not get infinite for mock signature recursion', function() {
var definition = {
type: 'object',
properties: {
pendingComponents: {
type: 'array',
items: {
$ref: 'Component'
}
},
receivedComponents: {
type: 'array',
items: {
$ref: 'Component'
}
},
rejectedComponents: {
type: 'array',
items: {
$ref: 'Component'
}
}
}
};
var model = new swagger.Model('Component', definition);
swagger.addModel('Component', model);
var sig = model.getMockSignature();
});

it('should not get infinite recursion for mock signature case 2', function() {
var definition = {
type: "array",
items: {
$ref: "ListOfSelf"
}
};
var model = new swagger.Model('ListOfSelf', definition);
swagger.addModel('ListOfSelf', model);
var sig = model.getMockSignature();
expect(sig).toEqual('<span class="strong">array {</span><div></div><span class="strong">}</span>');
});
});