Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/Model/CustomizableModelAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace OpenAPI\Client\Model;

abstract class CustomizableModelAbstract
{
public function __construct(private array $customizableFields)
{
}

/**
* @return mixed
*/
public function getCustomizableFields(): array
{
return $this->customizableFields;
}

/**
* @param mixed $customizableFields
* @return CustomizableModelAbstract
*/
public function setCustomizableFields(array $customizableFields): self
{
$this->customizableFields = $customizableFields;
return $this;
}

/**
* @param array $customizableFields
* @return $this
*/
public function addCustomizableFields(array $customizableFields): self
{
$fields = $this->customizableFields ?? [];
$this->customizableFields = array_merge($fields, $customizableFields);
return $this;
}
}
3 changes: 2 additions & 1 deletion lib/Model/JobAdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @link https://openapi-generator.tech
* @implements \ArrayAccess<string, mixed>
*/
class JobAdRequest implements ModelInterface, ArrayAccess, \JsonSerializable
class JobAdRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
{
public const DISCRIMINATOR = null;

Expand Down Expand Up @@ -253,6 +253,7 @@ public function __construct(array $data = null)
{
$this->setIfExists('data', $data ?? [], null);
$this->setIfExists('metadata', $data ?? [], null);
parent::__construct([]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Model/JobadCommonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @link https://openapi-generator.tech
* @implements \ArrayAccess<string, mixed>
*/
class JobadCommonData implements ModelInterface, ArrayAccess, \JsonSerializable
class JobadCommonData extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
{
public const DISCRIMINATOR = null;

Expand Down Expand Up @@ -400,6 +400,7 @@ public function __construct(array $data = null)
$this->setIfExists('benefits', $data ?? [], null);
$this->setIfExists('expiration_date', $data ?? [], null);
$this->setIfExists('status', $data ?? [], null);
parent::__construct([]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Model/JobadCommonOptionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @link https://openapi-generator.tech
* @implements \ArrayAccess<string, mixed>
*/
class JobadCommonOptionalData implements ModelInterface, ArrayAccess, \JsonSerializable
class JobadCommonOptionalData extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
{
public const DISCRIMINATOR = null;

Expand Down Expand Up @@ -400,6 +400,7 @@ public function __construct(array $data = null)
$this->setIfExists('benefits', $data ?? [], null);
$this->setIfExists('expiration_date', $data ?? [], null);
$this->setIfExists('status', $data ?? [], null);
parent::__construct([]);
}

/**
Expand Down
71 changes: 35 additions & 36 deletions lib/Model/PatchItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,57 @@
* @link https://openapi-generator.tech
* @implements \ArrayAccess<string, mixed>
*/
class PatchItemRequest implements ModelInterface, ArrayAccess, \JsonSerializable
class PatchItemRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
{
public const DISCRIMINATOR = null;

/**
* The original name of the model.
*
* @var string
*/
* The original name of the model.
*
* @var string
*/
protected static $openAPIModelName = 'PatchItemRequest';

/**
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $openAPITypes = [
'data' => '\OpenAPI\Client\Model\ResumeCommonData',
'metadata' => '\OpenAPI\Client\Model\Metadata',
'attachments' => '\OpenAPI\Client\Model\OptionalCVAttachmentSlimDocument'
];

/**
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
* @phpstan-var array<string, string|null>
* @psalm-var array<string, string|null>
*/
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
* @phpstan-var array<string, string|null>
* @psalm-var array<string, string|null>
*/
protected static $openAPIFormats = [
'data' => null,
'metadata' => null,
'attachments' => null
];

/**
* Array of nullable properties. Used for (de)serialization
*
* @var boolean[]
*/
* Array of nullable properties. Used for (de)serialization
*
* @var boolean[]
*/
protected static array $openAPINullables = [
'data' => false,
'metadata' => false,
'attachments' => false
'metadata' => false,
'attachments' => false
];

/**
* If a nullable field gets set to null, insert it here
*
* @var boolean[]
*/
* If a nullable field gets set to null, insert it here
*
* @var boolean[]
*/
protected array $openAPINullablesSetToNull = [];

/**
Expand Down Expand Up @@ -260,17 +260,18 @@ public function __construct(array $data = null)
$this->setIfExists('data', $data ?? [], null);
$this->setIfExists('metadata', $data ?? [], null);
$this->setIfExists('attachments', $data ?? [], null);
parent::__construct([]);
}

/**
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
* $this->openAPINullablesSetToNull array
*
* @param string $variableName
* @param array $fields
* @param mixed $defaultValue
*/
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
* $this->openAPINullablesSetToNull array
*
* @param string $variableName
* @param array $fields
* @param mixed $defaultValue
*/
private function setIfExists(string $variableName, array $fields, $defaultValue): void
{
if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
Expand Down Expand Up @@ -448,7 +449,7 @@ public function offsetUnset($offset): void
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return ObjectSerializer::sanitizeForSerialization($this);
return ObjectSerializer::sanitizeForSerialization($this);
}

/**
Expand All @@ -474,5 +475,3 @@ public function toHeaderValue()
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
}
}


3 changes: 2 additions & 1 deletion lib/Model/PatchJobAdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @link https://openapi-generator.tech
* @implements \ArrayAccess<string, mixed>
*/
class PatchJobAdRequest implements ModelInterface, ArrayAccess, \JsonSerializable
class PatchJobAdRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
{
public const DISCRIMINATOR = null;

Expand Down Expand Up @@ -253,6 +253,7 @@ public function __construct(array $data = null)
{
$this->setIfExists('data', $data ?? [], null);
$this->setIfExists('metadata', $data ?? [], null);
parent::__construct([]);
}

/**
Expand Down
57 changes: 48 additions & 9 deletions lib/ObjectSerializer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ObjectSerializer
*
Expand Down Expand Up @@ -30,6 +31,7 @@
namespace OpenAPI\Client;

use GuzzleHttp\Psr7\Utils;
use OpenAPI\Client\Model\CustomizableModelAbstract;
use OpenAPI\Client\Model\ModelInterface;

/**
Expand Down Expand Up @@ -64,7 +66,7 @@ public static function setDateTimeFormat($format)
*
* @return scalar|object|array|null serialized form of $data
*/
public static function sanitizeForSerialization($data, $type = null, $format = null)
public static function sanitizeForSerialization($data, $type = null, $format = null, bool $root = true)
{
if (is_scalar($data) || null === $data) {
return $data;
Expand All @@ -76,7 +78,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n

if (is_array($data)) {
foreach ($data as $property => $value) {
$data[$property] = self::sanitizeForSerialization($value);
$data[$property] = self::sanitizeForSerialization(data: $value, root: false);
}
return $data;
}
Expand All @@ -100,20 +102,53 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
}
}
if (($data::isNullable($property) && $data->isNullableSetToNull($property)) || $value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization(data: $value, type: $openAPIType, format: $formats[$property], root: false);
}
}
if ($root) {
if (is_subclass_of($data, CustomizableModelAbstract::class)) {
$customFields = $data->getCustomizableFields();
if (!empty($customFields)) {
$originalValues = $values;
$customFields = self::dotNotationToNestedArray($customFields);
$values = array_merge_recursive($originalValues, $customFields);
}
}
}
} else {
foreach($data as $property => $value) {
$values[$property] = self::sanitizeForSerialization($value);
foreach ($data as $property => $value) {
$values[$property] = self::sanitizeForSerialization(data: $value, root: false);
}
}

return (object)$values;
} else {
return (string)$data;
}
}

/**
*
* @param array $dotNotationArray
* @return mixed
*/
private static function dotNotationToNestedArray(array $dotNotationArray)
{
$nestedArray = [];
foreach ($dotNotationArray as $key => $value) {
$parts = explode('.', $key);
$pointer = &$nestedArray;
foreach ($parts as $part) {
if (!isset($pointer[$part])) {
$pointer[$part] = [];
}
$pointer = &$pointer[$part];
}
$pointer = $value;
}
return $nestedArray;
}

/**
* Sanitize filename by removing path.
* e.g. ../../sun.gif becomes sun.gif
Expand All @@ -140,7 +175,9 @@ public static function sanitizeFilename($filename)
*/
public static function sanitizeTimestamp($timestamp)
{
if (!is_string($timestamp)) return $timestamp;
if (!is_string($timestamp)) {
return $timestamp;
}

return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp);
}
Expand Down Expand Up @@ -236,7 +273,7 @@ public static function toQueryValue(
}

# Handle DateTime objects in query
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
if ($openApiType === "\\DateTime" && $value instanceof \DateTime) {
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
}

Expand All @@ -246,7 +283,9 @@ public static function toQueryValue(
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
// need to flatten array first
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
if (!is_array($arr)) return $arr;
if (!is_array($arr)) {
return $arr;
}

foreach ($arr as $k => $v) {
$prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k;
Expand Down Expand Up @@ -474,7 +513,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
// determine file name
if (
is_array($httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)
) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);
Expand Down
Loading