Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,56 @@ public static function deserialize($data, $class, $httpHeaders = null)
$instance = new $class();
foreach ($instance::swaggerTypes() as $property => $type) {
$propertySetter = $instance::setters()[$property];
$propertyName = self::convertToCamelCase($instance::attributeMap()[$property]);
if (!property_exists($data, $propertyName)) {
if (property_exists($data, self::convertCamelCaseToPascalCase($propertyName))) {
$propertyName = self::convertCamelCaseToPascalCase($propertyName);
} else {
$propertyName = self::convertCamelCaseToSnakeCase($propertyName);
}
}

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

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

private static function convertToCamelCase($property): string
{
if (str_contains($property, '_')) {
$arrStrings = explode('_', $property);
$count = count($arrStrings);
if ($count > 1) {
foreach ($arrStrings as $key => &$string) {
if ($key > 0) {
$string = ucfirst($string);
}
}
}
return implode($arrStrings);
}
return lcfirst($property);
}

private static function convertCamelCaseToPascalCase($property): string
{
return ucfirst($property);
}

private static function convertCamelCaseToSnakeCase($property): string
{
$chunks = preg_split('/(?=[A-Z])/', $property);
forEach($chunks as &$chunk) {
$chunk = lcfirst($chunk);
}
return implode('_', $chunks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,56 @@ public static function deserialize($data, $class, $httpHeaders = null)
$instance = new $class();
foreach ($instance::swaggerTypes() as $property => $type) {
$propertySetter = $instance::setters()[$property];
$propertyName = self::convertToCamelCase($instance::attributeMap()[$property]);
if (!property_exists($data, $propertyName)) {
if (property_exists($data, self::convertCamelCaseToPascalCase($propertyName))) {
$propertyName = self::convertCamelCaseToPascalCase($propertyName);
} else {
$propertyName = self::convertCamelCaseToSnakeCase($propertyName);
}
}

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

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

private static function convertToCamelCase($property): string
{
if (str_contains($property, '_')) {
$arrStrings = explode('_', $property);
$count = count($arrStrings);
if ($count > 1) {
foreach ($arrStrings as $key => &$string) {
if ($key > 0) {
$string = ucfirst($string);
}
}
}
return implode($arrStrings);
}
return lcfirst($property);
}

private static function convertCamelCaseToPascalCase($property): string
{
return ucfirst($property);
}

private static function convertCamelCaseToSnakeCase($property): string
{
$chunks = preg_split('/(?=[A-Z])/', $property);
forEach($chunks as &$chunk) {
$chunk = lcfirst($chunk);
}
return implode('_', $chunks);
}
}