Skip to content

Commit f788b69

Browse files
committed
Remove checks for missing properties for value object request bodies
This is already validated in the constructor now.
1 parent d8f5fdc commit f788b69

File tree

115 files changed

+210
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+210
-565
lines changed

src/CodeGenerator/src/Generator/InputGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild
429429
if ($operation->hasBody()) {
430430
[$body['body'], $hasRequestBody, $overrideArgs] = $serializer->generateRequestBody($operation, $inputShape) + [null, null, []];
431431
if ($hasRequestBody) {
432-
[$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($inputShape) + [null, null, []];
432+
[$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($inputShape, true) + [null, null, []];
433433
if ('' === trim($requestBody)) {
434434
$body['body'] = '$body = "";';
435435
} else {

src/CodeGenerator/src/Generator/ObjectGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function generate(StructureShape $shape, bool $forEndpoint = false): Clas
106106

107107
$serializer = $this->serializer->get($shape->getService());
108108
if ($this->isShapeUsedInput($shape)) {
109-
[$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($shape) + [null, null, []];
109+
[$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($shape, false) + [null, null, []];
110110
$method = $classBuilder->addMethod('requestBody')->setReturnType($returnType)->setBody($requestBody)->setPublic()->setComment('@internal');
111111
foreach ($args as $arg => $type) {
112112
$method->addParameter($arg)->setType($type);

src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
6969
]), true];
7070
}
7171

72-
public function generateRequestBuilder(StructureShape $shape): array
72+
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array
7373
{
74-
$body = implode("\n", array_map(function (StructureMember $member) {
74+
$body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) {
7575
if (null !== $member->getLocation()) {
7676
return '';
7777
}
@@ -84,10 +84,15 @@ public function generateRequestBuilder(StructureShape $shape): array
8484
MEMBER_CODE';
8585
$inputElement = '$v';
8686
} elseif ($member->isRequired()) {
87-
$body = 'if (null === $v = $this->PROPERTY) {
88-
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
87+
if ($needsChecks) {
88+
$body = 'if (null === $v = $this->PROPERTY) {
89+
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
90+
}
91+
MEMBER_CODE';
92+
} else {
93+
$body = '$v = $this->PROPERTY;
94+
MEMBER_CODE';
8995
}
90-
MEMBER_CODE';
9196
$inputElement = '$v';
9297
} else {
9398
$body = 'if (null !== $v = $this->PROPERTY) {

src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
6868
return ['$bodyPayload = $this->requestBody(); $body = empty($bodyPayload) ? "{}" : \json_encode($bodyPayload, ' . \JSON_THROW_ON_ERROR . ');', true];
6969
}
7070

71-
public function generateRequestBuilder(StructureShape $shape): array
71+
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array
7272
{
73-
$body = implode("\n", array_map(function (StructureMember $member) {
73+
$body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) {
7474
if (null !== $member->getLocation()) {
7575
return '';
7676
}
@@ -83,10 +83,15 @@ public function generateRequestBuilder(StructureShape $shape): array
8383
MEMBER_CODE';
8484
$inputElement = '$v';
8585
} elseif ($member->isRequired()) {
86-
$body = 'if (null === $v = $this->PROPERTY) {
87-
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
86+
if ($needsChecks) {
87+
$body = 'if (null === $v = $this->PROPERTY) {
88+
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
89+
}
90+
MEMBER_CODE';
91+
} else {
92+
$body = '$v = $this->PROPERTY;
93+
MEMBER_CODE';
8894
}
89-
MEMBER_CODE';
9095
$inputElement = '$v';
9196
} else {
9297
$body = 'if (null !== $v = $this->PROPERTY) {

src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
9393
', true, ['node' => \DOMNode::class]];
9494
}
9595

96-
public function generateRequestBuilder(StructureShape $shape): array
96+
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array
9797
{
98-
$body = implode("\n", array_map(function (StructureMember $member) {
98+
$body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) {
9999
if (null !== $member->getLocation()) {
100100
return '';
101101
}
@@ -108,10 +108,15 @@ public function generateRequestBuilder(StructureShape $shape): array
108108
MEMBER_CODE';
109109
$inputElement = '$v';
110110
} elseif ($member->isRequired()) {
111-
$body = 'if (null === $v = $this->PROPERTY) {
112-
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
111+
if ($needsChecks) {
112+
$body = 'if (null === $v = $this->PROPERTY) {
113+
throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__));
114+
}
115+
MEMBER_CODE';
116+
} else {
117+
$body = '$v = $this->PROPERTY;
118+
MEMBER_CODE';
113119
}
114-
MEMBER_CODE';
115120
$inputElement = '$v';
116121
} else {
117122
$body = 'if (null !== $v = $this->PROPERTY) {

src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
2727
*
2828
* @return array{0: string, 1: string, 2?: array<string, string>}
2929
*/
30-
public function generateRequestBuilder(StructureShape $shape): array;
30+
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array;
3131

3232
public function getHeaders(Operation $operation): string;
3333
}

src/Core/src/Sts/ValueObject/Tag.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ public function getValue(): string
7272
public function requestBody(): array
7373
{
7474
$payload = [];
75-
if (null === $v = $this->key) {
76-
throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__));
77-
}
75+
$v = $this->key;
7876
$payload['Key'] = $v;
79-
if (null === $v = $this->value) {
80-
throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__));
81-
}
77+
$v = $this->value;
8278
$payload['Value'] = $v;
8379

8480
return $payload;

src/Service/AppSync/src/ValueObject/AppSyncRuntime.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,12 @@ public function getRuntimeVersion(): string
6464
public function requestBody(): array
6565
{
6666
$payload = [];
67-
if (null === $v = $this->name) {
68-
throw new InvalidArgument(sprintf('Missing parameter "name" for "%s". The value cannot be null.', __CLASS__));
69-
}
67+
$v = $this->name;
7068
if (!RuntimeName::exists($v)) {
7169
throw new InvalidArgument(sprintf('Invalid parameter "name" for "%s". The value "%s" is not a valid "RuntimeName".', __CLASS__, $v));
7270
}
7371
$payload['name'] = $v;
74-
if (null === $v = $this->runtimeVersion) {
75-
throw new InvalidArgument(sprintf('Missing parameter "runtimeVersion" for "%s". The value cannot be null.', __CLASS__));
76-
}
72+
$v = $this->runtimeVersion;
7773
$payload['runtimeVersion'] = $v;
7874

7975
return $payload;

src/Service/AppSync/src/ValueObject/AuthorizationConfig.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function getAwsIamConfig(): ?AwsIamConfig
6464
public function requestBody(): array
6565
{
6666
$payload = [];
67-
if (null === $v = $this->authorizationType) {
68-
throw new InvalidArgument(sprintf('Missing parameter "authorizationType" for "%s". The value cannot be null.', __CLASS__));
69-
}
67+
$v = $this->authorizationType;
7068
if (!AuthorizationType::exists($v)) {
7169
throw new InvalidArgument(sprintf('Invalid parameter "authorizationType" for "%s". The value "%s" is not a valid "AuthorizationType".', __CLASS__, $v));
7270
}

src/Service/AppSync/src/ValueObject/CachingConfig.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public function getTtl(): int
6565
public function requestBody(): array
6666
{
6767
$payload = [];
68-
if (null === $v = $this->ttl) {
69-
throw new InvalidArgument(sprintf('Missing parameter "ttl" for "%s". The value cannot be null.', __CLASS__));
70-
}
68+
$v = $this->ttl;
7169
$payload['ttl'] = $v;
7270
if (null !== $v = $this->cachingKeys) {
7371
$index = -1;

src/Service/AppSync/src/ValueObject/DynamodbDataSourceConfig.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ public function getVersioned(): ?bool
9797
public function requestBody(): array
9898
{
9999
$payload = [];
100-
if (null === $v = $this->tableName) {
101-
throw new InvalidArgument(sprintf('Missing parameter "tableName" for "%s". The value cannot be null.', __CLASS__));
102-
}
100+
$v = $this->tableName;
103101
$payload['tableName'] = $v;
104-
if (null === $v = $this->awsRegion) {
105-
throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__));
106-
}
102+
$v = $this->awsRegion;
107103
$payload['awsRegion'] = $v;
108104
if (null !== $v = $this->useCallerCredentials) {
109105
$payload['useCallerCredentials'] = (bool) $v;

src/Service/AppSync/src/ValueObject/ElasticsearchDataSourceConfig.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ public function getEndpoint(): string
6161
public function requestBody(): array
6262
{
6363
$payload = [];
64-
if (null === $v = $this->endpoint) {
65-
throw new InvalidArgument(sprintf('Missing parameter "endpoint" for "%s". The value cannot be null.', __CLASS__));
66-
}
64+
$v = $this->endpoint;
6765
$payload['endpoint'] = $v;
68-
if (null === $v = $this->awsRegion) {
69-
throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__));
70-
}
66+
$v = $this->awsRegion;
7167
$payload['awsRegion'] = $v;
7268

7369
return $payload;

src/Service/AppSync/src/ValueObject/EventBridgeDataSourceConfig.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public function getEventBusArn(): string
4747
public function requestBody(): array
4848
{
4949
$payload = [];
50-
if (null === $v = $this->eventBusArn) {
51-
throw new InvalidArgument(sprintf('Missing parameter "eventBusArn" for "%s". The value cannot be null.', __CLASS__));
52-
}
50+
$v = $this->eventBusArn;
5351
$payload['eventBusArn'] = $v;
5452

5553
return $payload;

src/Service/AppSync/src/ValueObject/LambdaDataSourceConfig.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public function getLambdaFunctionArn(): string
4545
public function requestBody(): array
4646
{
4747
$payload = [];
48-
if (null === $v = $this->lambdaFunctionArn) {
49-
throw new InvalidArgument(sprintf('Missing parameter "lambdaFunctionArn" for "%s". The value cannot be null.', __CLASS__));
50-
}
48+
$v = $this->lambdaFunctionArn;
5149
$payload['lambdaFunctionArn'] = $v;
5250

5351
return $payload;

src/Service/AppSync/src/ValueObject/OpenSearchServiceDataSourceConfig.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ public function getEndpoint(): string
5858
public function requestBody(): array
5959
{
6060
$payload = [];
61-
if (null === $v = $this->endpoint) {
62-
throw new InvalidArgument(sprintf('Missing parameter "endpoint" for "%s". The value cannot be null.', __CLASS__));
63-
}
61+
$v = $this->endpoint;
6462
$payload['endpoint'] = $v;
65-
if (null === $v = $this->awsRegion) {
66-
throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__));
67-
}
63+
$v = $this->awsRegion;
6864
$payload['awsRegion'] = $v;
6965

7066
return $payload;

src/Service/Athena/src/ValueObject/AclConfiguration.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public function getS3AclOption(): string
5858
public function requestBody(): array
5959
{
6060
$payload = [];
61-
if (null === $v = $this->s3AclOption) {
62-
throw new InvalidArgument(sprintf('Missing parameter "S3AclOption" for "%s". The value cannot be null.', __CLASS__));
63-
}
61+
$v = $this->s3AclOption;
6462
if (!S3AclOption::exists($v)) {
6563
throw new InvalidArgument(sprintf('Invalid parameter "S3AclOption" for "%s". The value "%s" is not a valid "S3AclOption".', __CLASS__, $v));
6664
}

src/Service/Athena/src/ValueObject/EncryptionConfiguration.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public function getKmsKey(): ?string
6767
public function requestBody(): array
6868
{
6969
$payload = [];
70-
if (null === $v = $this->encryptionOption) {
71-
throw new InvalidArgument(sprintf('Missing parameter "EncryptionOption" for "%s". The value cannot be null.', __CLASS__));
72-
}
70+
$v = $this->encryptionOption;
7371
if (!EncryptionOption::exists($v)) {
7472
throw new InvalidArgument(sprintf('Invalid parameter "EncryptionOption" for "%s". The value "%s" is not a valid "EncryptionOption".', __CLASS__, $v));
7573
}

src/Service/Athena/src/ValueObject/EngineConfiguration.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public function requestBody(): array
112112
if (null !== $v = $this->coordinatorDpuSize) {
113113
$payload['CoordinatorDpuSize'] = $v;
114114
}
115-
if (null === $v = $this->maxConcurrentDpus) {
116-
throw new InvalidArgument(sprintf('Missing parameter "MaxConcurrentDpus" for "%s". The value cannot be null.', __CLASS__));
117-
}
115+
$v = $this->maxConcurrentDpus;
118116
$payload['MaxConcurrentDpus'] = $v;
119117
if (null !== $v = $this->defaultExecutorDpuSize) {
120118
$payload['DefaultExecutorDpuSize'] = $v;

src/Service/Athena/src/ValueObject/ResultReuseByAgeConfiguration.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public function getMaxAgeInMinutes(): ?int
5959
public function requestBody(): array
6060
{
6161
$payload = [];
62-
if (null === $v = $this->enabled) {
63-
throw new InvalidArgument(sprintf('Missing parameter "Enabled" for "%s". The value cannot be null.', __CLASS__));
64-
}
62+
$v = $this->enabled;
6563
$payload['Enabled'] = (bool) $v;
6664
if (null !== $v = $this->maxAgeInMinutes) {
6765
$payload['MaxAgeInMinutes'] = $v;

src/Service/CloudFront/src/ValueObject/InvalidationBatch.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,13 @@ public function getPaths(): Paths
7070
*/
7171
public function requestBody(\DOMElement $node, \DOMDocument $document): void
7272
{
73-
if (null === $v = $this->paths) {
74-
throw new InvalidArgument(sprintf('Missing parameter "Paths" for "%s". The value cannot be null.', __CLASS__));
75-
}
73+
$v = $this->paths;
7674

7775
$node->appendChild($child = $document->createElement('Paths'));
7876

7977
$v->requestBody($child, $document);
8078

81-
if (null === $v = $this->callerReference) {
82-
throw new InvalidArgument(sprintf('Missing parameter "CallerReference" for "%s". The value cannot be null.', __CLASS__));
83-
}
79+
$v = $this->callerReference;
8480
$node->appendChild($document->createElement('CallerReference', $v));
8581
}
8682

src/Service/CloudFront/src/ValueObject/Paths.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public function getQuantity(): int
6363
*/
6464
public function requestBody(\DOMElement $node, \DOMDocument $document): void
6565
{
66-
if (null === $v = $this->quantity) {
67-
throw new InvalidArgument(sprintf('Missing parameter "Quantity" for "%s". The value cannot be null.', __CLASS__));
68-
}
66+
$v = $this->quantity;
6967
$node->appendChild($document->createElement('Quantity', (string) $v));
7068
if (null !== $v = $this->items) {
7169
$node->appendChild($nodeList = $document->createElement('Items'));

src/Service/CloudWatch/src/ValueObject/Dimension.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,9 @@ public function getValue(): string
6666
public function requestBody(): array
6767
{
6868
$payload = [];
69-
if (null === $v = $this->name) {
70-
throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__));
71-
}
69+
$v = $this->name;
7270
$payload['Name'] = $v;
73-
if (null === $v = $this->value) {
74-
throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__));
75-
}
71+
$v = $this->value;
7672
$payload['Value'] = $v;
7773

7874
return $payload;

src/Service/CloudWatch/src/ValueObject/DimensionFilter.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public function getValue(): ?string
5858
public function requestBody(): array
5959
{
6060
$payload = [];
61-
if (null === $v = $this->name) {
62-
throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__));
63-
}
61+
$v = $this->name;
6462
$payload['Name'] = $v;
6563
if (null !== $v = $this->value) {
6664
$payload['Value'] = $v;

src/Service/CloudWatch/src/ValueObject/MetricDataQuery.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ public function getReturnData(): ?bool
183183
public function requestBody(): array
184184
{
185185
$payload = [];
186-
if (null === $v = $this->id) {
187-
throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__));
188-
}
186+
$v = $this->id;
189187
$payload['Id'] = $v;
190188
if (null !== $v = $this->metricStat) {
191189
foreach ($v->requestBody() as $bodyKey => $bodyValue) {

src/Service/CloudWatch/src/ValueObject/MetricDatum.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ public function getValues(): array
188188
public function requestBody(): array
189189
{
190190
$payload = [];
191-
if (null === $v = $this->metricName) {
192-
throw new InvalidArgument(sprintf('Missing parameter "MetricName" for "%s". The value cannot be null.', __CLASS__));
193-
}
191+
$v = $this->metricName;
194192
$payload['MetricName'] = $v;
195193
if (null !== $v = $this->dimensions) {
196194
$index = 0;

src/Service/CloudWatch/src/ValueObject/MetricStat.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,14 @@ public function getUnit(): ?string
103103
public function requestBody(): array
104104
{
105105
$payload = [];
106-
if (null === $v = $this->metric) {
107-
throw new InvalidArgument(sprintf('Missing parameter "Metric" for "%s". The value cannot be null.', __CLASS__));
108-
}
106+
$v = $this->metric;
109107
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
110108
$payload["Metric.$bodyKey"] = $bodyValue;
111109
}
112110

113-
if (null === $v = $this->period) {
114-
throw new InvalidArgument(sprintf('Missing parameter "Period" for "%s". The value cannot be null.', __CLASS__));
115-
}
111+
$v = $this->period;
116112
$payload['Period'] = $v;
117-
if (null === $v = $this->stat) {
118-
throw new InvalidArgument(sprintf('Missing parameter "Stat" for "%s". The value cannot be null.', __CLASS__));
119-
}
113+
$v = $this->stat;
120114
$payload['Stat'] = $v;
121115
if (null !== $v = $this->unit) {
122116
if (!StandardUnit::exists($v)) {

0 commit comments

Comments
 (0)