forked from loafle/openapi-generator-original
adding static setters/getters for models since members are no public
This commit is contained in:
parent
5de99bafa7
commit
109b7eeaec
@ -21,8 +21,9 @@ class ObjectSerializer {
|
||||
} else if (is_object($data)) {
|
||||
$values = array();
|
||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
||||
if ($data->$property !== null) {
|
||||
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$property);
|
||||
$getter = $data::$getters[$property];
|
||||
if ($data->$getter() !== null) {
|
||||
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
|
||||
}
|
||||
}
|
||||
$sanitized = $values;
|
||||
@ -131,9 +132,15 @@ class ObjectSerializer {
|
||||
} else {
|
||||
$instance = new $class();
|
||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||
$original_property_name = $instance::$attributeMap[$property];
|
||||
if (isset($original_property_name) && isset($data->$original_property_name)) {
|
||||
$instance->$property = self::deserialize($data->$original_property_name, $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));
|
||||
}
|
||||
}
|
||||
$deserialized = $instance;
|
||||
|
@ -30,13 +30,23 @@ use \ArrayAccess;
|
||||
|
||||
class {{classname}} implements ArrayAccess {
|
||||
static $swaggerTypes = array(
|
||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
static $attributeMap = array(
|
||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
static $setters = array(
|
||||
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
static $getters = array(
|
||||
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
{{#vars}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user