MSGraph-SDK-Code-Generator icon indicating copy to clipboard operation
MSGraph-SDK-Code-Generator copied to clipboard

Fix an issue with missing OData types.

Open SilasKenneth opened this issue 2 years ago • 3 comments

Summary

This PR replaces references for missing Odata types with Custom types on the microsoft-graph-php-core repo

Generated code differences

See #712 for detailed diff.

Command line arguments to run these changes

N/A

Links to issues or work items this PR addresses

Fixes #524

Microsoft Reviewers: Open in CodeFlow

SilasKenneth avatar Nov 17 '21 14:11 SilasKenneth

Idea to make the Date type useful in v1 as well & fix the Date serialization issue (https://github.com/microsoftgraph/msgraph-sdk-php/issues/704)..

Would it be worthwhile to make the setters for Date types continue to accept a DateTime but set the property to a Date via createFromDateTime and getters for Date types continue to return DateTime by creating a DateTime from Date's __toString()? e.g for RecurrenceRange

   public function setEndDate($val)
    {
        $this->_propDict["endDate"] = \Microsoft\Graph\Core\Models\Date::createFromDateTime($val);
         return $this;
    }
    
   public function getEndDate()
    {
        if (array_key_exists("endDate", $this->_propDict)) {
            if (is_a($this->_propDict["endDate"], "\Microsoft\Graph\Core\Models\Date") || is_null($this->_propDict["endDate"])) {
                return new \DateTime((string)$this->_propDict["endDate"]);
            } else {
                setEndDate($this->_propDict["endDate"]);
                return $this->_propDict["endDate"];
            }
        }
        return null;
    }

Ndiritu avatar Nov 18 '21 19:11 Ndiritu

Idea to make the Date type useful in v1 as well & fix the Date serialization issue (https://github.com/microsoftgraph/msgraph-sdk-php/issues/704)..

Would it be worthwhile to make the setters for Date types continue to accept a DateTime but set the property to a Date via createFromDateTime and getters for Date types continue to return DateTime by creating a DateTime from Date's __toString()? e.g for RecurrenceRange

   public function setEndDate($val)
    {
        $this->_propDict["endDate"] = \Microsoft\Graph\Core\Models\Date::createFromDateTime($val);
         return $this;
    }
    
   public function getEndDate()
    {
        if (array_key_exists("endDate", $this->_propDict)) {
            if (is_a($this->_propDict["endDate"], "\Microsoft\Graph\Core\Models\Date") || is_null($this->_propDict["endDate"])) {
                return new \DateTime((string)$this->_propDict["endDate"]);
            } else {
                setEndDate($this->_propDict["endDate"]);
                return $this->_propDict["endDate"];
            }
        }
        return null;
    }

Unfortunately this might have undefined behaviour where it sometimes returns DateTime type for the getter sometimes Date depending on the type of the property on the propDict.

SilasKenneth avatar Nov 19 '21 03:11 SilasKenneth

Idea to make the Date type useful in v1 as well & fix the Date serialization issue (microsoftgraph/msgraph-sdk-php#704).. Would it be worthwhile to make the setters for Date types continue to accept a DateTime but set the property to a Date via createFromDateTime and getters for Date types continue to return DateTime by creating a DateTime from Date's __toString()? e.g for RecurrenceRange

   public function setEndDate($val)
    {
        $this->_propDict["endDate"] = \Microsoft\Graph\Core\Models\Date::createFromDateTime($val);
         return $this;
    }
    
   public function getEndDate()
    {
        if (array_key_exists("endDate", $this->_propDict)) {
            if (is_a($this->_propDict["endDate"], "\Microsoft\Graph\Core\Models\Date") || is_null($this->_propDict["endDate"])) {
                return new \DateTime((string)$this->_propDict["endDate"]);
            } else {
                setEndDate($this->_propDict["endDate"]);
                return $this->_propDict["endDate"];
            }
        }
        return null;
    }

Unfortunately this might have undefined behaviour where it sometimes returns DateTime type for the getter sometimes Date depending on the type of the property on the propDict.

Okay. I'll need to think more. We can leave Date out of v1 for this PR

Ndiritu avatar Nov 19 '21 07:11 Ndiritu