[Php] Convert boolean value for query string (Configuration) (#12385)

* convert bool to query string format

* add variable

* update samples

* add test
This commit is contained in:
Kuzma
2022-05-25 05:36:21 +03:00
committed by GitHub
parent 4ec14706df
commit 45cbd5f7a7
5 changed files with 150 additions and 0 deletions

View File

@@ -219,12 +219,32 @@ class ObjectSerializer
return $value;
}
if ('boolean' === $openApiType && is_bool($value)) {
$value = self::convertBoolToQueryStringFormat($value);
}
// handle style in serializeCollection
$query[$paramName] = ($explode) ? $value : self::serializeCollection((array)$value, $style);
return $query;
}
/**
* Convert boolean value to format for query string.
*
* @param bool $value Boolean value
*
* @return int|string Boolean value in format
*/
public static function convertBoolToQueryStringFormat(bool $value)
{
if (Configuration::BOOLEAN_FORMAT_STRING == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
return $value ? 'true' : 'false';
}
return (int) $value;
}
/**
* Take value and turn it into a string suitable for inclusion in
* the header. If it's a string, pass through unchanged