[PHP] Fix discriminator handling (#4246)

* [PHP] Fix discriminator handling

* [PHP] Fix discriminator handling (Update examples)
This commit is contained in:
Robert Biehl
2016-11-25 09:12:41 +01:00
committed by wing328
parent c15743bfe6
commit 1ea9865a44
42 changed files with 216 additions and 119 deletions

View File

@@ -204,7 +204,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;
@@ -215,7 +215,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;
@@ -223,7 +223,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') {
@@ -261,6 +261,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 = '\{{invokerPackage}}\Model\\' . $data->{$discriminator};
if (is_subclass_of($subclass, $class)) {
@@ -277,7 +278,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;

View File

@@ -284,7 +284,7 @@ use \{{invokerPackage}}\ObjectSerializer;
);
{{#returnType}}
return [$this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader{{#discriminator}}, '{{discriminator}}'{{/discriminator}}), $statusCode, $httpHeader];
return [$this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader];
{{/returnType}}
{{^returnType}}
return [null, $statusCode, $httpHeader];

View File

@@ -1,5 +1,7 @@
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess
{
const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
/**
* The original name of the model.
* @var string
@@ -103,8 +105,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
{{#discriminator}}
// Initialize discriminator property with the model name.
$discrimintor = array_search('{{discriminator}}', self::$attributeMap);
$this->container[$discrimintor] = static::$swaggerModelName;
$discriminator = array_search('{{discriminator}}', self::$attributeMap);
$this->container[$discriminator] = static::$swaggerModelName;
{{/discriminator}}
}
@@ -370,4 +372,4 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this));
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
return Symfony\CS\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->fixers(
[
'ordered_use',
'phpdoc_order',
'short_array_syntax',
'strict',
'strict_param'
]
)
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
);

View File

@@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
script: "phpunit lib/Tests"
script: "vendor/bin/phpunit"

View File

@@ -4,7 +4,6 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
- API version: 1.0.0 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
- Build date: 2016-08-05T11:24:40.650+02:00
- Build package: class io.swagger.codegen.languages.PhpClientCodegen
## Requirements
@@ -46,7 +45,7 @@ To run the unit tests:
```
composer install
./vendor/bin/phpunit lib/Tests
./vendor/bin/phpunit
```
## Getting Started
@@ -86,20 +85,20 @@ Class | Method | HTTP request | Description
## Documentation For Authorization
## api_key
- **Type**: API key
- **API key parameter name**: api_key */ ' " =end -- \r\n \n \r
- **Location**: HTTP header
## petstore_auth
- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- **write:pets**: modify pets in your account */ ' " =end -- \r\n \n \r
- **read:pets**: read your pets */ ' " =end -- \r\n \n \r
## api_key
- **Type**: API key
- **API key parameter name**: api_key */ ' " =end -- \r\n \n \r
- **Location**: HTTP header
- **write:pets**: modify pets in your account *_/ ' \" =end -- \\r\\n \\n \\r
- **read:pets**: read your pets *_/ ' \" =end -- \\r\\n \\n \\r
## Author

View File

@@ -8,7 +8,7 @@
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"license": "Apache-2.0",
"authors": [
{
"name": "Swagger and contributors",
@@ -24,7 +24,8 @@
"require-dev": {
"phpunit/phpunit": "~4.8",
"satooshi/php-coveralls": "~1.0",
"squizlabs/php_codesniffer": "~2.6"
"squizlabs/php_codesniffer": "~2.6",
"friendsofphp/php-cs-fixer": "~1.12"
},
"autoload": {
"psr-4": { "Swagger\\Client\\" : "lib/" }

View File

@@ -40,9 +40,9 @@
namespace Swagger\Client\Api;
use \Swagger\Client\Configuration;
use \Swagger\Client\ApiClient;
use \Swagger\Client\ApiException;
use \Swagger\Client\Configuration;
use \Swagger\Client\ObjectSerializer;
/**
@@ -56,7 +56,6 @@ use \Swagger\Client\ObjectSerializer;
*/
class FakeApi
{
/**
* API Client
*
@@ -71,7 +70,7 @@ class FakeApi
*/
public function __construct(\Swagger\Client\ApiClient $apiClient = null)
{
if ($apiClient == null) {
if ($apiClient === null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r');
}
@@ -108,8 +107,8 @@ class FakeApi
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param string $test_code_inject____end____rn_n_r To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r (optional)
* @return void
* @throws \Swagger\Client\ApiException on non-2xx response
* @return void
*/
public function testCodeInjectEndRnNR($test_code_inject____end____rn_n_r = null)
{
@@ -123,22 +122,22 @@ class FakeApi
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param string $test_code_inject____end____rn_n_r To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
* @return array of null, HTTP status code, HTTP response headers (array of strings)
*/
public function testCodeInjectEndRnNRWithHttpInfo($test_code_inject____end____rn_n_r = null)
{
// parse inputs
$resourcePath = "/fake";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', '*_/ \" =end --'));
$queryParams = [];
$headerParams = [];
$formParams = [];
$_header_accept = $this->apiClient->selectHeaderAccept(['application/json', '*_/ \" =end --']);
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','*_/ \" =end --'));
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json', '*_/ \" =end --']);
// default format to json
$resourcePath = str_replace("{format}", "json", $resourcePath);
@@ -166,7 +165,7 @@ class FakeApi
'/fake'
);
return array(null, $statusCode, $httpHeader);
return [null, $statusCode, $httpHeader];
} catch (ApiException $e) {
switch ($e->getCode()) {
}
@@ -174,5 +173,4 @@ class FakeApi
throw $e;
}
}
}

View File

@@ -52,7 +52,6 @@ namespace Swagger\Client;
*/
class ApiClient
{
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
@@ -82,7 +81,7 @@ class ApiClient
*/
public function __construct(\Swagger\Client\Configuration $config = null)
{
if ($config == null) {
if ($config === null) {
$config = Configuration::getDefaultConfiguration();
}
@@ -151,8 +150,7 @@ class ApiClient
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null, $endpointPath = null)
{
$headers = array();
$headers = [];
// construct the http header
$headerParams = array_merge(
@@ -165,9 +163,9 @@ class ApiClient
}
// form data
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers, true)) {
$postData = http_build_query($postData);
} elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
} elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers, true)) { // json model
$postData = json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($postData));
}
@@ -175,7 +173,7 @@ class ApiClient
$curl = curl_init();
// set timeout, if needed
if ($this->config->getCurlTimeout() != 0) {
if ($this->config->getCurlTimeout() !== 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
}
// return the result on success, rather than just true
@@ -184,7 +182,7 @@ class ApiClient
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// disable SSL verification, if needed
if ($this->config->getSSLVerification() == false) {
if ($this->config->getSSLVerification() === false) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
}
@@ -193,24 +191,24 @@ class ApiClient
$url = ($url . '?' . http_build_query($queryParams));
}
if ($method == self::$POST) {
if ($method === self::$POST) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} elseif ($method == self::$HEAD) {
} elseif ($method === self::$HEAD) {
curl_setopt($curl, CURLOPT_NOBODY, true);
} elseif ($method == self::$OPTIONS) {
} elseif ($method === self::$OPTIONS) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} elseif ($method == self::$PATCH) {
} elseif ($method === self::$PATCH) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} elseif ($method == self::$PUT) {
} elseif ($method === self::$PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} elseif ($method == self::$DELETE) {
} elseif ($method === self::$DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} elseif ($method != self::$GET) {
} elseif ($method !== self::$GET) {
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
@@ -244,7 +242,7 @@ class ApiClient
}
// Handle the response
if ($response_info['http_code'] == 0) {
if ($response_info['http_code'] === 0) {
$curl_error_message = curl_error($curl);
// curl_exec can sometimes fail but still return a blank message from curl_error().
@@ -260,8 +258,8 @@ class ApiClient
throw $exception;
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
// return raw body if response is a file
if ($responseType == '\SplFileObject' || $responseType == 'string') {
return array($http_body, $response_info['http_code'], $http_header);
if ($responseType === '\SplFileObject' || $responseType === 'string') {
return [$http_body, $response_info['http_code'], $http_header];
}
$data = json_decode($http_body);
@@ -281,7 +279,7 @@ class ApiClient
$data
);
}
return array($data, $response_info['http_code'], $http_header);
return [$data, $response_info['http_code'], $http_header];
}
/**
@@ -330,7 +328,7 @@ class ApiClient
protected function httpParseHeaders($raw_headers)
{
// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
$headers = array();
$headers = [];
$key = '';
foreach (explode("\n", $raw_headers) as $h) {
@@ -340,14 +338,14 @@ class ApiClient
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = trim($h[1]);
} elseif (is_array($headers[$h[0]])) {
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
$headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]);
} else {
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
$headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]);
}
$key = $h[0];
} else {
if (substr($h[0], 0, 1) == "\t") {
if (substr($h[0], 0, 1) === "\t") {
$headers[$key] .= "\r\n\t".trim($h[0]);
} elseif (!$key) {
$headers[0] = trim($h[0]);

View File

@@ -52,7 +52,6 @@ namespace Swagger\Client;
*/
class Configuration
{
private static $defaultConfiguration = null;
/**
@@ -60,14 +59,14 @@ class Configuration
*
* @var string[]
*/
protected $apiKeys = array();
protected $apiKeys = [];
/**
* Associate array to store API prefix (e.g. Bearer)
*
* @var string[]
*/
protected $apiKeyPrefixes = array();
protected $apiKeyPrefixes = [];
/**
* Access token for OAuth
@@ -91,11 +90,11 @@ class Configuration
protected $password = '';
/**
* The default instance of ApiClient
* The default header(s)
*
* @var \Swagger\Client\ApiClient
* @var array
*/
protected $defaultHeaders = array();
protected $defaultHeaders = [];
/**
* The host
@@ -283,7 +282,7 @@ class Configuration
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
*
* @return ApiClient
* @return Configuration
*/
public function addDefaultHeader($headerName, $headerValue)
{
@@ -345,7 +344,7 @@ class Configuration
*
* @param string $userAgent the user agent of the api client
*
* @return ApiClient
* @return Configuration
*/
public function setUserAgent($userAgent)
{
@@ -372,7 +371,7 @@ class Configuration
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
*
* @return ApiClient
* @return Configuration
*/
public function setCurlTimeout($seconds)
{
@@ -493,7 +492,7 @@ class Configuration
*/
public static function getDefaultConfiguration()
{
if (self::$defaultConfiguration == null) {
if (self::$defaultConfiguration === null) {
self::$defaultConfiguration = new Configuration();
}

View File

@@ -48,7 +48,7 @@ use \ArrayAccess;
*
* @category Class */
// @description Model for testing reserved words *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
/**
/**
* @package Swagger\Client
* @author http://github.com/swagger-api/swagger-codegen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License v2
@@ -56,6 +56,8 @@ use \ArrayAccess;
*/
class ModelReturn implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string
@@ -66,9 +68,9 @@ class ModelReturn implements ArrayAccess
* Array of property to type mappings. Used for (de)serialization
* @var string[]
*/
protected static $swaggerTypes = array(
protected static $swaggerTypes = [
'return' => 'int'
);
];
public static function swaggerTypes()
{
@@ -79,36 +81,38 @@ class ModelReturn implements ArrayAccess
* Array of attributes where the key is the local name, and the value is the original name
* @var string[]
*/
protected static $attributeMap = array(
protected static $attributeMap = [
'return' => 'return'
);
];
/**
* Array of attributes to setter functions (for deserialization of responses)
* @var string[]
*/
protected static $setters = [
'return' => 'setReturn'
];
/**
* Array of attributes to getter functions (for serialization of requests)
* @var string[]
*/
protected static $getters = [
'return' => 'getReturn'
];
public static function attributeMap()
{
return self::$attributeMap;
}
/**
* Array of attributes to setter functions (for deserialization of responses)
* @var string[]
*/
protected static $setters = array(
'return' => 'setReturn'
);
public static function setters()
{
return self::$setters;
}
/**
* Array of attributes to getter functions (for serialization of requests)
* @var string[]
*/
protected static $getters = array(
'return' => 'getReturn'
);
public static function getters()
{
return self::$getters;
@@ -122,11 +126,11 @@ class ModelReturn implements ArrayAccess
* Associative array for storing property values
* @var mixed[]
*/
protected $container = array();
protected $container = [];
/**
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
* @param mixed[] $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
@@ -140,7 +144,7 @@ class ModelReturn implements ArrayAccess
*/
public function listInvalidProperties()
{
$invalid_properties = array();
$invalid_properties = [];
return $invalid_properties;
}
@@ -235,4 +239,3 @@ class ModelReturn implements ArrayAccess
}
}

View File

@@ -52,13 +52,12 @@ namespace Swagger\Client;
*/
class ObjectSerializer
{
/**
* Serialize data
*
* @param mixed $data the data to serialize
*
* @return string serialized form of $data
* @return string|object serialized form of $data
*/
public static function sanitizeForSerialization($data)
{
@@ -72,7 +71,7 @@ class ObjectSerializer
}
return $data;
} elseif (is_object($data)) {
$values = array();
$values = [];
foreach (array_keys($data::swaggerTypes()) as $property) {
$getter = $data::getters()[$property];
if ($data->$getter() !== null) {
@@ -121,7 +120,7 @@ class ObjectSerializer
* If it's a string, pass through unchanged. It will be url-encoded
* later.
*
* @param object $object an object to be serialized to a string
* @param string[]|string|\DateTime $object an object to be serialized to a string
*
* @return string the serialized object
*/
@@ -153,7 +152,7 @@ class ObjectSerializer
* the http body (form parameter). If it's a string, pass through unchanged
* If it's a datetime object, format it in ISO8601
*
* @param string $value the value of the form parameter
* @param string|\SplFileObject $value the value of the form parameter
*
* @return string the form string
*/
@@ -171,7 +170,7 @@ class ObjectSerializer
* the parameter. If it's a string, pass through unchanged
* If it's a datetime object, format it in ISO8601
*
* @param string $value the value of the parameter
* @param string|\DateTime $value the value of the parameter
*
* @return string the header string
*/
@@ -187,9 +186,10 @@ class ObjectSerializer
/**
* Serialize an array to a string.
*
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
*
* @return string
*/
@@ -220,33 +220,33 @@ class ObjectSerializer
/**
* Deserialize a JSON string into an object
*
* @param mixed $data object or primitive to be deserialized
* @param string $class class name is passed as a string
* @param string $httpHeaders HTTP headers
* @param string $discriminator discriminator if polymorphism is used
* @param mixed $data object or primitive to be deserialized
* @param string $class class name is passed as a string
* @param string[] $httpHeaders HTTP headers
* @param string $discriminator discriminator if polymorphism is used
*
* @return object an instance of $class
* @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;
} elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
$inner = substr($class, 4, -1);
$deserialized = array();
$deserialized = [];
if (strrpos($inner, ",") !== false) {
$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;
} elseif (strcasecmp(substr($class, -2), '[]') == 0) {
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
$subClass = substr($class, 0, -2);
$values = array();
$values = [];
foreach ($data as $key => $value) {
$values[] = self::deserialize($value, $subClass, null, $discriminator);
$values[] = self::deserialize($value, $subClass, null);
}
return $values;
} elseif ($class === 'object') {
@@ -264,7 +264,7 @@ class ObjectSerializer
} else {
return null;
}
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) {
} elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
settype($data, $class);
return $data;
} elseif ($class === '\SplFileObject') {
@@ -277,7 +277,6 @@ class ObjectSerializer
}
$deserialized = new \SplFileObject($filename, "w");
$byte_written = $deserialized->fwrite($data);
if (Configuration::getDefaultConfiguration()->getDebug()) {
error_log("[DEBUG] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.".PHP_EOL, 3, Configuration::getDefaultConfiguration()->getDebugFile());
}
@@ -285,6 +284,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)) {
@@ -301,7 +301,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;

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite>
<directory>./test/Api</directory>
<directory>./test/Model</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib/Api</directory>
<directory suffix=".php">./lib/Model</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class AdditionalPropertiesClass implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -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;
}
/**

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class AnimalFarm implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ApiResponse implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ArrayOfArrayOfNumberOnly implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ArrayOfNumberOnly implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ArrayTest implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Cat extends Animal implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Category implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Client implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Dog extends Animal implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class EnumArrays implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class EnumTest implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class FormatTest implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class HasOnlyReadOnly implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class MapTest implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class MixedPropertiesAndAdditionalPropertiesClass implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -43,6 +43,8 @@ use \ArrayAccess;
*/
class Model200Response implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ModelList implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -43,6 +43,8 @@ use \ArrayAccess;
*/
class ModelReturn implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -43,6 +43,8 @@ use \ArrayAccess;
*/
class Name implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class NumberOnly implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Order implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Pet implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class ReadOnlyFirst implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class SpecialModelName implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class Tag implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -42,6 +42,8 @@ use \ArrayAccess;
*/
class User implements ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
* @var string

View File

@@ -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;