Skip to content

Commit 907f8e3

Browse files
authored
Merge validate with request (#322)
* Merge validate with request * More readable input * Fix Input request
1 parent fa1b42a commit 907f8e3

9 files changed

+54
-121
lines changed

src/Input/AddLayerVersionPermissionRequest.php

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,14 @@ public function request(): Request
146146

147147
// Prepare URI
148148
$uri = [];
149-
$uri['LayerName'] = $this->LayerName ?? '';
150-
$uri['VersionNumber'] = $this->VersionNumber ?? '';
149+
if (null === $v = $this->LayerName) {
150+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" for "%s". The value cannot be null.', __CLASS__));
151+
}
152+
$uri['LayerName'] = $v;
153+
if (null === $v = $this->VersionNumber) {
154+
throw new InvalidArgument(sprintf('Missing parameter "VersionNumber" for "%s". The value cannot be null.', __CLASS__));
155+
}
156+
$uri['VersionNumber'] = $v;
151157
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions/{$uri['VersionNumber']}/policy";
152158

153159
// Prepare Body
@@ -207,39 +213,25 @@ public function setVersionNumber(?string $value): self
207213
return $this;
208214
}
209215

210-
public function validate(): void
211-
{
212-
if (null === $this->LayerName) {
213-
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
214-
}
215-
216-
if (null === $this->VersionNumber) {
217-
throw new InvalidArgument(sprintf('Missing parameter "VersionNumber" when validating the "%s". The value cannot be null.', __CLASS__));
218-
}
219-
220-
if (null === $this->StatementId) {
221-
throw new InvalidArgument(sprintf('Missing parameter "StatementId" when validating the "%s". The value cannot be null.', __CLASS__));
222-
}
223-
224-
if (null === $this->Action) {
225-
throw new InvalidArgument(sprintf('Missing parameter "Action" when validating the "%s". The value cannot be null.', __CLASS__));
226-
}
227-
228-
if (null === $this->Principal) {
229-
throw new InvalidArgument(sprintf('Missing parameter "Principal" when validating the "%s". The value cannot be null.', __CLASS__));
230-
}
231-
}
232-
233216
/**
234217
* @internal
235218
*/
236219
private function requestBody(): array
237220
{
238221
$payload = [];
239222

240-
$payload['StatementId'] = $this->StatementId;
241-
$payload['Action'] = $this->Action;
242-
$payload['Principal'] = $this->Principal;
223+
if (null === $v = $this->StatementId) {
224+
throw new InvalidArgument(sprintf('Missing parameter "StatementId" for "%s". The value cannot be null.', __CLASS__));
225+
}
226+
$payload['StatementId'] = $v;
227+
if (null === $v = $this->Action) {
228+
throw new InvalidArgument(sprintf('Missing parameter "Action" for "%s". The value cannot be null.', __CLASS__));
229+
}
230+
$payload['Action'] = $v;
231+
if (null === $v = $this->Principal) {
232+
throw new InvalidArgument(sprintf('Missing parameter "Principal" for "%s". The value cannot be null.', __CLASS__));
233+
}
234+
$payload['Principal'] = $v;
243235
if (null !== $v = $this->OrganizationId) {
244236
$payload['OrganizationId'] = $v;
245237
}

src/Input/InvocationRequest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,15 @@ public function request(): Request
123123
// Prepare headers
124124
$headers = ['content-type' => 'application/json'];
125125
if (null !== $this->InvocationType) {
126+
if (!InvocationType::exists($this->InvocationType)) {
127+
throw new InvalidArgument(sprintf('Invalid parameter "InvocationType" for "%s". The value "%s" is not a valid "InvocationType".', __CLASS__, $this->InvocationType));
128+
}
126129
$headers['X-Amz-Invocation-Type'] = $this->InvocationType;
127130
}
128131
if (null !== $this->LogType) {
132+
if (!LogType::exists($this->LogType)) {
133+
throw new InvalidArgument(sprintf('Invalid parameter "LogType" for "%s". The value "%s" is not a valid "LogType".', __CLASS__, $this->LogType));
134+
}
129135
$headers['X-Amz-Log-Type'] = $this->LogType;
130136
}
131137
if (null !== $this->ClientContext) {
@@ -140,7 +146,10 @@ public function request(): Request
140146

141147
// Prepare URI
142148
$uri = [];
143-
$uri['FunctionName'] = $this->FunctionName ?? '';
149+
if (null === $v = $this->FunctionName) {
150+
throw new InvalidArgument(sprintf('Missing parameter "FunctionName" for "%s". The value cannot be null.', __CLASS__));
151+
}
152+
$uri['FunctionName'] = $v;
144153
$uriString = "/2015-03-31/functions/{$uri['FunctionName']}/invocations";
145154

146155
// Prepare Body
@@ -197,23 +206,4 @@ public function setQualifier(?string $value): self
197206

198207
return $this;
199208
}
200-
201-
public function validate(): void
202-
{
203-
if (null === $this->FunctionName) {
204-
throw new InvalidArgument(sprintf('Missing parameter "FunctionName" when validating the "%s". The value cannot be null.', __CLASS__));
205-
}
206-
207-
if (null !== $this->InvocationType) {
208-
if (!InvocationType::exists($this->InvocationType)) {
209-
throw new InvalidArgument(sprintf('Invalid parameter "InvocationType" when validating the "%s". The value "%s" is not a valid "InvocationType".', __CLASS__, $this->InvocationType));
210-
}
211-
}
212-
213-
if (null !== $this->LogType) {
214-
if (!LogType::exists($this->LogType)) {
215-
throw new InvalidArgument(sprintf('Invalid parameter "LogType" when validating the "%s". The value "%s" is not a valid "LogType".', __CLASS__, $this->LogType));
216-
}
217-
}
218-
}
219209
}

