diff --git a/lib/Models/DocumentFromTemplateResponseFieldsInnerInner.php b/lib/Models/DocumentFromTemplateResponseFieldsInnerInner.php index 25cb8f3..57ac147 100644 --- a/lib/Models/DocumentFromTemplateResponseFieldsInnerInner.php +++ b/lib/Models/DocumentFromTemplateResponseFieldsInnerInner.php @@ -403,7 +403,6 @@ public function __construct($data = null) $this->setIfExists('options', $data ?? [], null); $this->setIfExists('default_option', $data ?? [], null); $this->setIfExists('allow_other', $data ?? [], null); - $this->normalizeCheckboxValue(); } public function hasActualInstance(): bool @@ -1177,39 +1176,6 @@ public function setAllowOther($allow_other) } private function normalizeAfterSet(): void { - $this->normalizeCheckboxValue(); - } - - private function normalizeCheckboxValue(): void - { - if (($this->container['type'] ?? null) !== 'checkbox' || !array_key_exists('value', $this->container) || $this->container['value'] === null) { - return; - } - - $this->container['value'] = self::normalizeCheckboxScalar($this->container['value']); - } - - private static function normalizeCheckboxScalar($value): string - { - if (is_object($value) && method_exists($value, 'hasActualInstance') && $value->hasActualInstance()) { - $value = $value->getActualInstance(); - } - - if (is_bool($value)) { - return $value ? 't' : 'f'; - } - - if (is_string($value)) { - $normalized = strtolower(trim($value)); - if ($normalized === 'true' || $normalized === 't') { - return 't'; - } - if ($normalized === 'false' || $normalized === 'f') { - return 'f'; - } - } - - throw new \InvalidArgumentException('Checkbox field values must be boolean or one of "true", "false", "t", or "f".'); } /** diff --git a/lib/Models/DocumentResponseFieldsInnerInner.php b/lib/Models/DocumentResponseFieldsInnerInner.php index 61969e2..bdbc714 100644 --- a/lib/Models/DocumentResponseFieldsInnerInner.php +++ b/lib/Models/DocumentResponseFieldsInnerInner.php @@ -403,7 +403,6 @@ public function __construct($data = null) $this->setIfExists('options', $data ?? [], null); $this->setIfExists('default_option', $data ?? [], null); $this->setIfExists('allow_other', $data ?? [], null); - $this->normalizeCheckboxValue(); } public function hasActualInstance(): bool @@ -1177,39 +1176,6 @@ public function setAllowOther($allow_other) } private function normalizeAfterSet(): void { - $this->normalizeCheckboxValue(); - } - - private function normalizeCheckboxValue(): void - { - if (($this->container['type'] ?? null) !== 'checkbox' || !array_key_exists('value', $this->container) || $this->container['value'] === null) { - return; - } - - $this->container['value'] = self::normalizeCheckboxScalar($this->container['value']); - } - - private static function normalizeCheckboxScalar($value): string - { - if (is_object($value) && method_exists($value, 'hasActualInstance') && $value->hasActualInstance()) { - $value = $value->getActualInstance(); - } - - if (is_bool($value)) { - return $value ? 't' : 'f'; - } - - if (is_string($value)) { - $normalized = strtolower(trim($value)); - if ($normalized === 'true' || $normalized === 't') { - return 't'; - } - if ($normalized === 'false' || $normalized === 'f') { - return 'f'; - } - } - - throw new \InvalidArgumentException('Checkbox field values must be boolean or one of "true", "false", "t", or "f".'); } /** diff --git a/test/Regression/EmbeddedTest.php b/test/Regression/EmbeddedTest.php index 6eb1d1d..17237f1 100644 --- a/test/Regression/EmbeddedTest.php +++ b/test/Regression/EmbeddedTest.php @@ -8,6 +8,7 @@ use SignWell\Sdk\Embedded; use SignWell\Sdk\Models\DocumentRequest; use SignWell\Sdk\Models\DocumentResponse; +use SignWell\Sdk\Models\DocumentResponseFieldsInnerInner; use SignWell\Sdk\Models\FieldsInnerInner; use SignWell\Sdk\Models\FieldType; use SignWell\Sdk\ObjectSerializer; @@ -169,6 +170,34 @@ public function testCheckboxFieldValuesNormalizeToApiWireValues(): void } } + public function testCheckboxResponseValuesDeserializeFromApiWireValues(): void + { + $checkbox = [ + 'type' => 'checkbox', + 'value' => 't', + 'x' => 1, + 'y' => 1, + 'page' => 1, + 'recipient_id' => '1', + ]; + + $field = ObjectSerializer::deserialize( + json_decode(json_encode($checkbox, JSON_THROW_ON_ERROR), false, flags: JSON_THROW_ON_ERROR), + DocumentResponseFieldsInnerInner::class + ); + $document = ObjectSerializer::deserialize( + json_decode(json_encode([ + 'id' => 'doc_123', + 'test_mode' => true, + 'fields' => [[$checkbox]], + ], JSON_THROW_ON_ERROR), false, flags: JSON_THROW_ON_ERROR), + DocumentResponse::class + ); + + self::assertInstanceOf(DocumentResponseFieldsInnerInner::class, $field); + self::assertInstanceOf(DocumentResponse::class, $document); + } + public function testRejectsMalformedPdfBase64Uploads(): void { $this->expectException(\InvalidArgumentException::class);