Skip to content

Commit fa77a47

Browse files
Merge pull request #11 from INDA-HR/manuel-sdk-fix
Manuel sdk fix
2 parents be52b15 + 66204a0 commit fa77a47

File tree

8 files changed

+784
-51
lines changed

8 files changed

+784
-51
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace OpenAPI\Client\Model;
4+
5+
abstract class CustomizableModelAbstract
6+
{
7+
public function __construct(private array $customizableFields)
8+
{
9+
}
10+
11+
/**
12+
* @return mixed
13+
*/
14+
public function getCustomizableFields(): array
15+
{
16+
return $this->customizableFields;
17+
}
18+
19+
/**
20+
* @param mixed $customizableFields
21+
* @return CustomizableModelAbstract
22+
*/
23+
public function setCustomizableFields(array $customizableFields): self
24+
{
25+
$this->customizableFields = $customizableFields;
26+
return $this;
27+
}
28+
29+
/**
30+
* @param array $customizableFields
31+
* @return $this
32+
*/
33+
public function addCustomizableFields(array $customizableFields): self
34+
{
35+
$fields = $this->customizableFields ?? [];
36+
$this->customizableFields = array_merge($fields, $customizableFields);
37+
return $this;
38+
}
39+
}

lib/Model/JobAdRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @link https://openapi-generator.tech
4242
* @implements \ArrayAccess<string, mixed>
4343
*/
44-
class JobAdRequest implements ModelInterface, ArrayAccess, \JsonSerializable
44+
class JobAdRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
4545
{
4646
public const DISCRIMINATOR = null;
4747

@@ -253,6 +253,7 @@ public function __construct(array $data = null)
253253
{
254254
$this->setIfExists('data', $data ?? [], null);
255255
$this->setIfExists('metadata', $data ?? [], null);
256+
parent::__construct([]);
256257
}
257258

258259
/**

lib/Model/JobadCommonData.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @link https://openapi-generator.tech
4242
* @implements \ArrayAccess<string, mixed>
4343
*/
44-
class JobadCommonData implements ModelInterface, ArrayAccess, \JsonSerializable
44+
class JobadCommonData extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
4545
{
4646
public const DISCRIMINATOR = null;
4747

@@ -400,6 +400,7 @@ public function __construct(array $data = null)
400400
$this->setIfExists('benefits', $data ?? [], null);
401401
$this->setIfExists('expiration_date', $data ?? [], null);
402402
$this->setIfExists('status', $data ?? [], null);
403+
parent::__construct([]);
403404
}
404405

405406
/**

lib/Model/JobadCommonOptionalData.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @link https://openapi-generator.tech
4242
* @implements \ArrayAccess<string, mixed>
4343
*/
44-
class JobadCommonOptionalData implements ModelInterface, ArrayAccess, \JsonSerializable
44+
class JobadCommonOptionalData extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
4545
{
4646
public const DISCRIMINATOR = null;
4747

@@ -400,6 +400,7 @@ public function __construct(array $data = null)
400400
$this->setIfExists('benefits', $data ?? [], null);
401401
$this->setIfExists('expiration_date', $data ?? [], null);
402402
$this->setIfExists('status', $data ?? [], null);
403+
parent::__construct([]);
403404
}
404405

405406
/**

lib/Model/PatchItemRequest.php

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,57 +41,57 @@
4141
* @link https://openapi-generator.tech
4242
* @implements \ArrayAccess<string, mixed>
4343
*/
44-
class PatchItemRequest implements ModelInterface, ArrayAccess, \JsonSerializable
44+
class PatchItemRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
4545
{
4646
public const DISCRIMINATOR = null;
4747

4848
/**
49-
* The original name of the model.
50-
*
51-
* @var string
52-
*/
49+
* The original name of the model.
50+
*
51+
* @var string
52+
*/
5353
protected static $openAPIModelName = 'PatchItemRequest';
5454

5555
/**
56-
* Array of property to type mappings. Used for (de)serialization
57-
*
58-
* @var string[]
59-
*/
56+
* Array of property to type mappings. Used for (de)serialization
57+
*
58+
* @var string[]
59+
*/
6060
protected static $openAPITypes = [
6161
'data' => '\OpenAPI\Client\Model\ResumeCommonData',
6262
'metadata' => '\OpenAPI\Client\Model\Metadata',
6363
'attachments' => '\OpenAPI\Client\Model\OptionalCVAttachmentSlimDocument'
6464
];
6565

6666
/**
67-
* Array of property to format mappings. Used for (de)serialization
68-
*
69-
* @var string[]
70-
* @phpstan-var array<string, string|null>
71-
* @psalm-var array<string, string|null>
72-
*/
67+
* Array of property to format mappings. Used for (de)serialization
68+
*
69+
* @var string[]
70+
* @phpstan-var array<string, string|null>
71+
* @psalm-var array<string, string|null>
72+
*/
7373
protected static $openAPIFormats = [
7474
'data' => null,
7575
'metadata' => null,
7676
'attachments' => null
7777
];
7878

7979
/**
80-
* Array of nullable properties. Used for (de)serialization
81-
*
82-
* @var boolean[]
83-
*/
80+
* Array of nullable properties. Used for (de)serialization
81+
*
82+
* @var boolean[]
83+
*/
8484
protected static array $openAPINullables = [
8585
'data' => false,
86-
'metadata' => false,
87-
'attachments' => false
86+
'metadata' => false,
87+
'attachments' => false
8888
];
8989

9090
/**
91-
* If a nullable field gets set to null, insert it here
92-
*
93-
* @var boolean[]
94-
*/
91+
* If a nullable field gets set to null, insert it here
92+
*
93+
* @var boolean[]
94+
*/
9595
protected array $openAPINullablesSetToNull = [];
9696

9797
/**
@@ -260,17 +260,18 @@ public function __construct(array $data = null)
260260
$this->setIfExists('data', $data ?? [], null);
261261
$this->setIfExists('metadata', $data ?? [], null);
262262
$this->setIfExists('attachments', $data ?? [], null);
263+
parent::__construct([]);
263264
}
264265

265266
/**
266-
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
267-
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
268-
* $this->openAPINullablesSetToNull array
269-
*
270-
* @param string $variableName
271-
* @param array $fields
272-
* @param mixed $defaultValue
273-
*/
267+
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
268+
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
269+
* $this->openAPINullablesSetToNull array
270+
*
271+
* @param string $variableName
272+
* @param array $fields
273+
* @param mixed $defaultValue
274+
*/
274275
private function setIfExists(string $variableName, array $fields, $defaultValue): void
275276
{
276277
if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
@@ -448,7 +449,7 @@ public function offsetUnset($offset): void
448449
#[\ReturnTypeWillChange]
449450
public function jsonSerialize()
450451
{
451-
return ObjectSerializer::sanitizeForSerialization($this);
452+
return ObjectSerializer::sanitizeForSerialization($this);
452453
}
453454

454455
/**
@@ -474,5 +475,3 @@ public function toHeaderValue()
474475
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
475476
}
476477
}
477-
478-

lib/Model/PatchJobAdRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @link https://openapi-generator.tech
4242
* @implements \ArrayAccess<string, mixed>
4343
*/
44-
class PatchJobAdRequest implements ModelInterface, ArrayAccess, \JsonSerializable
44+
class PatchJobAdRequest extends CustomizableModelAbstract implements ModelInterface, ArrayAccess, \JsonSerializable
4545
{
4646
public const DISCRIMINATOR = null;
4747

@@ -253,6 +253,7 @@ public function __construct(array $data = null)
253253
{
254254
$this->setIfExists('data', $data ?? [], null);
255255
$this->setIfExists('metadata', $data ?? [], null);
256+
parent::__construct([]);
256257
}
257258

258259
/**

lib/ObjectSerializer.php

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* ObjectSerializer
45
*
@@ -30,6 +31,7 @@
3031
namespace OpenAPI\Client;
3132

3233
use GuzzleHttp\Psr7\Utils;
34+
use OpenAPI\Client\Model\CustomizableModelAbstract;
3335
use OpenAPI\Client\Model\ModelInterface;
3436

3537
/**
@@ -64,7 +66,7 @@ public static function setDateTimeFormat($format)
6466
*
6567
* @return scalar|object|array|null serialized form of $data
6668
*/
67-
public static function sanitizeForSerialization($data, $type = null, $format = null)
69+
public static function sanitizeForSerialization($data, $type = null, $format = null, bool $root = true)
6870
{
6971
if (is_scalar($data) || null === $data) {
7072
return $data;
@@ -76,7 +78,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
7678

7779
if (is_array($data)) {
7880
foreach ($data as $property => $value) {
79-
$data[$property] = self::sanitizeForSerialization($value);
81+
$data[$property] = self::sanitizeForSerialization(data: $value, root: false);
8082
}
8183
return $data;
8284
}
@@ -100,20 +102,53 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
100102
}
101103
}
102104
if (($data::isNullable($property) && $data->isNullableSetToNull($property)) || $value !== null) {
103-
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
105+
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization(data: $value, type: $openAPIType, format: $formats[$property], root: false);
106+
}
107+
}
108+
if ($root) {
109+
if (is_subclass_of($data, CustomizableModelAbstract::class)) {
110+
$customFields = $data->getCustomizableFields();
111+
if (!empty($customFields)) {
112+
$originalValues = $values;
113+
$customFields = self::dotNotationToNestedArray($customFields);
114+
$values = array_merge_recursive($originalValues, $customFields);
115+
}
104116
}
105117
}
106118
} else {
107-
foreach($data as $property => $value) {
108-
$values[$property] = self::sanitizeForSerialization($value);
119+
foreach ($data as $property => $value) {
120+
$values[$property] = self::sanitizeForSerialization(data: $value, root: false);
109121
}
110122
}
123+
111124
return (object)$values;
112125
} else {
113126
return (string)$data;
114127
}
115128
}
116129

130+
/**
131+
*
132+
* @param array $dotNotationArray
133+
* @return mixed
134+
*/
135+
private static function dotNotationToNestedArray(array $dotNotationArray)
136+
{
137+
$nestedArray = [];
138+
foreach ($dotNotationArray as $key => $value) {
139+
$parts = explode('.', $key);
140+
$pointer = &$nestedArray;
141+
foreach ($parts as $part) {
142+
if (!isset($pointer[$part])) {
143+
$pointer[$part] = [];
144+
}
145+
$pointer = &$pointer[$part];
146+
}
147+
$pointer = $value;
148+
}
149+
return $nestedArray;
150+
}
151+
117152
/**
118153
* Sanitize filename by removing path.
119154
* e.g. ../../sun.gif becomes sun.gif
@@ -140,7 +175,9 @@ public static function sanitizeFilename($filename)
140175
*/
141176
public static function sanitizeTimestamp($timestamp)
142177
{
143-
if (!is_string($timestamp)) return $timestamp;
178+
if (!is_string($timestamp)) {
179+
return $timestamp;
180+
}
144181

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

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

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

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

0 commit comments

Comments
 (0)