Skip to content

Commit 06e91d2

Browse files
fix: allow object value (#3232)
* fix: allow object value Allow object value within a member which type is document. * chore: add change entry log * update changelog entry --------- Co-authored-by: Sean O'Brien <[email protected]>
1 parent 9fe72d7 commit 06e91d2

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"type": "bugfix",
4+
"category": "",
5+
"description": "Allow `stdClass` in `Validator` for document types for empty documents to be encoded as JSON objects rather than arrays."
6+
}
7+
]

src/Api/Validator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Aws\Api;
33

44
use Aws;
5+
use stdClass;
56

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

293294
private function checkDocumentType($value)
294295
{
296+
// To allow objects like value, which
297+
// can be used within a member which type is `Document`
298+
if ($value instanceof stdClass) {
299+
$value = (array) $value;
300+
}
301+
295302
if (is_array($value)) {
296303
$typeOfFirstKey = gettype(key($value));
297304
foreach ($value as $key => $val) {

tests/Api/ValidatorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,25 @@ public function validationProvider()
616616
"Found 1 error while validating the input provided for the Foo operation:\n"
617617
. "[unionVal] is a union type and must have exactly one non null value"
618618
],
619+
[
620+
[
621+
'type' => 'structure',
622+
'members' => [
623+
'documentMember' => [
624+
'type' => 'structure',
625+
'members' => [],
626+
'document' => true,
627+
]
628+
]
629+
],
630+
[
631+
'documentMember' => [
632+
'type' => 'object',
633+
'properties' => (object) []
634+
]
635+
],
636+
true
637+
]
619638
];
620639
}
621640

0 commit comments

Comments
 (0)