Skip to content

Commit 264ba29

Browse files
committed
updated client, version
1 parent 7b3b706 commit 264ba29

File tree

4 files changed

+122
-22
lines changed

4 files changed

+122
-22
lines changed

dist/lib/swagger.js

+60-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger.js
2-
// version 2.0.37
2+
// version 2.0.39
33

44
var __bind = function(fn, me){
55
return function(){
@@ -15,6 +15,16 @@ log = function(){
1515
}
1616
};
1717

18+
// if you want to apply conditional formatting of parameter values
19+
parameterMacro = function(value) {
20+
return value;
21+
}
22+
23+
// if you want to apply conditional formatting of model property values
24+
modelPropertyMacro = function(value) {
25+
return value;
26+
}
27+
1828
if (!Array.prototype.indexOf) {
1929
Array.prototype.indexOf = function(obj, start) {
2030
for (var i = (start || 0), j = this.length; i < j; i++) {
@@ -80,13 +90,15 @@ Object.keys = Object.keys || (function () {
8090
})();
8191

8292
var SwaggerApi = function(url, options) {
93+
this.isBuilt = false;
8394
this.url = null;
8495
this.debug = false;
8596
this.basePath = null;
8697
this.authorizations = null;
8798
this.authorizationScheme = null;
8899
this.info = null;
89100
this.useJQuery = false;
101+
this.modelsArray = [];
90102

91103
options = (options||{});
92104
if (url)
@@ -108,19 +120,23 @@ var SwaggerApi = function(url, options) {
108120

109121
this.failure = options.failure != null ? options.failure : function() {};
110122
this.progress = options.progress != null ? options.progress : function() {};
111-
if (options.success != null)
123+
if (options.success != null) {
112124
this.build();
125+
this.isBuilt = true;
126+
}
113127
}
114128

115129
SwaggerApi.prototype.build = function() {
130+
if(this.isBuilt)
131+
return this;
116132
var _this = this;
117133
this.progress('fetching resource list: ' + this.url);
118134
var obj = {
119135
useJQuery: this.useJQuery,
120136
url: this.url,
121137
method: "get",
122138
headers: {
123-
accept: "application/json"
139+
accept: "application/json,application/json;charset=\"utf-8\",*/*"
124140
},
125141
on: {
126142
error: function(response) {
@@ -276,7 +292,6 @@ SwaggerApi.prototype.fail = function(message) {
276292

277293
SwaggerApi.prototype.setConsolidatedModels = function() {
278294
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
279-
this.modelsArray = [];
280295
this.models = {};
281296
_ref = this.apis;
282297
for (resource_name in _ref) {
@@ -353,7 +368,7 @@ var SwaggerResource = function(resourceObj, api) {
353368
method: "get",
354369
useJQuery: this.useJQuery,
355370
headers: {
356-
accept: "application/json"
371+
accept: "application/json,application/json;charset=\"utf-8\",*/*"
357372
},
358373
on: {
359374
response: function(resp) {
@@ -593,6 +608,7 @@ var SwaggerModelProperty = function(name, obj) {
593608
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
594609
this.descr = obj.description;
595610
this.required = obj.required;
611+
this.defaultValue = modelPropertyMacro(obj.defaultValue);
596612
if (obj.items != null) {
597613
if (obj.items.type != null) {
598614
this.refDataType = obj.items.type;
@@ -638,7 +654,9 @@ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
638654

639655
SwaggerModelProperty.prototype.toSampleValue = function(value) {
640656
var result;
641-
if (value === "integer") {
657+
if ((typeof this.defaultValue !== 'undefined') && this.defaultValue !== null) {
658+
result = this.defaultValue;
659+
} else if (value === "integer") {
642660
result = 0;
643661
} else if (value === "boolean") {
644662
result = false;
@@ -768,6 +786,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
768786
}
769787
}
770788
}
789+
param.defaultValue = parameterMacro(param.defaultValue);
771790
}
772791
this.resource[this.nickname] = function(args, callback, error) {
773792
return _this["do"](args, callback, error);
@@ -1218,7 +1237,7 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12181237
// if there's a body, need to set the accepts header via requestContentType
12191238
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
12201239
if (this.opts.requestContentType)
1221-
accepts = this.opts.requestContentType;
1240+
consumes = this.opts.requestContentType;
12221241
} else {
12231242
// if any form params, content type must be set
12241243
if(definedFormParams.length > 0) {
@@ -1227,7 +1246,7 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12271246
else
12281247
consumes = "application/x-www-form-urlencoded";
12291248
}
1230-
else if (this.type == "DELETE")
1249+
else if (this.type === "DELETE")
12311250
body = "{}";
12321251
else if (this.type != "DELETE")
12331252
accepts = null;
@@ -1461,11 +1480,36 @@ ShredHttpClient.prototype.execute = function(obj) {
14611480
return out;
14621481
};
14631482

1483+
// Transform an error into a usable response-like object
1484+
var transformError = function(error) {
1485+
var out = {
1486+
// Default to a status of 0 - The client will treat this as a generic permissions sort of error
1487+
status: 0,
1488+
data: error.message || error
1489+
};
1490+
1491+
if(error.code) {
1492+
out.obj = error;
1493+
1494+
if(error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED' ) {
1495+
// We can tell the client that this should be treated as a missing resource and not as a permissions thing
1496+
out.status = 404;
1497+
}
1498+
}
1499+
1500+
return out;
1501+
};
1502+
14641503
res = {
14651504
error: function(response) {
14661505
if (obj)
14671506
return cb.error(transform(response));
14681507
},
1508+
// Catch the Shred error raised when the request errors as it is made (i.e. No Response is coming)
1509+
request_error: function(err) {
1510+
if(obj)
1511+
return cb.error(transformError(err));
1512+
},
14691513
redirect: function(response) {
14701514
if (obj)
14711515
return cb.redirect(transform(response));
@@ -1533,10 +1577,11 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
15331577
/**
15341578
* ApiKeyAuthorization allows a query param or header to be injected
15351579
*/
1536-
var ApiKeyAuthorization = function(name, value, type) {
1580+
var ApiKeyAuthorization = function(name, value, type, delimiter) {
15371581
this.name = name;
15381582
this.value = value;
15391583
this.type = type;
1584+
this.delimiter = delimiter;
15401585
};
15411586

15421587
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
@@ -1547,7 +1592,12 @@ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
15471592
obj.url = obj.url + "?" + this.name + "=" + this.value;
15481593
return true;
15491594
} else if (this.type === "header") {
1550-
obj.headers[this.name] = this.value;
1595+
if(typeof obj.headers[this.name] !== 'undefined') {
1596+
if(typeof this.delimiter !== 'undefined')
1597+
obj.headers[this.name] = obj.headers[this.name] + this.delimiter + this.value;
1598+
}
1599+
else
1600+
obj.headers[this.name] = this.value;
15511601
return true;
15521602
}
15531603
};

dist/swagger-ui.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-ui.js
2-
// version 2.0.22
2+
// version 2.0.23
33
$(function() {
44

55
// Helper function for vertically aligning DOM elements

lib/swagger.js

+60-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger.js
2-
// version 2.0.37
2+
// version 2.0.39
33

44
var __bind = function(fn, me){
55
return function(){
@@ -15,6 +15,16 @@ log = function(){
1515
}
1616
};
1717

18+
// if you want to apply conditional formatting of parameter values
19+
parameterMacro = function(value) {
20+
return value;
21+
}
22+
23+
// if you want to apply conditional formatting of model property values
24+
modelPropertyMacro = function(value) {
25+
return value;
26+
}
27+
1828
if (!Array.prototype.indexOf) {
1929
Array.prototype.indexOf = function(obj, start) {
2030
for (var i = (start || 0), j = this.length; i < j; i++) {
@@ -80,13 +90,15 @@ Object.keys = Object.keys || (function () {
8090
})();
8191

8292
var SwaggerApi = function(url, options) {
93+
this.isBuilt = false;
8394
this.url = null;
8495
this.debug = false;
8596
this.basePath = null;
8697
this.authorizations = null;
8798
this.authorizationScheme = null;
8899
this.info = null;
89100
this.useJQuery = false;
101+
this.modelsArray = [];
90102

91103
options = (options||{});
92104
if (url)
@@ -108,19 +120,23 @@ var SwaggerApi = function(url, options) {
108120

109121
this.failure = options.failure != null ? options.failure : function() {};
110122
this.progress = options.progress != null ? options.progress : function() {};
111-
if (options.success != null)
123+
if (options.success != null) {
112124
this.build();
125+
this.isBuilt = true;
126+
}
113127
}
114128

115129
SwaggerApi.prototype.build = function() {
130+
if(this.isBuilt)
131+
return this;
116132
var _this = this;
117133
this.progress('fetching resource list: ' + this.url);
118134
var obj = {
119135
useJQuery: this.useJQuery,
120136
url: this.url,
121137
method: "get",
122138
headers: {
123-
accept: "application/json"
139+
accept: "application/json,application/json;charset=\"utf-8\",*/*"
124140
},
125141
on: {
126142
error: function(response) {
@@ -276,7 +292,6 @@ SwaggerApi.prototype.fail = function(message) {
276292

277293
SwaggerApi.prototype.setConsolidatedModels = function() {
278294
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
279-
this.modelsArray = [];
280295
this.models = {};
281296
_ref = this.apis;
282297
for (resource_name in _ref) {
@@ -353,7 +368,7 @@ var SwaggerResource = function(resourceObj, api) {
353368
method: "get",
354369
useJQuery: this.useJQuery,
355370
headers: {
356-
accept: "application/json"
371+
accept: "application/json,application/json;charset=\"utf-8\",*/*"
357372
},
358373
on: {
359374
response: function(resp) {
@@ -593,6 +608,7 @@ var SwaggerModelProperty = function(name, obj) {
593608
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
594609
this.descr = obj.description;
595610
this.required = obj.required;
611+
this.defaultValue = modelPropertyMacro(obj.defaultValue);
596612
if (obj.items != null) {
597613
if (obj.items.type != null) {
598614
this.refDataType = obj.items.type;
@@ -638,7 +654,9 @@ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
638654

639655
SwaggerModelProperty.prototype.toSampleValue = function(value) {
640656
var result;
641-
if (value === "integer") {
657+
if ((typeof this.defaultValue !== 'undefined') && this.defaultValue !== null) {
658+
result = this.defaultValue;
659+
} else if (value === "integer") {
642660
result = 0;
643661
} else if (value === "boolean") {
644662
result = false;
@@ -768,6 +786,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
768786
}
769787
}
770788
}
789+
param.defaultValue = parameterMacro(param.defaultValue);
771790
}
772791
this.resource[this.nickname] = function(args, callback, error) {
773792
return _this["do"](args, callback, error);
@@ -1218,7 +1237,7 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12181237
// if there's a body, need to set the accepts header via requestContentType
12191238
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
12201239
if (this.opts.requestContentType)
1221-
accepts = this.opts.requestContentType;
1240+
consumes = this.opts.requestContentType;
12221241
} else {
12231242
// if any form params, content type must be set
12241243
if(definedFormParams.length > 0) {
@@ -1227,7 +1246,7 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12271246
else
12281247
consumes = "application/x-www-form-urlencoded";
12291248
}
1230-
else if (this.type == "DELETE")
1249+
else if (this.type === "DELETE")
12311250
body = "{}";
12321251
else if (this.type != "DELETE")
12331252
accepts = null;
@@ -1461,11 +1480,36 @@ ShredHttpClient.prototype.execute = function(obj) {
14611480
return out;
14621481
};
14631482

1483+
// Transform an error into a usable response-like object
1484+
var transformError = function(error) {
1485+
var out = {
1486+
// Default to a status of 0 - The client will treat this as a generic permissions sort of error
1487+
status: 0,
1488+
data: error.message || error
1489+
};
1490+
1491+
if(error.code) {
1492+
out.obj = error;
1493+
1494+
if(error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED' ) {
1495+
// We can tell the client that this should be treated as a missing resource and not as a permissions thing
1496+
out.status = 404;
1497+
}
1498+
}
1499+
1500+
return out;
1501+
};
1502+
14641503
res = {
14651504
error: function(response) {
14661505
if (obj)
14671506
return cb.error(transform(response));
14681507
},
1508+
// Catch the Shred error raised when the request errors as it is made (i.e. No Response is coming)
1509+
request_error: function(err) {
1510+
if(obj)
1511+
return cb.error(transformError(err));
1512+
},
14691513
redirect: function(response) {
14701514
if (obj)
14711515
return cb.redirect(transform(response));
@@ -1533,10 +1577,11 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
15331577
/**
15341578
* ApiKeyAuthorization allows a query param or header to be injected
15351579
*/
1536-
var ApiKeyAuthorization = function(name, value, type) {
1580+
var ApiKeyAuthorization = function(name, value, type, delimiter) {
15371581
this.name = name;
15381582
this.value = value;
15391583
this.type = type;
1584+
this.delimiter = delimiter;
15401585
};
15411586

15421587
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
@@ -1547,7 +1592,12 @@ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
15471592
obj.url = obj.url + "?" + this.name + "=" + this.value;
15481593
return true;
15491594
} else if (this.type === "header") {
1550-
obj.headers[this.name] = this.value;
1595+
if(typeof obj.headers[this.name] !== 'undefined') {
1596+
if(typeof this.delimiter !== 'undefined')
1597+
obj.headers[this.name] = obj.headers[this.name] + this.delimiter + this.value;
1598+
}
1599+
else
1600+
obj.headers[this.name] = this.value;
15511601
return true;
15521602
}
15531603
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-ui",
3-
"version": "2.0.22",
3+
"version": "2.0.24",
44
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
55
"scripts": {
66
"build": "PATH=$PATH:./node_modules/.bin cake dist",

0 commit comments

Comments
 (0)