Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer issue. #60

Closed
Ohda opened this issue Apr 24, 2018 · 11 comments
Closed

Serializer issue. #60

Ohda opened this issue Apr 24, 2018 · 11 comments

Comments

@Ohda
Copy link
Contributor

Ohda commented Apr 24, 2018

When i try to call
$templateApi = new \DocuSign\eSign\Api\TemplatesApi($apiClient);
$template = $templateApi->get($accountId, '[id-template]');

I've got this error
Fatal error: Class 'Number' not found in _vendors/docusign/esign-client/src/ObjectSerializer.php on line 274

Looks like the serializer is waiting for number and not Number. (ObjectSerializer.php line 254)

Edit : Pull request #46 and #41 try to fix that issue already.
Duplicate issue with #48

@Ohda
Copy link
Contributor Author

Ohda commented Jun 11, 2018

Hi there,
Just to warn the project that this Fatal Error appear each time a Number enter the ObjectSerializer.

To go in production with this vendor, our team was forced to fork the repo and patch it by ourself.
This bug is here for months now...

@kendalltristan
Copy link

I can confirm I'm also seeing this and would greatly appreciate if the PR in question could be merged. Thanks.

@davidloubere
Copy link

Hi @acooper4960, do someone at DocuSign plans to release a fix shortly? It would be greatly appreciated. ICYMI, a fork of DocuSign repository by @trickeyone seems to do the trick.

@davidloubere
Copy link

For those stuck with the bug, you may also consider extending DocuSign\eSign\ApiClient and DocuSign\eSign\ObjectSerializer :

use DocuSign\eSign\ApiClient;

class ApiClientFixer extends ApiClient
{
    public function __construct(\DocuSign\eSign\Configuration $config = null)
    {
        parent::__construct($config);

        $this->serializer = new ObjectSerializerFixer();
    }
}
use DocuSign\eSign\Configuration;
use DocuSign\eSign\ObjectSerializer;

class ObjectSerializerFixer extends ObjectSerializer
{
    /**
     * @param mixed $data
     * @param string $class
     * @param null $httpHeaders
     *
     * @return array|mixed|object|\SplFileObject|null
     *
     * @throws \Exception
     */
    public static function deserialize($data, $class, $httpHeaders = null)
    {
        if (null === $data) {
            return null;
        } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
            $inner = substr($class, 4, -1);
            $deserialized = [];
            if (strrpos($inner, ",") !== false) {
                $subClass_array = explode(',', $inner, 2);
                $subClass = $subClass_array[1];
                foreach ($data as $key => $value) {
                    $deserialized[$key] = self::deserialize($value, $subClass, null);
                }
            }
            return $deserialized;
        } elseif (strcasecmp(substr($class, -2), '[]') === 0) {
            $subClass = substr($class, 0, -2);
            $values = [];
            foreach ($data as $key => $value) {
                $values[] = self::deserialize($value, $subClass, null);
            }
            return $values;
        } elseif ($class === 'object') {
            settype($data, 'array');
            return $data;
        } elseif ($class === '\DateTime') {
            // Some API's return an invalid, empty string as a
            // date-time property. DateTime::__construct() will return
            // the current time for empty input which is probably not
            // what is meant. The invalid empty string is probably to
            // be interpreted as a missing field/value. Let's handle
            // this graceful.
            if (!empty($data)) {
                return new \DateTime($data);
            } else {
                return null;
            }
        } elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
            settype($data, $class);
            return $data;
        } elseif ($class === '\SplFileObject') {
            // determine file name
            if (array_key_exists('Content-Disposition', $httpHeaders) &&
                preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
                $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]);
            } else {
                $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
            }
            $deserialized = new \SplFileObject($filename, "w");
            $byte_written = $deserialized->fwrite($data);
            if (Configuration::getDefaultConfiguration()->getDebug()) {
                error_log("[DEBUG] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.".PHP_EOL, 3, Configuration::getDefaultConfiguration()->getDebugFile());
            }

            return $deserialized;
        } else {
            $class = self::fixClassNamespacing($class);

            // If a discriminator is defined and points to a valid subclass, use it.
            $discriminator = $class::DISCRIMINATOR;
            if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
                $subclass = '\DocuSign\eSign\Model\\' . $data->{$discriminator};
                if (is_subclass_of($subclass, $class)) {
                    $class = $subclass;
                }
            }
            $instance = new $class();
            foreach ($instance::swaggerTypes() as $property => $type) {
                $propertySetter = $instance::setters()[$property];

                if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) {
                    continue;
                }

                $propertyValue = $data->{$instance::attributeMap()[$property]};
                if (isset($propertyValue)) {
                    $instance->$propertySetter(self::deserialize($propertyValue, $type, null));
                }
            }
            return $instance;
        }
    }

    /**
     * Fix issue with loading non-namespaced types
     * @see https://github.com/trickeyone/docusign-php-client/commit/cc3483c44c301ad7c0d42e41094e70dfde5f68ef
     */
    private static function fixClassNamespacing(string $class): string
    {
        if (in_array($class, ['Number', 'Date'])) {
            return '\DocuSign\eSign\Model\\' . $class;
        }

        return $class;
    }
}

@LarryKlugerDS
Copy link
Contributor

Thank you for the problem report. And please accept my apologies for the very slow DocuSign staff replies on this issue. We have reorganized so we can provide faster response.

This issue now has internal bug report # DCM-3210

We are working on it.

@astroanu
Copy link

Is this fixed?

@benburleson
Copy link

Thank you for the problem report. And please accept my apologies for the very slow DocuSign staff replies on this issue. We have reorganized so we can provide faster response.

This issue now has internal bug report # DCM-3210

We are working on it.

@larrykluger Almost a year later -- is there really any attention here?

@LarryKlugerDS
Copy link
Contributor

Hi, our engineering group reports that this has been fixed in v5.1. Can you verify?
Thank you!

@benburleson
Copy link

@larrykluger Can you point to a commit that addresses this? There is no activity on related issues/PRs, and no mention of this in release notes.

@LarryKlugerDS
Copy link
Contributor

Hi @benburleson ,
Our engineering group says that it is fixed within the model's definition for the forthcoming 5.1 release. Currently thats the 5.1.0-RC release -- RC means Release Candidate.

To install it: composer require docusign/esign-client:v5.1.0-rc

Packagist listing

@LarryKlugerDS
Copy link
Contributor

No reply for since Mar 26. Closing. Please comment to re-open if there's still an issue. Thank you, Larry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants