From 905e59c238c5648fdfd4cfdc40f487a8b7210586 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Mon, 14 Feb 2022 03:38:16 -0600 Subject: [PATCH] [PHP] Allows passing filename to deserialize (#11582) * Allows passing filename to deserialize * Code review changes --- .../src/main/resources/php/ObjectSerializer.mustache | 3 +++ .../php/OpenAPIClient-php/lib/ObjectSerializer.php | 3 +++ .../php/OpenAPIClient-php/tests/ObjectSerializerTest.php | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 7d48d3557c34..61b146fd9d92 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -20,6 +20,7 @@ namespace {{invokerPackage}}; use {{modelPackage}}\ModelInterface; +use GuzzleHttp\Psr7\Utils; /** * ObjectSerializer Class Doc Comment @@ -337,6 +338,8 @@ class ObjectSerializer } if ($class === '\SplFileObject') { + $data = Utils::streamFor($data); + /** @var \Psr\Http\Message\StreamInterface $data */ // determine file name diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 840e4d934149..9bd27f580625 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -29,6 +29,7 @@ namespace OpenAPI\Client; use OpenAPI\Client\Model\ModelInterface; +use GuzzleHttp\Psr7\Utils; /** * ObjectSerializer Class Doc Comment @@ -346,6 +347,8 @@ class ObjectSerializer } if ($class === '\SplFileObject') { + $data = Utils::streamFor($data); + /** @var \Psr\Http\Message\StreamInterface $data */ // determine file name diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php index 9c4e86d5bf1e..bb919ffaa668 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php @@ -4,7 +4,6 @@ namespace OpenAPI\Client; use GuzzleHttp\Psr7\Utils; use PHPUnit\Framework\TestCase; -use Psr\Http\Message\StreamInterface; // test object serializer class ObjectSerializerTest extends TestCase @@ -34,7 +33,7 @@ class ObjectSerializerTest extends TestCase * @covers ObjectSerializer::serialize * @dataProvider provideFileStreams */ - public function testDeserializeFile(StreamInterface $stream, ?array $httpHeaders = null, ?string $expectedFilename = null): void + public function testDeserializeFile($stream, ?array $httpHeaders = null, ?string $expectedFilename = null): void { $s = new ObjectSerializer(); @@ -62,6 +61,11 @@ class ObjectSerializerTest extends TestCase ['Content-Disposition' => 'inline; filename=\'foobar.php\''], 'foobar.php', ], + 'File path' => [ + __FILE__, + null, + null, + ], ]; }