diff --git a/changelogs/fragments/PR-587-Fix-win_uri-json-depth.yaml b/changelogs/fragments/PR-587-Fix-win_uri-json-depth.yaml new file mode 100644 index 00000000..292c3dfc --- /dev/null +++ b/changelogs/fragments/PR-587-Fix-win_uri-json-depth.yaml @@ -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 diff --git a/plugins/modules/win_uri.ps1 b/plugins/modules/win_uri.ps1 index 6106120e..987d54f7 100644 --- a/plugins/modules/win_uri.ps1 +++ b/plugins/modules/win_uri.ps1 @@ -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() diff --git a/tests/integration/targets/win_uri/tasks/main.yml b/tests/integration/targets/win_uri/tasks/main.yml index c94f30c2..8d18464b 100644 --- a/tests/integration/targets/win_uri/tasks/main.yml +++ b/tests/integration/targets/win_uri/tasks/main.yml @@ -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: