Merge branch 'multi-value-params' of ssh://github.com/valdemon/swagger-ui into valdemon-multi-value-params
This commit is contained in:
@@ -4,4 +4,25 @@ Handlebars.registerHelper('sanitize', function(html) {
|
||||
// Strip the script tags from the html, and return it as a Handlebars.SafeString
|
||||
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
|
||||
return new Handlebars.SafeString(html);
|
||||
});
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('renderTextParam', function(param) {
|
||||
var result;
|
||||
var isArray = param.type.toLowerCase() === 'array' || param.allowMultiple;
|
||||
var defaultValue = isArray && Array.isArray(param.default) ? param.default.join('\n') : param.default;
|
||||
|
||||
if (typeof defaultValue === 'undefined') {
|
||||
defaultValue = '';
|
||||
}
|
||||
|
||||
if(isArray) {
|
||||
result = '<textarea class=\'body-textarea' + (param.required ? ' required' : '') + '\' name=\'' + param.name + '\'';
|
||||
result += ' placeholder=\'Provide multiple values in new lines' + (param.required ? ' (at least one required).' : '.') + '\'>';
|
||||
result += defaultValue + '</textarea>';
|
||||
} else {
|
||||
result = '<input class=\'parameter\'' + (param.required ? ' class=\'required\'' : '') + ' minlength=\'' + (param.required ? 1 : 0) + '\'';
|
||||
result += ' name=\'' + param.name +'\' placeholder=\'' + (param.required ? '(required)' : '') + '\'';
|
||||
result += ' type=\'text\' value=\'' + defaultValue + '\'/>';
|
||||
}
|
||||
return new Handlebars.SafeString(result);
|
||||
});
|
||||
|
||||
@@ -275,6 +275,20 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
||||
error_free = false;
|
||||
}
|
||||
});
|
||||
form.find('select.required').each(function() {
|
||||
$(this).removeClass('error');
|
||||
if (this.selectedIndex === -1) {
|
||||
$(this).addClass('error');
|
||||
$(this).wiggle({
|
||||
callback: (function(_this) {
|
||||
return function() {
|
||||
$(_this).focus();
|
||||
};
|
||||
})(this)
|
||||
});
|
||||
error_free = false;
|
||||
}
|
||||
});
|
||||
if (error_free) {
|
||||
map = {};
|
||||
opts = {
|
||||
@@ -295,8 +309,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
||||
ref2 = form.find('textarea');
|
||||
for (m = 0, len1 = ref2.length; m < len1; m++) {
|
||||
o = ref2[m];
|
||||
if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
|
||||
map[o.name] = o.value;
|
||||
val = this.getTextAreaValue(o);
|
||||
if ((val !== null) && jQuery.trim(val).length > 0) {
|
||||
map[o.name] = val;
|
||||
}
|
||||
}
|
||||
ref3 = form.find('select');
|
||||
@@ -666,5 +681,38 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
||||
} else {
|
||||
Docs.expandOperation(elem);
|
||||
}
|
||||
},
|
||||
|
||||
getTextAreaValue: function(textArea) {
|
||||
var param, parsed, result, i;
|
||||
if (textArea.value === null || jQuery.trim(textArea.value).length === 0) {
|
||||
return null;
|
||||
}
|
||||
param = this.getParamByName(textArea.name);
|
||||
if (param && param.type && param.type.toLowerCase() === 'array') {
|
||||
parsed = textArea.value.split('\n');
|
||||
result = [];
|
||||
for (i = 0; i < parsed.length; i++) {
|
||||
if (parsed[i] !== null && jQuery.trim(parsed[i]).length > 0) {
|
||||
result.push(parsed[i]);
|
||||
}
|
||||
}
|
||||
return result.length > 0 ? result : null;
|
||||
} else {
|
||||
return textArea.value;
|
||||
}
|
||||
},
|
||||
|
||||
getParamByName: function(name) {
|
||||
var i;
|
||||
if (this.model.parameters) {
|
||||
for(i = 0; i < this.model.parameters.length; i++) {
|
||||
if (this.model.parameters[i].name === name) {
|
||||
return this.model.parameters[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user