Multiple values for array type parameters as separated lines in the textarea.
Improved required parameter handling for the array type. Improved default value handling for the array type.
This commit is contained in:
@@ -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');
|
||||
@@ -661,5 +676,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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -4,9 +4,9 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
|
||||
initialize: function(){
|
||||
Handlebars.registerHelper('isArray', function(param, opts) {
|
||||
if (param.type.toLowerCase() === 'array' || param.allowMultiple) {
|
||||
opts.fn(this);
|
||||
return opts.fn(this);
|
||||
} else {
|
||||
opts.inverse(this);
|
||||
return opts.inverse(this);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user