Skip to content

Commit

Permalink
fix for swagger-api/swagger-ui#898, exposing param.signature as Array…
Browse files Browse the repository at this point in the history
…[...] when type:'array'
  • Loading branch information
fehguy committed Feb 3, 2015
1 parent 00fa8b0 commit ef54d2b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
23 changes: 15 additions & 8 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.0-M1
* @version v2.1.1-M1
* @link http://swagger.io
* @license apache 2.0
*/
Expand Down Expand Up @@ -614,13 +614,15 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
}
}
if(param.type === 'array' && typeof param.allowableValues === 'undefined') {
// can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
if(param.type === 'array') {
innerType = [innerType];
if(typeof param.allowableValues === 'undefined') {
// 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.responseClassSignature = param.signature;
}
Expand Down Expand Up @@ -772,16 +774,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true;
type = type[0];
}
else if(typeof type === 'undefined')
type = 'undefined';

if(type === 'string')
isPrimitive = true;
else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) {
return type;
if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else {
if (listType)
return definitions[type].getMockSignature();
return 'Array[' + definitions[type].getMockSignature() + ']';
else
return definitions[type].getMockSignature();
}
Expand Down
2 changes: 1 addition & 1 deletion 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 <[email protected]>",
"description": "swagger.js is a javascript client for use with swaggering APIs.",
"version": "2.1.0-M1",
"version": "2.1.1-M1",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
Expand Down
21 changes: 14 additions & 7 deletions src/js/swagger-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,15 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
}
}
if(param.type === 'array' && typeof param.allowableValues === 'undefined') {
// can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
if(param.type === 'array') {
innerType = [innerType];
if(typeof param.allowableValues === 'undefined') {
// 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.responseClassSignature = param.signature;
}
Expand Down Expand Up @@ -490,16 +492,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true;
type = type[0];
}
else if(typeof type === 'undefined')
type = 'undefined';

if(type === 'string')
isPrimitive = true;
else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) {
return type;
if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else {
if (listType)
return definitions[type].getMockSignature();
return 'Array[' + definitions[type].getMockSignature() + ']';
else
return definitions[type].getMockSignature();
}
Expand Down
4 changes: 2 additions & 2 deletions test/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ describe('operations', function() {
{ in: 'query', name: 'year', type: 'array', items: {type: 'string'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters });
expect(op.parameters[0].signature).toEqual(['string']);
expect(op.parameters[0].signature).toEqual('Array[string]');
});

it('should get a date array signature', function() {
var parameters = [
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters });
expect(op.parameters[0].signature).toEqual(['date-time']);
expect(op.parameters[0].signature).toEqual('Array[date-time]');
});
});

Expand Down

0 comments on commit ef54d2b

Please sign in to comment.