Skip to content

Commit

Permalink
Added depth parameter to win_uri ConvertTo-Json call (#587)
Browse files Browse the repository at this point in the history
Added depth parameter to win_uri ConvertTo-Json call
  • Loading branch information
thomasriera-akkodis authored Mar 6, 2024
1 parent c207ed4 commit b02f66c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/PR-587-Fix-win_uri-json-depth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- win_uri - Max depth for json object conversion used to be 2. Can now send json objects with up to 20 levels of nesting
2 changes: 1 addition & 1 deletion plugins/modules/win_uri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ $response_script = {
$body_st = $null
if ($null -ne $body) {
if ($body -is [System.Collections.IDictionary] -or $body -is [System.Collections.IList]) {
$body_string = ConvertTo-Json -InputObject $body -Compress
$body_string = ConvertTo-Json -InputObject $body -Compress -Depth 20
}
elseif ($body -isnot [String]) {
$body_string = $body.ToString()
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/targets/win_uri/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,52 @@
- not json_as_dict.changed
- json_as_dict.json.json == json_as_dict_value
- json_as_dict.status_code == 200

- name: send JSON body with multiple levels of nesting
win_uri:
url: https://{{httpbin_host}}/post
method: POST
body:
foo: bar
list:
- 1
- 2
dict:
foo: bar
dict:
foo: bar
dict:
foo: bar
dict:
foo: bar
headers:
'Content-Type': 'text/json'
return_content: yes
register: nested_json_as_dict

- name: set fact of expected json dict
set_fact:
nested_json_as_dict_value:
foo: bar
list:
- 1
- 2
dict:
foo: bar
dict:
foo: bar
dict:
foo: bar
dict:
foo: bar

- name: assert send JSON body with multiple levels of nesting
assert:
that:
- not nested_json_as_dict.changed
- nested_json_as_dict.json.json == nested_json_as_dict_value
- nested_json_as_dict.status_code == 200


- name: send JSON body with 1 item in list
win_uri:
Expand Down

0 comments on commit b02f66c

Please sign in to comment.