PR: Fix error when giving an array as parameter to an endpoint body r… (#1037)

* PR: Fix error when giving an array as parameter to an endpoint body request

* PR #1037 - Fix issue with array as parameter to operation

* update samples

* PHP - ObjectSerializer::sanitizeForSerialization(): manage \stdClass objects properly

* update samples

* bug fix: missing "use" clause

* update samples

* Changes after @ackintosh review

* update samples
This commit is contained in:
Thomas Hansen 2018-09-19 12:58:56 +02:00 committed by Akihito Nakano
parent b7edad5cd0
commit ca9a4a2ff3
16 changed files with 336 additions and 312 deletions

View File

@ -19,6 +19,8 @@
namespace {{invokerPackage}}; namespace {{invokerPackage}};
use {{modelPackage}}\ModelInterface;
/** /**
* ObjectSerializer Class Doc Comment * ObjectSerializer Class Doc Comment
* *
@ -51,19 +53,25 @@ class ObjectSerializer
return $data; return $data;
} elseif (is_object($data)) { } elseif (is_object($data)) {
$values = []; $values = [];
$formats = $data::openAPIFormats(); if ($data instanceof ModelInterface) {
foreach ($data::openAPITypes() as $property => $openAPIType) { $formats = $data::openAPIFormats();
$getter = $data::getters()[$property]; foreach ($data::openAPITypes() as $property => $openAPIType) {
$value = $data->$getter(); $getter = $data::getters()[$property];
if ($value !== null $value = $data->$getter();
&& !in_array($openAPIType, [{{&primitives}}], true) if ($value !== null
&& method_exists($openAPIType, 'getAllowableEnumValues') && !in_array($openAPIType, [{{&primitives}}], true)
&& !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { && method_exists($openAPIType, 'getAllowableEnumValues')
$imploded = implode("', '", $openAPIType::getAllowableEnumValues()); && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
}
if ($value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
}
} }
if ($value !== null) { } else {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); foreach($data as $property => $value) {
$values[$property] = self::sanitizeForSerialization($value);
} }
} }
return (object)$values; return (object)$values;

View File

@ -444,10 +444,10 @@ use {{invokerPackage}}\ObjectSerializer;
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -307,10 +307,10 @@ class AnotherFakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -297,10 +297,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -554,10 +554,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -811,10 +811,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1068,10 +1068,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1283,10 +1283,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1513,10 +1513,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1780,10 +1780,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2183,10 +2183,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2470,10 +2470,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2689,10 +2689,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2924,10 +2924,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -307,10 +307,10 @@ class FakeClassnameTags123Api
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -259,10 +259,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -496,10 +496,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -771,10 +771,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1046,10 +1046,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1322,10 +1322,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1546,10 +1546,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1792,10 +1792,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2087,10 +2087,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2388,10 +2388,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -264,10 +264,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -517,10 +517,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -801,10 +801,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1068,10 +1068,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -259,10 +259,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -478,10 +478,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -697,10 +697,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -921,10 +921,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1193,10 +1193,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1476,10 +1476,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1681,10 +1681,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1919,10 +1919,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -29,6 +29,8 @@
namespace OpenAPI\Client; namespace OpenAPI\Client;
use OpenAPI\Client\Model\ModelInterface;
/** /**
* ObjectSerializer Class Doc Comment * ObjectSerializer Class Doc Comment
* *
@ -61,19 +63,25 @@ class ObjectSerializer
return $data; return $data;
} elseif (is_object($data)) { } elseif (is_object($data)) {
$values = []; $values = [];
$formats = $data::openAPIFormats(); if ($data instanceof ModelInterface) {
foreach ($data::openAPITypes() as $property => $openAPIType) { $formats = $data::openAPIFormats();
$getter = $data::getters()[$property]; foreach ($data::openAPITypes() as $property => $openAPIType) {
$value = $data->$getter(); $getter = $data::getters()[$property];
if ($value !== null $value = $data->$getter();
&& !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) if ($value !== null
&& method_exists($openAPIType, 'getAllowableEnumValues') && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
&& !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { && method_exists($openAPIType, 'getAllowableEnumValues')
$imploded = implode("', '", $openAPIType::getAllowableEnumValues()); && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
}
if ($value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
}
} }
if ($value !== null) { } else {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); foreach($data as $property => $value) {
$values[$property] = self::sanitizeForSerialization($value);
} }
} }
return (object)$values; return (object)$values;

View File

@ -307,10 +307,10 @@ class AnotherFakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -297,10 +297,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -554,10 +554,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -811,10 +811,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1068,10 +1068,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1283,10 +1283,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1513,10 +1513,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1780,10 +1780,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2183,10 +2183,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2470,10 +2470,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2689,10 +2689,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2924,10 +2924,10 @@ class FakeApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -307,10 +307,10 @@ class FakeClassnameTags123Api
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -259,10 +259,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -496,10 +496,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -771,10 +771,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1046,10 +1046,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1322,10 +1322,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1546,10 +1546,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1792,10 +1792,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2087,10 +2087,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -2388,10 +2388,10 @@ class PetApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -264,10 +264,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -517,10 +517,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -801,10 +801,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1068,10 +1068,10 @@ class StoreApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -259,10 +259,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -478,10 +478,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -697,10 +697,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -921,10 +921,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1193,10 +1193,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1476,10 +1476,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1681,10 +1681,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {
@ -1919,10 +1919,10 @@ class UserApi
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
// $_tempBody is the method argument, if present // $_tempBody is the method argument, if present
$httpBody = $_tempBody; if ($headers['Content-Type'] === 'application/json') {
// \stdClass has no __toString(), so we should encode it manually $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { } else {
$httpBody = \GuzzleHttp\json_encode($httpBody); $httpBody = $_tempBody;
} }
} elseif (count($formParams) > 0) { } elseif (count($formParams) > 0) {
if ($multipart) { if ($multipart) {

View File

@ -29,6 +29,8 @@
namespace OpenAPI\Client; namespace OpenAPI\Client;
use OpenAPI\Client\Model\ModelInterface;
/** /**
* ObjectSerializer Class Doc Comment * ObjectSerializer Class Doc Comment
* *
@ -61,19 +63,25 @@ class ObjectSerializer
return $data; return $data;
} elseif (is_object($data)) { } elseif (is_object($data)) {
$values = []; $values = [];
$formats = $data::openAPIFormats(); if ($data instanceof ModelInterface) {
foreach ($data::openAPITypes() as $property => $openAPIType) { $formats = $data::openAPIFormats();
$getter = $data::getters()[$property]; foreach ($data::openAPITypes() as $property => $openAPIType) {
$value = $data->$getter(); $getter = $data::getters()[$property];
if ($value !== null $value = $data->$getter();
&& !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true) if ($value !== null
&& method_exists($openAPIType, 'getAllowableEnumValues') && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
&& !in_array($value, $openAPIType::getAllowableEnumValues(), true)) { && method_exists($openAPIType, 'getAllowableEnumValues')
$imploded = implode("', '", $openAPIType::getAllowableEnumValues()); && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
}
if ($value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
}
} }
if ($value !== null) { } else {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); foreach($data as $property => $value) {
$values[$property] = self::sanitizeForSerialization($value);
} }
} }
return (object)$values; return (object)$values;