forked from loafle/openapi-generator-original
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user