src/Input/ListLayerVersionsRequest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public function request(): Request
9494
// Prepare query
9595
$query = [];
9696
if (null !== $this->CompatibleRuntime) {
97+
if (!Runtime::exists($this->CompatibleRuntime)) {
98+
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntime" for "%s". The value "%s" is not a valid "Runtime".', __CLASS__, $this->CompatibleRuntime));
99+
}
97100
$query['CompatibleRuntime'] = $this->CompatibleRuntime;
98101
}
99102
if (null !== $this->Marker) {
@@ -105,7 +108,10 @@ public function request(): Request
105108

106109
// Prepare URI
107110
$uri = [];
108-
$uri['LayerName'] = $this->LayerName ?? '';
111+
if (null === $v = $this->LayerName) {
112+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" for "%s". The value cannot be null.', __CLASS__));
113+
}
114+
$uri['LayerName'] = $v;
109115
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
110116

111117
// Prepare Body
@@ -145,17 +151,4 @@ public function setMaxItems(?int $value): self
145151

146152
return $this;
147153
}
148-
149-
public function validate(): void
150-
{
151-
if (null !== $this->CompatibleRuntime) {
152-
if (!Runtime::exists($this->CompatibleRuntime)) {
153-
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntime" when validating the "%s". The value "%s" is not a valid "Runtime".', __CLASS__, $this->CompatibleRuntime));
154-
}
155-
}
156-
157-
if (null === $this->LayerName) {
158-
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
159-
}
160-
}
161154
}

src/Input/PublishLayerVersionRequest.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ public function request(): Request
115115

116116
// Prepare URI
117117
$uri = [];
118-
$uri['LayerName'] = $this->LayerName ?? '';
118+
if (null === $v = $this->LayerName) {
119+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" for "%s". The value cannot be null.', __CLASS__));
120+
}
121+
$uri['LayerName'] = $v;
119122
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
120123

121124
// Prepare Body
@@ -164,24 +167,6 @@ public function setLicenseInfo(?string $value): self
164167
return $this;
165168
}
166169

