Skip to content

Commit

Permalink
Fix model deepObject serialization for PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
pylafleur committed Nov 4, 2024
1 parent a1f00ef commit bf56181
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace {{invokerPackage}};

use GuzzleHttp\Psr7\Utils;
use {{modelPackage}}\ModelInterface;
use JsonSerializable;

/**
* ObjectSerializer Class Doc Comment
Expand Down Expand Up @@ -231,7 +232,11 @@ class ObjectSerializer
}
$query = [];
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;
// Models are cast to arrays using json encode/decode to properly sanitize
// values and recursively handle nested objects
if (in_array($openApiType, ['object', 'array'], true)) {
$value = ($value instanceof JsonSerializable) ? json_decode(json_encode($value), true) : (array)$value;
}
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
// need to flatten array first
Expand Down

0 comments on commit bf56181

Please sign in to comment.