Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-71) Fix type def of props with optional nested cim instances #78

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Function Get-DscResourceParameterInfoByCimClass {

# Similarly to how the properties were resolved for embedded CIM instances, resolve them for each property
ForEach($Property in $DscResourceCimClassProperties) {
$IsMandatory = $Property.Flags -Match '(Required|Key)'
$DscResourceMetadata.$($Property.Name) = [ordered]@{
Name = $Property.Name.ToLowerInvariant()
# The one thing we *can't* retrieve here is the default values; they still apply, but they're
Expand All @@ -103,8 +104,8 @@ Function Get-DscResourceParameterInfoByCimClass {
DefaultValue = $null
Help = $Property.Qualifiers['Description'].Value
is_namevar = ($Property.Flags -Match 'Key').ToString().ToLowerInvariant()
mandatory_for_get = ($Property.Flags -Match '(Required|Key)').ToString().ToLowerInvariant()
mandatory_for_set = ($Property.Flags -Match '(Required|Key)').ToString().ToLowerInvariant()
mandatory_for_get = $IsMandatory.ToString().ToLowerInvariant()
mandatory_for_set = $IsMandatory.ToString().ToLowerInvariant()
mof_is_embedded = 'false'
}
If ($Property.ReferenceClassName -in $DefinedEmbeddedInstances.Keys) {
Expand All @@ -123,9 +124,15 @@ Function Get-DscResourceParameterInfoByCimClass {
Where-Object -FilterScript {$_ -notmatch "cim_instance_type => '$($Property.ReferenceClassName)'"}
# Recombine the struct definition appropriately mapped as an array or singleton
If ($Property.CimType -match 'Array') {
$DscResourceMetadata.$($Property.Name).Type = """Array[$($SplitDefinition -Join "`n")]"""
$PuppetType = "Array[$($SplitDefinition -Join "`n")]"
$DscResourceMetadata.$($Property.Name).Type
} Else {
$DscResourceMetadata.$($Property.Name).Type = """$($SplitDefinition -Join "`n")"""
$PuppetType = "$($SplitDefinition -Join "`n")"
}
If ($IsMandatory -or ($PuppetType -match '^Optional\[')) {
$DscResourceMetadata.$($Property.Name).Type = """$PuppetType"""
} Else {
$DscResourceMetadata.$($Property.Name).Type = """Optional[$PuppetType]"""
}
} Else {
$DscResourceMetadata.$($Property.Name).mof_type = $Property.CimType -Replace '(\S+)Array$','$1[]'
Expand Down