|
4 | 4 |
|
5 | 5 | namespace ApiClients\Client\GitHub\Internal\Hydrator\Operation\Repos\Owner\Repo\Commits\CommitSha;
|
6 | 6 |
|
| 7 | +use ApiClients\Client\GitHub\Schema\BasicError; |
7 | 8 | use ApiClients\Client\GitHub\Schema\ValidationError;
|
8 | 9 | use EventSauce\ObjectHydrator\IterableList;
|
9 | 10 | use EventSauce\ObjectHydrator\ObjectMapper;
|
@@ -39,6 +40,7 @@ public function hydrateObject(string $className, array $payload): object
|
39 | 40 | {
|
40 | 41 | return match ($className) {
|
41 | 42 | 'ApiClients\Client\GitHub\Schema\ValidationError' => $this->hydrateApiClients⚡️Client⚡️GitHub⚡️Schema⚡️ValidationError($payload),
|
| 43 | + 'ApiClients\Client\GitHub\Schema\BasicError' => $this->hydrateApiClients⚡️Client⚡️GitHub⚡️Schema⚡️BasicError($payload), |
42 | 44 | default => throw UnableToHydrateObject::noHydrationDefined($className, $this->hydrationStack),
|
43 | 45 | };
|
44 | 46 | }
|
@@ -95,6 +97,69 @@ private function hydrateApiClients⚡️Client⚡️GitHub⚡️Schema⚡️Vali
|
95 | 97 | }
|
96 | 98 | }
|
97 | 99 |
|
| 100 | + private function hydrateApiClients⚡️Client⚡️GitHub⚡️Schema⚡️BasicError(array $payload): BasicError |
| 101 | + { |
| 102 | + $properties = []; |
| 103 | + $missingFields = []; |
| 104 | + try { |
| 105 | + $value = $payload['message'] ?? null; |
| 106 | + |
| 107 | + if ($value === null) { |
| 108 | + $properties['message'] = null; |
| 109 | + goto after_message; |
| 110 | + } |
| 111 | + |
| 112 | + $properties['message'] = $value; |
| 113 | + |
| 114 | + after_message: |
| 115 | + |
| 116 | + $value = $payload['documentation_url'] ?? null; |
| 117 | + |
| 118 | + if ($value === null) { |
| 119 | + $properties['documentationUrl'] = null; |
| 120 | + goto after_documentationUrl; |
| 121 | + } |
| 122 | + |
| 123 | + $properties['documentationUrl'] = $value; |
| 124 | + |
| 125 | + after_documentationUrl: |
| 126 | + |
| 127 | + $value = $payload['url'] ?? null; |
| 128 | + |
| 129 | + if ($value === null) { |
| 130 | + $properties['url'] = null; |
| 131 | + goto after_url; |
| 132 | + } |
| 133 | + |
| 134 | + $properties['url'] = $value; |
| 135 | + |
| 136 | + after_url: |
| 137 | + |
| 138 | + $value = $payload['status'] ?? null; |
| 139 | + |
| 140 | + if ($value === null) { |
| 141 | + $properties['status'] = null; |
| 142 | + goto after_status; |
| 143 | + } |
| 144 | + |
| 145 | + $properties['status'] = $value; |
| 146 | + |
| 147 | + after_status: |
| 148 | + } catch (Throwable $exception) { |
| 149 | + throw UnableToHydrateObject::dueToError('ApiClients\Client\GitHub\Schema\BasicError', $exception, stack: $this->hydrationStack); |
| 150 | + } |
| 151 | + |
| 152 | + if (count($missingFields) > 0) { |
| 153 | + throw UnableToHydrateObject::dueToMissingFields(BasicError::class, $missingFields, stack: $this->hydrationStack); |
| 154 | + } |
| 155 | + |
| 156 | + try { |
| 157 | + return new BasicError(...$properties); |
| 158 | + } catch (Throwable $exception) { |
| 159 | + throw UnableToHydrateObject::dueToError('ApiClients\Client\GitHub\Schema\BasicError', $exception, stack: $this->hydrationStack); |
| 160 | + } |
| 161 | + } |
| 162 | + |
98 | 163 | private function serializeViaTypeMap(string $accessor, object $object, array $payloadToTypeMap): array
|
99 | 164 | {
|
100 | 165 | foreach ($payloadToTypeMap as $payloadType => [$valueType, $method]) {
|
@@ -127,6 +192,7 @@ public function serializeObjectOfType(object $object, string $className): mixed
|
127 | 192 | 'DateTimeImmutable' => $this->serializeValueDateTimeImmutable($object),
|
128 | 193 | 'DateTimeInterface' => $this->serializeValueDateTimeInterface($object),
|
129 | 194 | 'ApiClients\Client\GitHub\Schema\ValidationError' => $this->serializeObjectApiClients⚡️Client⚡️GitHub⚡️Schema⚡️ValidationError($object),
|
| 195 | + 'ApiClients\Client\GitHub\Schema\BasicError' => $this->serializeObjectApiClients⚡️Client⚡️GitHub⚡️Schema⚡️BasicError($object), |
130 | 196 | default => throw new LogicException('No serialization defined for $className'),
|
131 | 197 | };
|
132 | 198 | } catch (Throwable $exception) {
|
@@ -218,6 +284,46 @@ private function serializeObjectApiClients⚡️Client⚡️GitHub⚡️Schema
|
218 | 284 | return $result;
|
219 | 285 | }
|
220 | 286 |
|
| 287 | + private function serializeObjectApiClients⚡️Client⚡️GitHub⚡️Schema⚡️BasicError(mixed $object): mixed |
| 288 | + { |
| 289 | + assert($object instanceof BasicError); |
| 290 | + $result = []; |
| 291 | + |
| 292 | + $message = $object->message; |
| 293 | + |
| 294 | + if ($message === null) { |
| 295 | + goto after_message; |
| 296 | + } |
| 297 | + |
| 298 | + after_message: $result['message'] = $message; |
| 299 | + |
| 300 | + $documentationUrl = $object->documentationUrl; |
| 301 | + |
| 302 | + if ($documentationUrl === null) { |
| 303 | + goto after_documentationUrl; |
| 304 | + } |
| 305 | + |
| 306 | + after_documentationUrl: $result['documentation_url'] = $documentationUrl; |
| 307 | + |
| 308 | + $url = $object->url; |
| 309 | + |
| 310 | + if ($url === null) { |
| 311 | + goto after_url; |
| 312 | + } |
| 313 | + |
| 314 | + after_url: $result['url'] = $url; |
| 315 | + |
| 316 | + $status = $object->status; |
| 317 | + |
| 318 | + if ($status === null) { |
| 319 | + goto after_status; |
| 320 | + } |
| 321 | + |
| 322 | + after_status: $result['status'] = $status; |
| 323 | + |
| 324 | + return $result; |
| 325 | + } |
| 326 | + |
221 | 327 | /**
|
222 | 328 | * @param class-string<T> $className
|
223 | 329 | * @param iterable<array> $payloads;
|
|
0 commit comments