-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRequestBody.php
More file actions
106 lines (80 loc) 路 2.01 KB
/
Copy pathRequestBody.php
File metadata and controls
106 lines (80 loc) 路 2.01 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php declare(strict_types = 1);
namespace Contributte\OpenApi\Schema;
class RequestBody
{
private ?string $description = null;
/** @var MediaType[] */
private array $content = [];
private bool $required = false;
private ?VendorExtensions $vendorExtensions = null;
/**
* @param mixed[] $data
*/
public static function fromArray(array $data): RequestBody
{
$requestBody = new RequestBody();
$requestBody->setRequired($data['required'] ?? false);
$requestBody->setDescription($data['description'] ?? null);
foreach ($data['content'] ?? [] as $key => $mediaType) {
$requestBody->addMediaType($key, MediaType::fromArray($mediaType));
}
$requestBody->setVendorExtensions(VendorExtensions::fromArray($data));
return $requestBody;
}
/**
* @return mixed[]
*/
public function toArray(): array
{
$data = [];
if ($this->description !== null) {
$data['description'] = $this->description;
}
$data['content'] = [];
foreach ($this->content as $key => $mediaType) {
$data['content'][$key] = $mediaType->toArray();
}
if ($this->required) {
$data['required'] = true;
}
if ($this->vendorExtensions !== null) {
$data = array_merge($data, $this->vendorExtensions->toArray());
}
return $data;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function setRequired(bool $required): void
{
$this->required = $required;
}
public function addMediaType(string $key, MediaType $mediaType): void
{
$this->content[$key] = $mediaType;
}
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return MediaType[]
*/
public function getContent(): array
{
return $this->content;
}
public function isRequired(): bool
{
return $this->required;
}
public function getVendorExtensions(): ?VendorExtensions
{
return $this->vendorExtensions;
}
public function setVendorExtensions(?VendorExtensions $vendorExtensions): void
{
$this->vendorExtensions = $vendorExtensions;
}
}