Skip to content

Commit fd4d634

Browse files
authored
Merge pull request #152 from Icinga/fix/array_handling_for_validateset
Fix: Array handling for ValidateSet and array rendering for config generator Empty arrays will now properly be rendered as empty array with @()instead of $null. In addition the config renderer now also supports ValidateSet for array entries
2 parents f31ac25 + 5060dec commit fd4d634

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
3131
* [#138](https://github.com/Icinga/icinga-powershell-framework/issues/138) Fixes possible value overflow on `Convert-Bytes` while converting from anything larger than MB to Bytes
3232
* [#140](https://github.com/Icinga/icinga-powershell-framework/issues/140) Fixes version fetching for not loaded modules during upgrades/plugin calls with `Get-IcingaPowerShellModuleVersion`
3333
* [#143](https://github.com/Icinga/icinga-powershell-framework/issues/143) Fixes the annoying hint from the analyzer to check space before open brace
34+
* [#152](https://github.com/Icinga/icinga-powershell-framework/issues/152) Fixes incorrect rendering for empty arrays which used `$null` incorrectly instead of `@()` and fixed ValidateSet which now also supports arrays as data type
3435

3536
## 1.2.0 (2020-08-28)
3637

lib/core/tools/Get-IcingaCheckCommandConfig.psm1

+8-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function Get-IcingaCheckCommandConfig()
165165
'value' = @{
166166
'type' = 'Function';
167167
'body' = [string]::Format(
168-
'var arr = macro("{0}");{1}if (len(arr) == 0) {2}{1}return "$null";{1}{3}{1}return arr.join(",");',
168+
'var arr = macro("{0}");{1}if (len(arr) == 0) {2}{1}return "@()";{1}{3}{1}return arr.join(",");',
169169
$IcingaCustomVariable,
170170
"`r`n",
171171
'{',
@@ -259,10 +259,16 @@ function Get-IcingaCheckCommandConfig()
259259
);
260260

261261
if ($IsDataList) {
262+
[string]$DataListDataType = 'string';
263+
264+
if ($parameter.type.name -eq 'Array') {
265+
$DataListDataType = 'array';
266+
}
267+
262268
$Basket.Datafield[[string]$FieldID].Add(
263269
'settings', @{
264270
'datalist' = $DataListName;
265-
'data_type' = 'string';
271+
'data_type' = $DataListDataType;
266272
'behavior' = 'strict';
267273
}
268274
);

0 commit comments

Comments
 (0)