From c40e345666a06abc13758a5bb619d3098171da01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 16 Mar 2023 18:36:22 +0100 Subject: [PATCH] Fix blank line afweter if in Headers generation --- src/CodeGenerator/src/Generator/InputGenerator.php | 14 +++++++++----- src/Service/S3/src/Input/CopyObjectRequest.php | 3 ++- .../S3/src/Input/CreateMultipartUploadRequest.php | 3 ++- src/Service/S3/src/Input/PutObjectRequest.php | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/CodeGenerator/src/Generator/InputGenerator.php b/src/CodeGenerator/src/Generator/InputGenerator.php index a83ae752d..223d5f74b 100644 --- a/src/CodeGenerator/src/Generator/InputGenerator.php +++ b/src/CodeGenerator/src/Generator/InputGenerator.php @@ -306,7 +306,8 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild $body['querystring'] = '$query = [];' . "\n"; $usesEndpointDiscovery = $operation->usesEndpointDiscovery(); - foreach (['header' => '$headers', 'querystring' => '$query', 'uri' => '$uri'] as $requestPart => $varName) { + $requestParts = ['header' => '$headers', 'querystring' => '$query', 'uri' => '$uri']; + foreach ($requestParts as $requestPart => $varName) { foreach ($inputShape->getMembers() as $member) { // If location is not specified, it will go in the request body. if ($requestPart !== $member->getLocation()) { @@ -373,9 +374,6 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild } $body[$requestPart] .= $bodyCode . "\n"; } - if (isset($body[$requestPart])) { - $body[$requestPart] = implode("\n", array_filter(array_map('trim', explode("\n", $body[$requestPart])))); - } } // "headers" are not "header" @@ -406,7 +404,13 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild 'LOCATION' => $member->getLocationName() ?? $member->getName(), 'VALUE' => $inputElement, ]); - $body['header'] .= implode("\n", array_filter(array_map('trim', explode("\n", $bodyCode)))); + $body['header'] .= $bodyCode . "\n"; + } + + foreach (array_keys($requestParts) as $requestPart) { + if (isset($body[$requestPart])) { + $body[$requestPart] = implode("\n", array_filter(array_map('trim', explode("\n", $body[$requestPart])))); + } } if ($operation->hasBody()) { diff --git a/src/Service/S3/src/Input/CopyObjectRequest.php b/src/Service/S3/src/Input/CopyObjectRequest.php index 3bc9d5baf..819bbd165 100644 --- a/src/Service/S3/src/Input/CopyObjectRequest.php +++ b/src/Service/S3/src/Input/CopyObjectRequest.php @@ -820,7 +820,8 @@ public function request(): Request } if (null !== $this->expectedSourceBucketOwner) { $headers['x-amz-source-expected-bucket-owner'] = $this->expectedSourceBucketOwner; - }if (null !== $this->metadata) { + } + if (null !== $this->metadata) { foreach ($this->metadata as $key => $value) { $headers["x-amz-meta-$key"] = $value; } diff --git a/src/Service/S3/src/Input/CreateMultipartUploadRequest.php b/src/Service/S3/src/Input/CreateMultipartUploadRequest.php index d933b7324..cbd0bd2ff 100644 --- a/src/Service/S3/src/Input/CreateMultipartUploadRequest.php +++ b/src/Service/S3/src/Input/CreateMultipartUploadRequest.php @@ -608,7 +608,8 @@ public function request(): Request throw new InvalidArgument(sprintf('Invalid parameter "ChecksumAlgorithm" for "%s". The value "%s" is not a valid "ChecksumAlgorithm".', __CLASS__, $this->checksumAlgorithm)); } $headers['x-amz-checksum-algorithm'] = $this->checksumAlgorithm; - }if (null !== $this->metadata) { + } + if (null !== $this->metadata) { foreach ($this->metadata as $key => $value) { $headers["x-amz-meta-$key"] = $value; } diff --git a/src/Service/S3/src/Input/PutObjectRequest.php b/src/Service/S3/src/Input/PutObjectRequest.php index 072bd789d..3e666fbeb 100644 --- a/src/Service/S3/src/Input/PutObjectRequest.php +++ b/src/Service/S3/src/Input/PutObjectRequest.php @@ -775,7 +775,8 @@ public function request(): Request } if (null !== $this->expectedBucketOwner) { $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner; - }if (null !== $this->metadata) { + } + if (null !== $this->metadata) { foreach ($this->metadata as $key => $value) { $headers["x-amz-meta-$key"] = $value; }