Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/fix-object-value-validation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "bugfix",
"category": "",
"description": "Allow `stdClass` in `Validator` for document types for empty documents to be encoded as JSON objects rather than arrays."
}
]
7 changes: 7 additions & 0 deletions src/Api/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Aws\Api;

use Aws;
use stdClass;

/**
* Validates a schema against a hash of input.
Expand Down Expand Up @@ -292,6 +293,12 @@ private function checkAssociativeArray($value)

private function checkDocumentType($value)
{
// To allow objects like value, which
// can be used within a member which type is `Document`
if ($value instanceof stdClass) {
$value = (array) $value;
}

if (is_array($value)) {
$typeOfFirstKey = gettype(key($value));
foreach ($value as $key => $val) {
Expand Down
19 changes: 19 additions & 0 deletions tests/Api/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,25 @@ public function validationProvider()
"Found 1 error while validating the input provided for the Foo operation:\n"
. "[unionVal] is a union type and must have exactly one non null value"
],
[
[
'type' => 'structure',
'members' => [
'documentMember' => [
'type' => 'structure',
'members' => [],
'document' => true,
]
]
],
[
'documentMember' => [
'type' => 'object',
'properties' => (object) []
]
],
true
]
];
}

Expand Down