Skip to content

Commit

Permalink
Differentiate empty list to not set list (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyx authored Jun 9, 2020
1 parent ca24099 commit e6eb162
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
19 changes: 10 additions & 9 deletions src/Input/GetParametersByPathRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class GetParametersByPathRequest extends Input
/**
* Filters to limit the request results.
*
* @var ParameterStringFilter[]
* @var ParameterStringFilter[]|null
*/
private $ParameterFilters;

Expand Down Expand Up @@ -72,7 +72,7 @@ public function __construct(array $input = [])
{
$this->Path = $input['Path'] ?? null;
$this->Recursive = $input['Recursive'] ?? null;
$this->ParameterFilters = array_map([ParameterStringFilter::class, 'create'], $input['ParameterFilters'] ?? []);
$this->ParameterFilters = isset($input['ParameterFilters']) ? array_map([ParameterStringFilter::class, 'create'], $input['ParameterFilters']) : null;
$this->WithDecryption = $input['WithDecryption'] ?? null;
$this->MaxResults = $input['MaxResults'] ?? null;
$this->NextToken = $input['NextToken'] ?? null;
Expand All @@ -99,7 +99,7 @@ public function getNextToken(): ?string
*/
public function getParameterFilters(): array
{
return $this->ParameterFilters;
return $this->ParameterFilters ?? [];
}

public function getPath(): ?string
Expand Down Expand Up @@ -197,13 +197,14 @@ private function requestBody(): array
if (null !== $v = $this->Recursive) {
$payload['Recursive'] = (bool) $v;
}

$index = -1;
foreach ($this->ParameterFilters as $listValue) {
++$index;
$payload['ParameterFilters'][$index] = $listValue->requestBody();
if (null !== $v = $this->ParameterFilters) {
$index = -1;
$payload['ParameterFilters'] = [];
foreach ($v as $listValue) {
++$index;
$payload['ParameterFilters'][$index] = $listValue->requestBody();
}
}

if (null !== $v = $this->WithDecryption) {
$payload['WithDecryption'] = (bool) $v;
}
Expand Down
13 changes: 9 additions & 4 deletions src/Input/GetParametersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AsyncAws\Ssm\Input;

use AsyncAws\Core\Exception\InvalidArgument;
use AsyncAws\Core\Input;
use AsyncAws\Core\Request;
use AsyncAws\Core\Stream\StreamFactory;
Expand All @@ -13,7 +14,7 @@ final class GetParametersRequest extends Input
*
* @required
*
* @var string[]
* @var string[]|null
*/
private $Names;

Expand All @@ -34,7 +35,7 @@ final class GetParametersRequest extends Input
*/
public function __construct(array $input = [])
{
$this->Names = $input['Names'] ?? [];
$this->Names = $input['Names'] ?? null;
$this->WithDecryption = $input['WithDecryption'] ?? null;
parent::__construct($input);
}
Expand All @@ -49,7 +50,7 @@ public static function create($input): self
*/
public function getNames(): array
{
return $this->Names;
return $this->Names ?? [];
}

public function getWithDecryption(): ?bool
Expand Down Expand Up @@ -102,9 +103,13 @@ public function setWithDecryption(?bool $value): self
private function requestBody(): array
{
$payload = [];
if (null === $v = $this->Names) {
throw new InvalidArgument(sprintf('Missing parameter "Names" for "%s". The value cannot be null.', __CLASS__));
}

$index = -1;
foreach ($this->Names as $listValue) {
$payload['Names'] = [];
foreach ($v as $listValue) {
++$index;
$payload['Names'][$index] = $listValue;
}
Expand Down
19 changes: 10 additions & 9 deletions src/Input/PutParameterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class PutParameterRequest extends Input
* type of resource to which it applies, the environment, or the type of configuration data referenced by the parameter.
* In this case, you could specify the following key name/value pairs:.
*
* @var Tag[]
* @var Tag[]|null
*/
private $Tags;

Expand Down Expand Up @@ -128,7 +128,7 @@ public function __construct(array $input = [])
$this->KeyId = $input['KeyId'] ?? null;
$this->Overwrite = $input['Overwrite'] ?? null;
$this->AllowedPattern = $input['AllowedPattern'] ?? null;
$this->Tags = array_map([Tag::class, 'create'], $input['Tags'] ?? []);
$this->Tags = isset($input['Tags']) ? array_map([Tag::class, 'create'], $input['Tags']) : null;
$this->Tier = $input['Tier'] ?? null;
$this->Policies = $input['Policies'] ?? null;
$this->DataType = $input['DataType'] ?? null;
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getPolicies(): ?string
*/
public function getTags(): array
{
return $this->Tags;
return $this->Tags ?? [];
}

/**
Expand Down Expand Up @@ -344,13 +344,14 @@ private function requestBody(): array
if (null !== $v = $this->AllowedPattern) {
$payload['AllowedPattern'] = $v;
}

$index = -1;
foreach ($this->Tags as $listValue) {
++$index;
$payload['Tags'][$index] = $listValue->requestBody();
if (null !== $v = $this->Tags) {
$index = -1;
$payload['Tags'] = [];
foreach ($v as $listValue) {
++$index;
$payload['Tags'][$index] = $listValue->requestBody();
}
}

if (null !== $v = $this->Tier) {
if (!ParameterTier::exists($v)) {
throw new InvalidArgument(sprintf('Invalid parameter "Tier" for "%s". The value "%s" is not a valid "ParameterTier".', __CLASS__, $v));
Expand Down
16 changes: 9 additions & 7 deletions src/ValueObject/ParameterStringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $input)
{
$this->Key = $input['Key'] ?? null;
$this->Option = $input['Option'] ?? null;
$this->Values = $input['Values'] ?? [];
$this->Values = $input['Values'] ?? null;
}

public static function create($input): self
Expand All @@ -57,7 +57,7 @@ public function getOption(): ?string
*/
public function getValues(): array
{
return $this->Values;
return $this->Values ?? [];
}

/**
Expand All @@ -73,11 +73,13 @@ public function requestBody(): array
if (null !== $v = $this->Option) {
$payload['Option'] = $v;
}

$index = -1;
foreach ($this->Values as $listValue) {
++$index;
$payload['Values'][$index] = $listValue;
if (null !== $v = $this->Values) {
$index = -1;
$payload['Values'] = [];
foreach ($v as $listValue) {
++$index;
$payload['Values'][$index] = $listValue;
}
}

return $payload;
Expand Down

0 comments on commit e6eb162

Please sign in to comment.