167-
public function validate(): void
168-
{
169-
if (null === $this->LayerName) {
170-
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
171-
}
172-
173-
if (null === $this->Content) {
174-
throw new InvalidArgument(sprintf('Missing parameter "Content" when validating the "%s". The value cannot be null.', __CLASS__));
175-
}
176-
$this->Content->validate();
177-
178-
foreach ($this->CompatibleRuntimes as $item) {
179-
if (!Runtime::exists($item)) {
180-
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntimes" when validating the "%s". The value "%s" is not a valid "Runtime".', __CLASS__, $item));
181-
}
182-
}
183-
}
184-
185170
/**
186171
* @internal
187172
*/
@@ -192,14 +177,18 @@ private function requestBody(): array
192177
if (null !== $v = $this->Description) {
193178
$payload['Description'] = $v;
194179
}
195-
if (null !== $v = $this->Content) {
196-
$payload['Content'] = $v->requestBody();
180+
if (null === $v = $this->Content) {
181+
throw new InvalidArgument(sprintf('Missing parameter "Content" for "%s". The value cannot be null.', __CLASS__));
197182
}
183+
$payload['Content'] = $v->requestBody();
198184

199185
$index = -1;
200-
foreach ($this->CompatibleRuntimes as $mapValue) {
186+
foreach ($this->CompatibleRuntimes as $listValue) {
201187
++$index;
202-
$payload['CompatibleRuntimes'][$index] = $mapValue;
188+
if (!Runtime::exists($listValue)) {
189+
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntimes" for "%s". The value "%s" is not a valid "Runtime".', __CLASS__, $listValue));
190+
}
191+
$payload['CompatibleRuntimes'][$index] = $listValue;
203192
}
204193

205194
if (null !== $v = $this->LicenseInfo) {

src/LambdaClient.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ class LambdaClient extends AbstractApi
3434
*/
3535
public function addLayerVersionPermission($input): AddLayerVersionPermissionResponse
3636
{
37-
$input = AddLayerVersionPermissionRequest::create($input);
38-
$input->validate();
39-
40-
$response = $this->getResponse($input->request());
37+
$response = $this->getResponse(AddLayerVersionPermissionRequest::create($input)->request());
4138

4239
return new AddLayerVersionPermissionResponse($response, $this->httpClient);
4340
}
@@ -59,10 +56,7 @@ public function addLayerVersionPermission($input): AddLayerVersionPermissionResp
5956
*/
6057
public function invoke($input): InvocationResponse
6158
{
62-
$input = InvocationRequest::create($input);
63-
$input->validate();
64-
65-
$response = $this->getResponse($input->request());
59+
$response = $this->getResponse(InvocationRequest::create($input)->request());
6660

6761
return new InvocationResponse($response, $this->httpClient);
6862
}
@@ -85,8 +79,6 @@ public function invoke($input): InvocationResponse
8579
public function listLayerVersions($input): ListLayerVersionsResponse
8680
{
8781
$input = ListLayerVersionsRequest::create($input);
88-
$input->validate();
89-
9082
$response = $this->getResponse($input->request());
9183

9284
return new ListLayerVersionsResponse($response, $this->httpClient, $this, $input);
@@ -109,10 +101,7 @@ public function listLayerVersions($input): ListLayerVersionsResponse
109101
*/
110102
public function publishLayerVersion($input): PublishLayerVersionResponse
111103
{
112-
$input = PublishLayerVersionRequest::create($input);
113-
$input->validate();
114-
115-
$response = $this->getResponse($input->request());
104+
$response = $this->getResponse(PublishLayerVersionRequest::create($input)->request());
116105

117106
return new PublishLayerVersionResponse($response, $this->httpClient);
118107
}

src/ValueObject/LayerVersionContentInput.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,4 @@ public function requestBody(): array
8686

8787
return $payload;
8888
}
89-
90-
public function validate(): void
91-
{
92-
// There are no required properties
93-
}
9489
}

src/ValueObject/LayerVersionContentOutput.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,4 @@ public function getLocation(): ?string
5252
{
5353
return $this->Location;
5454
}
55-
56-
public function validate(): void
57-
{
58-
// There are no required properties
59-
}
6055
}

src/ValueObject/LayerVersionsListItem.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace AsyncAws\Lambda\ValueObject;
44

5-
use AsyncAws\Core\Exception\InvalidArgument;
65
use AsyncAws\Lambda\Enum\Runtime;
76

87
class LayerVersionsListItem
@@ -94,13 +93,4 @@ public function getVersion(): ?string
9493
{
9594
return $this->Version;
9695
}
97-
98-
public function validate(): void
99-
{
100-
foreach ($this->CompatibleRuntimes as $item) {
101-
if (!Runtime::exists($item)) {
102-
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntimes" when validating the "%s". The value "%s" is not a valid "Runtime".', __CLASS__, $item));
103-
}
104-
}
105-
}
10696
}

tests/Unit/Input/ListLayerVersionsRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testInvalidEnum(): void
3333
'CompatibleRuntime' => 'boom',
3434
]);
3535
$this->expectException(InvalidArgument::class);
36-
$this->expectExceptionMessage('Invalid parameter "CompatibleRuntime" when validating the "AsyncAws\Lambda\Input\ListLayerVersionsRequest". The value "boom" is not a valid "Runtime".');
37-
$input->validate();
36+
$this->expectExceptionMessage('Invalid parameter "CompatibleRuntime" for "AsyncAws\Lambda\Input\ListLayerVersionsRequest". The value "boom" is not a valid "Runtime".');
37+
$input->request();
3838
}
3939
}

0 commit comments

Comments
 (0)