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)) {
|
} else if (is_object($data)) {
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
foreach (array_keys($data::$swaggerTypes) as $property) {
|
||||||
if ($data->$property !== null) {
|
$getter = $data::$getters[$property];
|
||||||
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$property);
|
if ($data->$getter() !== null) {
|
||||||
|
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sanitized = $values;
|
$sanitized = $values;
|
||||||
@ -131,9 +132,15 @@ class ObjectSerializer {
|
|||||||
} else {
|
} else {
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||||
$original_property_name = $instance::$attributeMap[$property];
|
$propertySetter = $instance::$setters[$property];
|
||||||
if (isset($original_property_name) && isset($data->$original_property_name)) {
|
|
||||||
$instance->$property = self::deserialize($data->$original_property_name, $type);
|
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;
|
$deserialized = $instance;
|
||||||
|
@ -30,13 +30,23 @@ use \ArrayAccess;
|
|||||||
|
|
||||||
class {{classname}} implements ArrayAccess {
|
class {{classname}} implements ArrayAccess {
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
);
|
);
|
||||||
|
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
|
);
|
||||||
|
|
||||||
|
static $setters = array(
|
||||||
|
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
|
||||||
|
{{/hasMore}}{{/vars}}
|
||||||
|
);
|
||||||
|
|
||||||
|
static $getters = array(
|
||||||
|
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
|
||||||
|
{{/hasMore}}{{/vars}}
|
||||||
);
|
);
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user