From 4caf0d855e196e2b37243ce1ac40bf7bfa293fa8 Mon Sep 17 00:00:00 2001 From: Pier-Paolo Mammi Date: Tue, 30 Jun 2026 12:19:11 +0200 Subject: [PATCH] add warning message for unparseable JSON in body data --- scripts/generate-http-docs.ps1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/generate-http-docs.ps1 b/scripts/generate-http-docs.ps1 index 9f0821c..7100634 100644 --- a/scripts/generate-http-docs.ps1 +++ b/scripts/generate-http-docs.ps1 @@ -113,11 +113,11 @@ function Parse-HttpBlock($text) { } return @{ - method = $http.method - url = $http.url - params = $http.params + method = $http.method + url = $http.url + params = $http.params headers = $headers - body = $http.body + body = $http.body } } @@ -238,8 +238,17 @@ function Build-RequestContent($http, $name, $config, $dotenvVars) { } if ($http.body) { - $lines += "" - $lines += ($http.body.data | ConvertTo-Json -Depth 10) + if ($http.body.type -eq 'json') { + $lines += "" + try { + $lines += ($http.body.data | ConvertFrom-Json -Depth 10 | ConvertTo-Json -Depth 10) + } + catch { + <#Do this if a terminating exception happens#> + Write-Warning "Failed to parse JSON for request $name, will use original content" + $lines += $http.body.data + } + } } return ($lines -join "`n")