fix(php): no need to serialize collections, Guzzle does that, fix #2292 (#3984)

* fix(php): only serialize collections if !explode, Guzzle handles the rest, fix #2292

* fix(php): update petstore samples

Co-authored-by: Mahdi Dibaiee <mdibaiee@pm.me>
This commit is contained in:
copypasta-g
2020-03-04 05:53:30 +03:30
committed by GitHub
parent 33129ca104
commit 3e5fb670e2
17 changed files with 246 additions and 64 deletions

View File

@@ -219,23 +219,26 @@ class ObjectSerializer
*
* @return string
*/
public static function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti = false)
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false)
{
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
// http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
}
switch ($collectionFormat) {
switch ($style) {
case 'pipeDelimited':
case 'pipes':
return implode('|', $collection);
case 'tsv':
return implode("\t", $collection);
case 'spaceDelimited':
case 'ssv':
return implode(' ', $collection);
case 'simple':
case 'csv':
// Deliberate fall through. CSV is default format.
default: