Skip to content

Commit eb00c2f

Browse files
[PHP] Correctly serialize php arrays
Use json_encode for php arrays, so they can be used as the root type in a json request body.
1 parent f41683a commit eb00c2f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

modules/swagger-codegen/src/main/resources/php/api.mustache

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,16 @@ use {{invokerPackage}}\ObjectSerializer;
426426
if (isset($_tempBody)) {
427427
// $_tempBody is the method argument, if present
428428
$httpBody = $_tempBody;
429-
// \stdClass has no __toString(), so we should encode it manually
430-
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
431-
$httpBody = \GuzzleHttp\json_encode($httpBody);
429+
430+
if($headers['Content-Type'] === 'application/json') {
431+
// \stdClass has no __toString(), so we should encode it manually
432+
if ($httpBody instanceof \stdClass) {
433+
$httpBody = \GuzzleHttp\json_encode($httpBody);
434+
}
435+
// array has no __toString(), so we should encode it manually
436+
if(is_array($httpBody)) {
437+
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
438+
}
432439
}
433440
} elseif (count($formParams) > 0) {
434441
if ($multipart) {

0 commit comments

Comments
 (0)