From 103eaf23f585127ecc430d08506c2660219491b1 Mon Sep 17 00:00:00 2001
From: Pascal Krason
Date: Wed, 7 May 2025 19:47:03 +0200
Subject: [PATCH] php/api.mustache: Fix missing body decoding before
deserialization for exception
Fixes an issue where the response body was not decoded before attempting to deserialize it into a model when an exception (non-2xx HTTP response) occurs.
Previously, the raw response body stream was passed directly to the deserializer inside the `ApiException` handling block, which caused deserialization to fail for structured response types (e.g. JSON).
This patch ensures that the body content is read and decoded (JSON-decoded if applicable) before passing it to `ObjectSerializer::deserialize()`, mirroring the successful response handling logic.
---
src/main/resources/handlebars/php/api.mustache | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/resources/handlebars/php/api.mustache b/src/main/resources/handlebars/php/api.mustache
index 428a38677e..d3793564a7 100644
--- a/src/main/resources/handlebars/php/api.mustache
+++ b/src/main/resources/handlebars/php/api.mustache
@@ -182,8 +182,13 @@ use {{invokerPackage}}\ObjectSerializer;
{{#responses}}
{{#dataType}}
{{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}}
+ $content = $e->getResponseBody();
+ if ('{{dataType}}' !== 'string' && '{{dataType}}' !== '\SplFileObject') {
+ $content = json_decode($content);
+ }
+
$data = ObjectSerializer::deserialize(
- $e->getResponseBody(),
+ $content,
'{{dataType}}',
$e->getResponseHeaders()
);