Skip to content

Commit

Permalink
Add forced casting for Arrays in Remove-NullProperties (#50)
Browse files Browse the repository at this point in the history
This adds a forced cast inside the method that prevents Powershell from
converting a single valued array to an object.

This pr does not include changes to the test methods as Im not sure how
the team would intend the use case to be tested

Its a revisit on #35

Signed-off-by: Laura Rodriguez <rdz.maria.laura@gmail.com>
  • Loading branch information
TriggerAu authored and laura-rodriguez committed Oct 30, 2024
1 parent b01fd0a commit d3d8fc5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Okta.PowerShell/Client/JsonHelper.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# Okta Management
# Allows customers to easily access the Okta Management APIs
# Version: 3.0.0
# Contact: devex-public@okta.com
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
#
# Okta Management
# Allows customers to easily access the Okta Management APIs
# Version: 3.0.0
# Contact: devex-public@okta.com
# Generated by OpenAPI Generator: https://openapi-generator.tech
#


# Remove null properties from an object recursively
Expand Down Expand Up @@ -33,7 +33,12 @@ function Remove-NullProperties {
$PropertyList = $InputObject.PSObject.Properties | Where-Object { $null -ne $_.Value }

foreach ($Property in $PropertyList) {
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
if($Property.Value -is [array]){
# explicit cast to avoid arrays to be converted to object (i.e @('foo'))
$NewObject[$Property.Name] = [array]@(Remove-NullProperties $Property.Value)
}else{
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
}
}
}

Expand Down

0 comments on commit d3d8fc5

Please sign in to comment.