Skip to content

Commit f78b2c6

Browse files
Merge pull request #58 from okta/TriggerAu-Bug_JSONHelperArrayFix
Fix "Remove-NullProperties function in JsonHelper.ps1 causes error that the request body was not well-formed"
2 parents 036dde3 + d928a29 commit f78b2c6

File tree

8 files changed

+109
-14
lines changed

8 files changed

+109
-14
lines changed

Build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ $Manifest = @{
6161
ReleaseNotes = 'https://github.com/okta/okta-powershell-cli/releases'
6262

6363

64-
ModuleVersion = '1.0.2'
64+
ModuleVersion = '1.0.3'
6565

6666

6767
RootModule = 'Okta.PowerShell.psm1'
68-
Guid = '{74F58D24-72C5-4A88-AF6D-204B1DE897A5}' # Has to be static, otherwise each new build will be considered different module
68+
Guid = '{5E82B81C-92D5-47BC-A10F-E26B40081903}' # Has to be static, otherwise each new build will be considered different module
6969

7070
PowerShellVersion = '6.2'
7171

openapi3/codegen-templates/json_helper.mustache

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ function Remove-NullProperties {
2626
$PropertyList = $InputObject.PSObject.Properties | Where-Object { $null -ne $_.Value }
2727

2828
foreach ($Property in $PropertyList) {
29-
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
29+
if($Property.Value -is [array]){
30+
# explicit cast to avoid arrays to be converted to object (i.e @('foo'))
31+
$NewObject[$Property.Name] = Remove-NullPropertiesFromArray $Property.Value
32+
}else{
33+
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
34+
}
3035
}
3136
}
3237

@@ -62,7 +67,6 @@ function Remove-NullPropertiesFromHashMap{
6267
}
6368

6469
# Remove null properties from an array recursively
65-
6670
function Remove-NullPropertiesFromArray {
6771
[CmdletBinding()]
6872
param(
@@ -78,5 +82,7 @@ function Remove-NullPropertiesFromArray {
7882
$NewArray += $NewItem
7983
}
8084

81-
return $NewArray
85+
#https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#comma-operator-
86+
# Ensure the return is always an array, even if there's only one item
87+
return ,$NewArray
8288
}

openapi3/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"templateDir": "./codegen-templates",
1515
"outputDir" : "../",
1616
"inputSpec" : "./management.yaml",
17-
"packageVersion" : "1.0.2",
17+
"packageVersion" : "1.0.3",
1818
"packageDescription" : "Official PowerShell CLI for the Okta API",
1919
"packageTitle" : "Official PowerShell for the Okta API",
2020
"packageCompany" : "Okta, Inc.",

src/Okta.PowerShell/Client/JsonHelper.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ function Remove-NullProperties {
3333
$PropertyList = $InputObject.PSObject.Properties | Where-Object { $null -ne $_.Value }
3434

3535
foreach ($Property in $PropertyList) {
36-
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
36+
if($Property.Value -is [array]){
37+
# explicit cast to avoid arrays to be converted to object (i.e @('foo'))
38+
$NewObject[$Property.Name] = Remove-NullPropertiesFromArray $Property.Value
39+
}else{
40+
$NewObject[$Property.Name] = Remove-NullProperties $Property.Value
41+
}
3742
}
3843
}
3944

@@ -69,7 +74,6 @@ function Remove-NullPropertiesFromHashMap{
6974
}
7075

7176
# Remove null properties from an array recursively
72-
7377
function Remove-NullPropertiesFromArray {
7478
[CmdletBinding()]
7579
param(
@@ -85,5 +89,7 @@ function Remove-NullPropertiesFromArray {
8589
$NewArray += $NewItem
8690
}
8791

88-
return $NewArray
92+
#https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#comma-operator-
93+
# Ensure the return is always an array, even if there's only one item
94+
return ,$NewArray
8995
}

src/Okta.PowerShell/Okta.PowerShell.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
RootModule = 'Okta.PowerShell.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.2'
15+
ModuleVersion = '1.0.3'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
1919

2020
# ID used to uniquely identify this module
21-
GUID = '74f58d24-72c5-4a88-af6d-204b1de897a5'
21+
GUID = '5e82b81c-92d5-47bc-a10f-e26b40081903'
2222

2323
# Author of this module
2424
Author = 'Okta, Inc.'

src/Okta.PowerShell/Private/OktaApiClient.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Invoke-OktaApiClient {
131131
}
132132
}
133133

134-
$OktaUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome + " okta-powershell-module/1.0.2"
134+
$OktaUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome + " okta-powershell-module/1.0.3"
135135

136136

137137
# Setting up vars for retry

src/Okta.PowerShell/en-US/about_Okta.PowerShell.help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LONG DESCRIPTION
1010
This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
1111

1212
- API version: 3.0.0
13-
- SDK version: 1.0.2
13+
- SDK version: 1.0.3
1414
- Build package: org.openapitools.codegen.languages.PowerShellClientCodegen
1515
For more information, please visit [https://developer.okta.com/](https://developer.okta.com/)
1616

tests/Client/JsonHelper.Tests.ps1

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Context 'Remove-NullProperties' {
4545
Get-Member -inputobject $CleanedJsonObject.details.children[0] -name "name" -MemberType Properties | Should -Be -Not $null
4646
}
4747

48-
It 'Should maintain the same object when there''s no null values'{
48+
It 'Should maintain the same object when there''s no null values in a single-item array'{
49+
# GroupIds - 1 item array
4950
$NewGroupRule = [PSObject]@{
5051
name = "Assign users to the Sales Team"
5152
type = "group_rule"
@@ -63,4 +64,86 @@ Context 'Remove-NullProperties' {
6364
$CleanedRule.actions.assignUserToGroups.groupIds.Count | Should -Be 1
6465
$CleanedRule.actions.assignUserToGroups.groupIds[0] | Should -Be "foo"
6566
}
67+
68+
It 'Should maintain the same object when there''s no null values in a multiple-items array'{
69+
# GroupIds - multiple-items array
70+
$NewGroupRule = [PSObject]@{
71+
name = "Assign users to the Sales Team"
72+
type = "group_rule"
73+
actions = [PSObject]@{
74+
assignUserToGroups = [PSObject]@{
75+
groupIds = [array]@('foo', 'bar', 'baz')
76+
}
77+
}
78+
}
79+
80+
$CleanedRule = Remove-NullProperties $NewGroupRule
81+
82+
$CleanedRule.name | Should -Be "Assign users to the Sales Team"
83+
$CleanedRule.type | Should -Be "group_rule"
84+
$CleanedRule.actions.assignUserToGroups.groupIds.Count | Should -Be 3
85+
$CleanedRule.actions.assignUserToGroups.groupIds[0] | Should -Be "foo"
86+
$CleanedRule.actions.assignUserToGroups.groupIds[1] | Should -Be "bar"
87+
$CleanedRule.actions.assignUserToGroups.groupIds[2] | Should -Be "baz"
88+
}
89+
90+
It 'Should maintain the same object when there''s no null values in a single-item array when using initializers'{
91+
# GroupIds - 1 item array
92+
$GroupRuleGroupAssignment = Initialize-OktaGroupRuleGroupAssignment -GroupIds ([array]@("foo"))
93+
94+
$GroupRuleAction = Initialize-OktaGroupRuleAction -AssignUserToGroups $GroupRuleGroupAssignment
95+
96+
$GroupRuleExpression = Initialize-OktaGroupRuleExpression -Type "urn:okta:expression:1.0" -Value "user.title=='Sales Representative'"
97+
98+
$GroupRuleConditions = Initialize-OktaGroupRuleConditions -Expression $GroupRuleExpression
99+
100+
$NewGroupRule = Initialize-OktaGroupRule -Actions $GroupRuleAction -Conditions $GroupRuleConditions -Name "Assign users to the Sales Team" -Type "group_rule"
101+
102+
$CleanedRule = Remove-NullProperties $NewGroupRule
103+
104+
$CleanedRule.name | Should -Be "Assign users to the Sales Team"
105+
$CleanedRule.type | Should -Be "group_rule"
106+
$CleanedRule.actions.assignUserToGroups.groupIds.Count | Should -Be 1
107+
$CleanedRule.actions.assignUserToGroups.groupIds[0] | Should -Be "foo"
108+
}
109+
110+
It 'Should maintain the same object when there''s no null values in a multiple-items array when using initializers'{
111+
# GroupIds - 1 item array
112+
$GroupRuleGroupAssignment = Initialize-OktaGroupRuleGroupAssignment -GroupIds ([array]@("foo"))
113+
114+
$GroupRuleAction = Initialize-OktaGroupRuleAction -AssignUserToGroups $GroupRuleGroupAssignment
115+
116+
$GroupRuleExpression = Initialize-OktaGroupRuleExpression -Type "urn:okta:expression:1.0" -Value "user.title=='Sales Representative'"
117+
118+
$GroupRuleConditions = Initialize-OktaGroupRuleConditions -Expression $GroupRuleExpression
119+
120+
$NewGroupRule = Initialize-OktaGroupRule -Actions $GroupRuleAction -Conditions $GroupRuleConditions -Name "Assign users to the Sales Team" -Type "group_rule"
121+
122+
$CleanedRule = Remove-NullProperties $NewGroupRule
123+
124+
$CleanedRule.name | Should -Be "Assign users to the Sales Team"
125+
$CleanedRule.type | Should -Be "group_rule"
126+
$CleanedRule.actions.assignUserToGroups.groupIds.Count | Should -Be 1
127+
$CleanedRule.actions.assignUserToGroups.groupIds[0] | Should -Be "foo"
128+
129+
# GroupIds - 1 multiple-items array
130+
$GroupRuleGroupAssignment = Initialize-OktaGroupRuleGroupAssignment -GroupIds ([array]@("foo", "bar", "baz"))
131+
132+
$GroupRuleAction = Initialize-OktaGroupRuleAction -AssignUserToGroups $GroupRuleGroupAssignment
133+
134+
$GroupRuleExpression = Initialize-OktaGroupRuleExpression -Type "urn:okta:expression:1.0" -Value "user.title=='Sales Representative'"
135+
136+
$GroupRuleConditions = Initialize-OktaGroupRuleConditions -Expression $GroupRuleExpression
137+
138+
$NewGroupRule = Initialize-OktaGroupRule -Actions $GroupRuleAction -Conditions $GroupRuleConditions -Name "Assign users to the Sales Team" -Type "group_rule"
139+
140+
$CleanedRule = Remove-NullProperties $NewGroupRule
141+
142+
$CleanedRule.name | Should -Be "Assign users to the Sales Team"
143+
$CleanedRule.type | Should -Be "group_rule"
144+
$CleanedRule.actions.assignUserToGroups.groupIds.Count | Should -Be 3
145+
$CleanedRule.actions.assignUserToGroups.groupIds[0] | Should -Be "foo"
146+
$CleanedRule.actions.assignUserToGroups.groupIds[1] | Should -Be "bar"
147+
$CleanedRule.actions.assignUserToGroups.groupIds[2] | Should -Be "baz"
148+
}
66149
}

0 commit comments

Comments
 (0)