forked from loafle/openapi-generator-original
[PHP] Fix discriminator handling (#4246)
* [PHP] Fix discriminator handling * [PHP] Fix discriminator handling (Update examples)
This commit is contained in:
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class AdditionalPropertiesClass implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Animal implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = 'className';
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
@@ -126,8 +128,8 @@ class Animal implements ArrayAccess
|
||||
$this->container['color'] = isset($data['color']) ? $data['color'] : 'red';
|
||||
|
||||
// Initialize discriminator property with the model name.
|
||||
$discrimintor = array_search('className', self::$attributeMap);
|
||||
$this->container[$discrimintor] = static::$swaggerModelName;
|
||||
$discriminator = array_search('className', self::$attributeMap);
|
||||
$this->container[$discriminator] = static::$swaggerModelName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class AnimalFarm implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ApiResponse implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ArrayOfArrayOfNumberOnly implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ArrayOfNumberOnly implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ArrayTest implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Cat extends Animal implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Category implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Client implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Dog extends Animal implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class EnumArrays implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class EnumTest implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class FormatTest implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class HasOnlyReadOnly implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class MapTest implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class MixedPropertiesAndAdditionalPropertiesClass implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -43,6 +43,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Model200Response implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ModelList implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -43,6 +43,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ModelReturn implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -43,6 +43,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Name implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class NumberOnly implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Order implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Pet implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class ReadOnlyFirst implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class SpecialModelName implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class Tag implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -42,6 +42,8 @@ use \ArrayAccess;
|
||||
*/
|
||||
class User implements ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = null;
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
* @var string
|
||||
|
||||
@@ -214,7 +214,7 @@ class ObjectSerializer
|
||||
*
|
||||
* @return object|array|null an single or an array of $class instances
|
||||
*/
|
||||
public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null)
|
||||
public static function deserialize($data, $class, $httpHeaders = null)
|
||||
{
|
||||
if (null === $data) {
|
||||
return null;
|
||||
@@ -225,7 +225,7 @@ class ObjectSerializer
|
||||
$subClass_array = explode(',', $inner, 2);
|
||||
$subClass = $subClass_array[1];
|
||||
foreach ($data as $key => $value) {
|
||||
$deserialized[$key] = self::deserialize($value, $subClass, null, $discriminator);
|
||||
$deserialized[$key] = self::deserialize($value, $subClass, null);
|
||||
}
|
||||
}
|
||||
return $deserialized;
|
||||
@@ -233,7 +233,7 @@ class ObjectSerializer
|
||||
$subClass = substr($class, 0, -2);
|
||||
$values = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$values[] = self::deserialize($value, $subClass, null, $discriminator);
|
||||
$values[] = self::deserialize($value, $subClass, null);
|
||||
}
|
||||
return $values;
|
||||
} elseif ($class === 'object') {
|
||||
@@ -271,6 +271,7 @@ class ObjectSerializer
|
||||
return $deserialized;
|
||||
} else {
|
||||
// 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 = '\Swagger\Client\Model\\' . $data->{$discriminator};
|
||||
if (is_subclass_of($subclass, $class)) {
|
||||
@@ -287,7 +288,7 @@ class ObjectSerializer
|
||||
|
||||
$propertyValue = $data->{$instance::attributeMap()[$property]};
|
||||
if (isset($propertyValue)) {
|
||||
$instance->$propertySetter(self::deserialize($propertyValue, $type, null, $discriminator));
|
||||
$instance->$propertySetter(self::deserialize($propertyValue, $type, null));
|
||||
}
|
||||
}
|
||||
return $instance;
|
||||
|
||||
Reference in New Issue
Block a user