Skip to content

Commit b0c43ec

Browse files
committed
Merge pull request #244 from swagger-api/develop_2.0
Merged from develop_2.0
2 parents 23e4fa2 + 1290275 commit b0c43ec

File tree

11 files changed

+204
-53
lines changed

11 files changed

+204
-53
lines changed

lib/swagger-client.js

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
3-
* @version v2.1.3-M1
3+
* @version v2.1.5-M1
44
* @link http://swagger.io
55
* @license apache 2.0
66
*/
@@ -57,10 +57,31 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
5757

5858
ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
5959
var propertiesStr = [];
60+
var i, prop;
61+
for (i = 0; i < this.properties.length; i++) {
62+
prop = this.properties[i];
63+
propertiesStr.push(prop.toString());
64+
}
6065

61-
if(this.ref) {
62-
return models[simpleRef(this.ref)].getMockSignature();
66+
var strong = '<span class="strong">';
67+
var stronger = '<span class="stronger">';
68+
var strongClose = '</span>';
69+
var classOpen = strong + 'array' + ' {' + strongClose;
70+
var classClose = strong + '}' + strongClose;
71+
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
72+
73+
if (!modelsToIgnore)
74+
modelsToIgnore = {};
75+
modelsToIgnore[this.name] = this;
76+
for (i = 0; i < this.properties.length; i++) {
77+
prop = this.properties[i];
78+
var ref = prop.$ref;
79+
var model = models[ref];
80+
if (model && typeof modelsToIgnore[ref] === 'undefined') {
81+
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
82+
}
6383
}
84+
return returnVal;
6485
};
6586

6687

@@ -336,6 +357,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
336357
this.options = options;
337358

338359
if (typeof options.success === 'function') {
360+
this.ready = true;
339361
this.build();
340362
}
341363
};
@@ -411,8 +433,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
411433
// legacy support
412434
this.authSchemes = response.securityDefinitions;
413435

414-
var location;
436+
var definedTags = {};
437+
if(Array.isArray(response.tags)) {
438+
definedTags = {};
439+
for(k = 0; k < response.tags.length; k++) {
440+
var t = response.tags[k];
441+
definedTags[t.name] = t;
442+
}
443+
}
415444

445+
var location;
416446
if(typeof this.url === 'string') {
417447
location = this.parseUri(this.url);
418448
}
@@ -478,8 +508,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
478508
operationGroup.operations = {};
479509
operationGroup.label = tag;
480510
operationGroup.apis = [];
511+
var tagObject = definedTags[tag];
512+
if(typeof tagObject === 'object') {
513+
operationGroup.description = tagObject.description;
514+
operationGroup.externalDocs = tagObject.externalDocs;
515+
}
481516
this[tag].help = this.help.bind(operationGroup);
482-
this.apisArray.push(new OperationGroup(tag, operationObject));
517+
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
483518
}
484519
operationGroup[operationId] = operationObject.execute.bind(operationObject);
485520
operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -548,14 +583,14 @@ SwaggerClient.prototype.fail = function(message) {
548583
throw message;
549584
};
550585

