Skip to content

Commit 954a10f

Browse files
committed
Fix the handling of required fields populated from headers
1 parent 18fcf64 commit 954a10f

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,39 +184,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
184184
$memberShape = $member->getShape();
185185
switch ($memberShape->getType()) {
186186
case 'timestamp':
187-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null;' . "\n", [
188-
'PROPERTY_NAME' => $propertyName,
189-
'LOCATION_NAME' => $locationName,
190-
]);
187+
$input = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0])';
191188

192189
break;
193190
case 'integer':
194191
case 'long':
195-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null;' . "\n", [
196-
'PROPERTY_NAME' => $propertyName,
197-
'LOCATION_NAME' => $locationName,
198-
]);
192+
$input = '(int) $headers["LOCATION_NAME"][0]';
199193

200194
break;
201195
case 'boolean':
202196
$this->requirementsRegistry->addRequirement('ext-filter');
203197

204-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null;' . "\n", [
205-
'PROPERTY_NAME' => $propertyName,
206-
'LOCATION_NAME' => $locationName,
207-
]);
198+
$input = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN)';
208199

209200
break;
210201
case 'string':
211-
$body .= strtr('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null;' . "\n", [
212-
'PROPERTY_NAME' => $propertyName,
213-
'LOCATION_NAME' => $locationName,
214-
]);
202+
$input = '$headers["LOCATION_NAME"][0]';
215203

216204
break;
217205
default:
218206
throw new \RuntimeException(sprintf('Type %s is not yet implemented', $memberShape->getType()));
219207
}
208+
209+
if (!$member->isRequired()) {
210+
$input = 'isset($headers["LOCATION_NAME"][0]) ? ' . $input . ' : null';
211+
}
212+
213+
$body .= strtr('$this->PROPERTY_NAME = ' . $input . ";\n", [
214+
'PROPERTY_NAME' => $propertyName,
215+
'LOCATION_NAME' => $locationName,
216+
]);
220217
}
221218

222219
// This will catch arbitrary values that exists in undefined "headers"

src/Service/Route53/src/Result/CreateHostedZoneResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function populateResult(Response $response): void
8080
{
8181
$headers = $response->getHeaders();
8282

83-
$this->location = $headers['location'][0] ?? null;
83+
$this->location = $headers['location'][0];
8484

8585
$data = new \SimpleXMLElement($response->getContent());
8686
$this->hostedZone = new HostedZone([

0 commit comments

Comments
 (0)