-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathResponses.php
More file actions
80 lines (61 loc) 路 1.66 KB
/
Copy pathResponses.php
File metadata and controls
80 lines (61 loc) 路 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php declare(strict_types = 1);
namespace Contributte\OpenApi\Schema;
class Responses
{
/** @var Response[]|Reference[] */
private array $responses = [];
private ?VendorExtensions $vendorExtensions = null;
/**
* @param mixed[] $data
*/
public static function fromArray(array $data): Responses
{
$responses = new Responses();
foreach ($data as $key => $responseData) {
if (str_starts_with((string) $key, 'x-')) {
continue;
}
if (isset($responseData['$ref'])) {
$responses->setResponse((string) $key, Reference::fromArray($responseData));
} else {
$responses->setResponse((string) $key, Response::fromArray($responseData));
}
}
$responses->setVendorExtensions(VendorExtensions::fromArray($data));
return $responses;
}
public function setResponse(string $key, Response|Reference $response): void
{
$this->responses[$key] = $response;
}
/**
* @return mixed[]
*/
public function toArray(): array
{
$data = [];
foreach ($this->responses as $key => $response) {
if ($key === 'default') {
continue;
}
$data[$key] = $response->toArray();
}
// Default response last
if (isset($this->responses['default'])) {
$data['default'] = $this->responses['default']->toArray();
}
if ($this->vendorExtensions !== null) {
// array_merge() would renumber the numeric status code keys
$data = array_replace($data, $this->vendorExtensions->toArray());
}
return $data;
}
public function getVendorExtensions(): ?VendorExtensions
{
return $this->vendorExtensions;
}
public function setVendorExtensions(?VendorExtensions $vendorExtensions): void
{
$this->vendorExtensions = $vendorExtensions;
}
}