From 532c6ae83b1e212b719dc3b568d40a300e1308d1 Mon Sep 17 00:00:00 2001 From: Patrik Foldes Date: Fri, 3 Jul 2020 19:15:03 +0300 Subject: [PATCH] Fixed type conversion from bool to string (#73) --- src/Types/ScalarTypesResolver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Types/ScalarTypesResolver.php b/src/Types/ScalarTypesResolver.php index f3fd8de..330d1d9 100644 --- a/src/Types/ScalarTypesResolver.php +++ b/src/Types/ScalarTypesResolver.php @@ -6,6 +6,7 @@ use cebe\openapi\spec\Type; +use function is_string; use function Safe\settype; class ScalarTypesResolver @@ -87,8 +88,12 @@ public function convert(bool $deserialize, int $id, $value) } if ($deserialize) { - /** phpcs:disable Generic.PHP.ForbiddenFunctions.Found */ - settype($value, $format['phpType']); + if (is_string($value) && $format['phpType'] === 'bool') { + $value = $value === 'true'; + } else { + /** phpcs:disable Generic.PHP.ForbiddenFunctions.Found */ + settype($value, $format['phpType']); + } } return $value;