diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache index aec98f8b9e8..9c57c887441 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache @@ -188,6 +188,9 @@ class ObjectSerializer # For boolean values, '' is considered empty 'bool','boolean' => !in_array($value, [false, 0], true), + # For string values, '' is considered empty. + 'string' => $value === '', + # For all the other types, any value at this point can be considered empty. default => true }; diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index a126b346ebc..00aeea6cbcc 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -185,6 +185,10 @@ class ObjectSerializer case 'boolean': return !in_array($value, [false, 0], true); + # For string values, '' is considered empty. + case 'string': + return $value === ''; + # For all the other types, any value at this point can be considered empty. default: return true; diff --git a/samples/client/echo_api/php-nextgen-streaming/src/ObjectSerializer.php b/samples/client/echo_api/php-nextgen-streaming/src/ObjectSerializer.php index 3dfd7c05f58..e75e7b623e0 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/ObjectSerializer.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/ObjectSerializer.php @@ -198,6 +198,9 @@ class ObjectSerializer # For boolean values, '' is considered empty 'bool','boolean' => !in_array($value, [false, 0], true), + # For string values, '' is considered empty. + 'string' => $value === '', + # For all the other types, any value at this point can be considered empty. default => true }; diff --git a/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php b/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php index 3dfd7c05f58..e75e7b623e0 100644 --- a/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php +++ b/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php @@ -198,6 +198,9 @@ class ObjectSerializer # For boolean values, '' is considered empty 'bool','boolean' => !in_array($value, [false, 0], true), + # For string values, '' is considered empty. + 'string' => $value === '', + # For all the other types, any value at this point can be considered empty. default => true }; diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php index 9e46385b4c7..ad81c50c69d 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php @@ -197,6 +197,9 @@ class ObjectSerializer # For boolean values, '' is considered empty 'bool','boolean' => !in_array($value, [false, 0], true), + # For string values, '' is considered empty. + 'string' => $value === '', + # For all the other types, any value at this point can be considered empty. default => true }; diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index a02f072f66b..03f89f0bcad 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -194,6 +194,10 @@ class ObjectSerializer case 'boolean': return !in_array($value, [false, 0], true); + # For string values, '' is considered empty. + case 'string': + return $value === ''; + # For all the other types, any value at this point can be considered empty. default: return true; diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php index 4ca73b37565..dc71cd108b8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php @@ -430,6 +430,9 @@ class ObjectSerializerTest extends TestCase 'form 0 bool, explode on, required false' => [ 0, 'field', 'bool', 'form', true, false, 'field=0', ], + 'form string "0", explode on, required true' => [ + '0', 'field', 'string', 'form', true, true, 'field=0', + ], ]; } diff --git a/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php b/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php index a02f072f66b..03f89f0bcad 100644 --- a/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php @@ -194,6 +194,10 @@ class ObjectSerializer case 'boolean': return !in_array($value, [false, 0], true); + # For string values, '' is considered empty. + case 'string': + return $value === ''; + # For all the other types, any value at this point can be considered empty. default: return true;