1
1
/**
2
2
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
3
- * @version v2.1.0 -M1
3
+ * @version v2.1.1 -M1
4
4
* @link http://swagger.io
5
5
* @license apache 2.0
6
6
*/
@@ -31,7 +31,13 @@ ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
31
31
}
32
32
else if ( this . ref ) {
33
33
var name = simpleRef ( this . ref ) ;
34
- result = models [ name ] . createJSONSample ( ) ;
34
+ if ( typeof modelsToIgnore [ name ] === 'undefined' ) {
35
+ modelsToIgnore [ name ] = this ;
36
+ result = models [ name ] . createJSONSample ( modelsToIgnore ) ;
37
+ }
38
+ else {
39
+ return name ;
40
+ }
35
41
}
36
42
return [ result ] ;
37
43
} ;
@@ -90,6 +96,7 @@ SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
90
96
else {
91
97
// 2.0 support
92
98
if ( Array . isArray ( authorizations ) ) {
99
+
93
100
for ( var i = 0 ; i < authorizations . length ; i ++ ) {
94
101
var auth = authorizations [ i ] ;
95
102
for ( name in auth ) {
@@ -607,12 +614,15 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
607
614
param . allowableValues . descriptiveValues . push ( { value : value , isDefault : isDefault } ) ;
608
615
}
609
616
}
610
- if ( param . type === 'array' && typeof param . allowableValues === 'undefined' ) {
611
- // can't show as a list if no values to select from
612
- delete param . isList ;
613
- delete param . allowMultiple ;
617
+ if ( param . type === 'array' ) {
618
+ innerType = [ innerType ] ;
619
+ if ( typeof param . allowableValues === 'undefined' ) {
620
+ // can't show as a list if no values to select from
621
+ delete param . isList ;
622
+ delete param . allowMultiple ;
623
+ }
614
624
}
615
- param . signature = this . getModelSignature ( innerType , models ) ;
625
+ param . signature = this . getModelSignature ( innerType , models ) . toString ( ) ;
616
626
param . sampleJSON = this . getModelSampleJSON ( innerType , models ) ;
617
627
param . responseClassSignature = param . signature ;
618
628
}
@@ -764,16 +774,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
764
774
listType = true ;
765
775
type = type [ 0 ] ;
766
776
}
777
+ else if ( typeof type === 'undefined' )
778
+ type = 'undefined' ;
767
779
768
780
if ( type === 'string' )
769
781
isPrimitive = true ;
770
782
else
771
783
isPrimitive = ( listType && definitions [ listType ] ) || ( definitions [ type ] ) ? false : true ;
772
784
if ( isPrimitive ) {
773
- return type ;
785
+ if ( listType )
786
+ return 'Array[' + type + ']' ;
787
+ else
788
+ return type . toString ( ) ;
774
789
} else {
775
790
if ( listType )
776
- return definitions [ type ] . getMockSignature ( ) ;
791
+ return 'Array[' + definitions [ type ] . getMockSignature ( ) + ']' ;
777
792
else
778
793
return definitions [ type ] . getMockSignature ( ) ;
779
794
}
@@ -965,8 +980,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
965
980
fail ( message ) ;
966
981
return ;
967
982
}
968
- var headers = this . getHeaderParams ( args ) ;
969
- headers = this . setContentTypes ( args , opts ) ;
983
+ var allHeaders = this . getHeaderParams ( args ) ;
984
+ var contentTypeHeaders = this . setContentTypes ( args , opts ) ;
985
+
986
+ var headers = { } ;
987
+ for ( var attrname in allHeaders ) { headers [ attrname ] = allHeaders [ attrname ] ; }
988
+ for ( var attrname in contentTypeHeaders ) { headers [ attrname ] = contentTypeHeaders [ attrname ] ; }
989
+
970
990
var body = this . getBody ( headers , args ) ;
971
991
var url = this . urlify ( args ) ;
972
992
@@ -1013,10 +1033,10 @@ Operation.prototype.setContentTypes = function(args, opts) {
1013
1033
else
1014
1034
definedFormParams . push ( param ) ;
1015
1035
}
1016
- else if ( param . in === 'header' && this . headers ) {
1036
+ else if ( param . in === 'header' && opts ) {
1017
1037
var key = param . name ;
1018
- var headerValue = this . headers [ param . name ] ;
1019
- if ( typeof this . headers [ param . name ] !== 'undefined' )
1038
+ var headerValue = opts [ param . name ] ;
1039
+ if ( typeof opts [ param . name ] !== 'undefined' )
1020
1040
headers [ key ] = headerValue ;
1021
1041
}
1022
1042
else if ( param . in === 'body' && typeof args [ param . name ] !== 'undefined' ) {
@@ -1184,21 +1204,20 @@ var Model = function(name, definition) {
1184
1204
} ;
1185
1205
1186
1206
Model . prototype . createJSONSample = function ( modelsToIgnore ) {
1187
- var result = { } ;
1207
+ var i , result = { } ;
1188
1208
modelsToIgnore = ( modelsToIgnore || { } ) ;
1189
1209
modelsToIgnore [ this . name ] = this ;
1190
- var i ;
1191
1210
for ( i = 0 ; i < this . properties . length ; i ++ ) {
1192
1211
prop = this . properties [ i ] ;
1193
- result [ prop . name ] = prop . getSampleValue ( modelsToIgnore ) ;
1212
+ var sample = prop . getSampleValue ( modelsToIgnore ) ;
1213
+ result [ prop . name ] = sample ;
1194
1214
}
1195
1215
delete modelsToIgnore [ this . name ] ;
1196
1216
return result ;
1197
1217
} ;
1198
1218
1199
1219
Model . prototype . getSampleValue = function ( modelsToIgnore ) {
1200
- var i ;
1201
- var obj = { } ;
1220
+ var i , obj = { } ;
1202
1221
for ( i = 0 ; i < this . properties . length ; i ++ ) {
1203
1222
var property = this . properties [ i ] ;
1204
1223
obj [ property . name ] = property . sampleValue ( false , modelsToIgnore ) ;
@@ -1207,8 +1226,7 @@ Model.prototype.getSampleValue = function(modelsToIgnore) {
1207
1226
} ;
1208
1227
1209
1228
Model . prototype . getMockSignature = function ( modelsToIgnore ) {
1210
- var propertiesStr = [ ] ;
1211
- var i , prop ;
1229
+ var i , prop , propertiesStr = [ ] ;
1212
1230
for ( i = 0 ; i < this . properties . length ; i ++ ) {
1213
1231
prop = this . properties [ i ] ;
1214
1232
propertiesStr . push ( prop . toString ( ) ) ;
@@ -1282,7 +1300,7 @@ Property.prototype.isArray = function () {
1282
1300
Property . prototype . sampleValue = function ( isArray , ignoredModels ) {
1283
1301
isArray = ( isArray || this . isArray ( ) ) ;
1284
1302
ignoredModels = ( ignoredModels || { } ) ;
1285
- var type = getStringSignature ( this . obj ) ;
1303
+ var type = getStringSignature ( this . obj , true ) ;
1286
1304
var output ;
1287
1305
1288
1306
if ( this . $ref ) {
@@ -1292,8 +1310,9 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
1292
1310
ignoredModels [ type ] = this ;
1293
1311
output = refModel . getSampleValue ( ignoredModels ) ;
1294
1312
}
1295
- else
1296
- type = refModel ;
1313
+ else {
1314
+ output = refModelName ;
1315
+ }
1297
1316
}
1298
1317
else if ( this . example )
1299
1318
output = this . example ;
@@ -1324,16 +1343,20 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
1324
1343
return output ;
1325
1344
} ;
1326
1345
1327
- getStringSignature = function ( obj ) {
1346
+ getStringSignature = function ( obj , baseComponent ) {
1328
1347
var str = '' ;
1329
1348
if ( typeof obj . $ref !== 'undefined' )
1330
1349
str += simpleRef ( obj . $ref ) ;
1331
1350
else if ( typeof obj . type === 'undefined' )
1332
1351
str += 'object' ;
1333
1352
else if ( obj . type === 'array' ) {
1334
- str += 'Array[' ;
1335
- str += getStringSignature ( ( obj . items || obj . $ref || { } ) ) ;
1336
- str += ']' ;
1353
+ if ( baseComponent )
1354
+ str += getStringSignature ( ( obj . items || obj . $ref || { } ) ) ;
1355
+ else {
1356
+ str += 'Array[' ;
1357
+ str += getStringSignature ( ( obj . items || obj . $ref || { } ) ) ;
1358
+ str += ']' ;
1359
+ }
1337
1360
}
1338
1361
else if ( obj . type === 'integer' && obj . format === 'int32' )
1339
1362
str += 'integer' ;
0 commit comments