551-
var OperationGroup = function(tag, operation) {
586+
var OperationGroup = function(tag, description, externalDocs, operation) {
552587
this.tag = tag;
553588
this.path = tag;
589+
this.description = description;
590+
this.externalDocs = externalDocs;
554591
this.name = tag;
555592
this.operation = operation;
556593
this.operationsArray = [];
557-
558-
this.description = operation.description || "";
559594
};
560595

561596
var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) {
@@ -720,10 +755,14 @@ Operation.prototype.getType = function (param) {
720755
str = 'long';
721756
else if(type === 'integer')
722757
str = 'integer';
723-
else if(type === 'string' && format === 'date-time')
724-
str = 'date-time';
725-
else if(type === 'string' && format === 'date')
726-
str = 'date';
758+
else if(type === 'string') {
759+
if(format === 'date-time')
760+
str = 'date-time';
761+
else if(format === 'date')
762+
str = 'date';
763+
else
764+
str = 'string';
765+
}
727766
else if(type === 'number' && format === 'float')
728767
str = 'float';
729768
else if(type === 'number' && format === 'double')
@@ -732,8 +771,6 @@ Operation.prototype.getType = function (param) {
732771
str = 'double';
733772
else if(type === 'boolean')
734773
str = 'boolean';
735-
else if(type === 'string')
736-
str = 'string';
737774
else if(type === 'array') {
738775
isArray = true;
739776
if(param.items)
@@ -1028,14 +1065,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
10281065
if(opts.mock === true)
10291066
return obj;
10301067
else
1031-
new SwaggerHttp().execute(obj);
1068+
new SwaggerHttp().execute(obj, opts);
10321069
};
10331070

10341071
Operation.prototype.setContentTypes = function(args, opts) {
10351072
// default type
10361073
var accepts = 'application/json';
10371074
var consumes = args.parameterContentType || 'application/json';
1038-
10391075
var allDefinedParams = this.parameters;
10401076
var definedFormParams = [];
10411077
var definedFileParams = [];
@@ -1288,7 +1324,7 @@ var Property = function(name, obj, required) {
12881324
this.optional = true;
12891325
this.optional = !required;
12901326
this.default = obj.default || null;
1291-
this.example = obj.example || null;
1327+
this.example = obj.example !== undefined ? obj.example : null;
12921328
this.collectionFormat = obj.collectionFormat || null;
12931329
this.maximum = obj.maximum || null;
12941330
this.exclusiveMaximum = obj.exclusiveMaximum || null;
@@ -1591,6 +1627,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
15911627
SwaggerClient.prototype.finish = function() {
15921628
if (typeof this.success === 'function') {
15931629
this.isValid = true;
1630+
this.ready = true;
15941631
this.isBuilt = true;
15951632
this.selfReflect();
15961633
this.success();
@@ -2356,7 +2393,7 @@ SwaggerOperation.prototype.urlify = function (args) {
23562393
if (param.paramType === 'path') {
23572394
if (typeof args[param.name] !== 'undefined') {
23582395
// apply path params and remove from args
2359-
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi');
2396+
var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
23602397
url = url.replace(reg, this.encodePathParam(args[param.name]));
23612398
delete args[param.name];
23622399
}
@@ -2724,7 +2761,7 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) {
27242761
*/
27252762
var SwaggerHttp = function() {};
27262763

2727-
SwaggerHttp.prototype.execute = function(obj) {
2764+
SwaggerHttp.prototype.execute = function(obj, opts) {
27282765
if(obj && (typeof obj.useJQuery === 'boolean'))
27292766
this.useJQuery = obj.useJQuery;
27302767
else
@@ -2735,9 +2772,9 @@ SwaggerHttp.prototype.execute = function(obj) {
27352772
}
27362773

27372774
if(this.useJQuery)
2738-
return new JQueryHttpClient().execute(obj);
2775+
return new JQueryHttpClient(opts).execute(obj);
27392776
else
2740-
return new ShredHttpClient().execute(obj);
2777+
return new ShredHttpClient(opts).execute(obj);
27412778
};
27422779

27432780
SwaggerHttp.prototype.isIE8 = function() {
@@ -2845,8 +2882,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
28452882
/*
28462883
* ShredHttpClient is a light-weight, node or browser HTTP client
28472884
*/
2848-
var ShredHttpClient = function(options) {
2849-
this.options = (options||{});
2885+
var ShredHttpClient = function(opts) {
2886+
this.opts = (opts||{});
28502887
this.isInitialized = false;
28512888

28522889
var identity, toString;
@@ -2857,7 +2894,7 @@ var ShredHttpClient = function(options) {
28572894
}
28582895
else
28592896
this.Shred = require("shred");
2860-
this.shred = new this.Shred(options);
2897+
this.shred = new this.Shred(opts);
28612898
};
28622899

28632900
ShredHttpClient.prototype.initShred = function () {

lib/swagger-client.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "swagger-client",
33
"author": "Tony Tam <[email protected]>",
44
"description": "swagger.js is a javascript client for use with swaggering APIs.",
5-
"version": "2.1.4-M1",
5+
"version": "2.1.5-M1",
66
"homepage": "http://swagger.io",
77
"repository": {
88
"type": "git",

src/js/arrayModel.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,29 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
5050

5151
ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
5252
var propertiesStr = [];
53+
var i, prop;
54+
for (i = 0; i < this.properties.length; i++) {
55+
prop = this.properties[i];
56+
propertiesStr.push(prop.toString());
57+
}
58+
59+
var strong = '<span class="strong">';
60+
var stronger = '<span class="stronger">';
61+
var strongClose = '</span>';
62+
var classOpen = strong + 'array' + ' {' + strongClose;
63+
var classClose = strong + '}' + strongClose;
64+
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
5365

54-
if(this.ref) {
55-
return models[simpleRef(this.ref)].getMockSignature();
66+
if (!modelsToIgnore)
67+
modelsToIgnore = {};
68+
modelsToIgnore[this.name] = this;
69+
for (i = 0; i < this.properties.length; i++) {
70+
prop = this.properties[i];
71+
var ref = prop.$ref;
72+
var model = models[ref];
73+
if (model && typeof modelsToIgnore[ref] === 'undefined') {
74+
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
75+
}
5676
}
77+
return returnVal;
5778
};

src/js/swagger-a.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
5454
this.options = options;
5555

5656
if (typeof options.success === 'function') {
57+
this.ready = true;
5758
this.build();
5859
}
5960
};
@@ -129,8 +130,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
129130
// legacy support
130131
this.authSchemes = response.securityDefinitions;
131132

132-
var location;
133+
var definedTags = {};
134+
if(Array.isArray(response.tags)) {
135+
definedTags = {};
136+
for(k = 0; k < response.tags.length; k++) {
137+
var t = response.tags[k];
138+
definedTags[t.name] = t;
139+
}
140+
}
133141

142+
var location;
134143
if(typeof this.url === 'string') {
135144
location = this.parseUri(this.url);
136145
}
@@ -196,8 +205,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
196205
operationGroup.operations = {};
197206
operationGroup.label = tag;
198207
operationGroup.apis = [];
208+
var tagObject = definedTags[tag];
209+
if(typeof tagObject === 'object') {
210+
operationGroup.description = tagObject.description;
211+
operationGroup.externalDocs = tagObject.externalDocs;
212+
}
199213
this[tag].help = this.help.bind(operationGroup);
200-
this.apisArray.push(new OperationGroup(tag, operationObject));
214+
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
201215
}
202216
operationGroup[operationId] = operationObject.execute.bind(operationObject);
203217
operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -266,14 +280,14 @@ SwaggerClient.prototype.fail = function(message) {
266280
throw message;
267281
};
268282

269-
var OperationGroup = function(tag, operation) {
283+
var OperationGroup = function(tag, description, externalDocs, operation) {
270284
this.tag = tag;
271285
this.path = tag;
286+
this.description = description;
287+
this.externalDocs = externalDocs;
272288
this.name = tag;
273289
this.operation = operation;
274290
this.operationsArray = [];
275-
276-
this.description = operation.description || "";
277291
};
278292

279293
var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) {
@@ -438,10 +452,14 @@ Operation.prototype.getType = function (param) {
438452
str = 'long';
439453
else if(type === 'integer')
440454
str = 'integer';
441-
else if(type === 'string' && format === 'date-time')
442-
str = 'date-time';
443-
else if(type === 'string' && format === 'date')
444-
str = 'date';
455+
else if(type === 'string') {
456+
if(format === 'date-time')
457+
str = 'date-time';
458+
else if(format === 'date')
459+
str = 'date';
460+
else
461+
str = 'string';
462+
}
445463
else if(type === 'number' && format === 'float')
446464
str = 'float';
447465
else if(type === 'number' && format === 'double')
@@ -450,8 +468,6 @@ Operation.prototype.getType = function (param) {
450468
str = 'double';
451469
else if(type === 'boolean')
452470
str = 'boolean';
453-
else if(type === 'string')
454-
str = 'string';
455471
else if(type === 'array') {
456472
isArray = true;
457473
if(param.items)
@@ -746,14 +762,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
746762
if(opts.mock === true)
747763
return obj;
748764
else
749-
new SwaggerHttp().execute(obj);
765+
new SwaggerHttp().execute(obj, opts);
750766
};
751767

752768
Operation.prototype.setContentTypes = function(args, opts) {
753769
// default type
754770
var accepts = 'application/json';
755771
var consumes = args.parameterContentType || 'application/json';
756-
757772
var allDefinedParams = this.parameters;
758773
var definedFormParams = [];
759774
var definedFileParams = [];
@@ -1006,7 +1021,7 @@ var Property = function(name, obj, required) {
10061021
this.optional = true;
10071022
this.optional = !required;
10081023
this.default = obj.default || null;
1009-
this.example = obj.example || null;
1024+
this.example = obj.example !== undefined ? obj.example : null;
10101025
this.collectionFormat = obj.collectionFormat || null;
10111026
this.maximum = obj.maximum || null;
10121027
this.exclusiveMaximum = obj.exclusiveMaximum || null;

src/js/swagger-compat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
5050
SwaggerClient.prototype.finish = function() {
5151
if (typeof this.success === 'function') {
5252
this.isValid = true;
53+
this.ready = true;
5354
this.isBuilt = true;
5455
this.selfReflect();
5556
this.success();
@@ -815,7 +816,7 @@ SwaggerOperation.prototype.urlify = function (args) {
815816
if (param.paramType === 'path') {
816817
if (typeof args[param.name] !== 'undefined') {
817818
// apply path params and remove from args
818-
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi');
819+
var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
819820
url = url.replace(reg, this.encodePathParam(args[param.name]));
820821
delete args[param.name];
821822
}

0 commit comments

Comments
 (0)