-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathContent.php
More file actions
102 lines (89 loc) · 2.43 KB
/
Content.php
File metadata and controls
102 lines (89 loc) · 2.43 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
<?php
declare(strict_types=1);
namespace SwaggerBake\Lib\OpenApi;
use JsonSerializable;
/**
* Class Content
*
* @package SwaggerBake\Lib\OpenApi
* @see https://swagger.io/docs/specification/describing-request-body/
*/
class Content implements JsonSerializable
{
/**
* @param string $mimeType A mimetype such as "application/json"
* @param \SwaggerBake\Lib\OpenApi\Schema|string $schema An instance of the schema or an OpenApi $ref string
* @todo add enum for $mimeType argument in PHP 8.1
*/
public function __construct(
private string $mimeType,
private Schema|string $schema,
) {
}
/**
* @return array
*/
public function toArray(): array
{
$vars = get_object_vars($this);
unset($vars['mimeType']);
unset($vars['schema']);
if ($this->schema instanceof Schema) {
if ($this->schema->getRefPath()) {
$vars['schema']['required'] = array_values($this->schema->getRequired());
$vars['schema']['allOf'][] = [
'$ref' => $this->schema->getRefPath(),
];
if (empty($vars['schema']['required'])) {
unset($vars['schema']['required']);
}
} else {
$vars['schema'] = $this->schema;
}
} elseif (is_string($this->schema)) {
$vars['schema']['$ref'] = $this->schema;
}
return $vars;
}
/**
* @inheritDoc
*/
public function jsonSerialize(): mixed
{
return $this->toArray();
}
/**
* @return string
*/
public function getMimeType(): string
{
return $this->mimeType;
}
/**
* @param string $mimeType Mime type e.g. application/json, application/xml, etc...
* @return $this
*/
public function setMimeType(string $mimeType)
{
$this->mimeType = $mimeType;
return $this;
}
/**
* @return \SwaggerBake\Lib\OpenApi\Schema|string
*/
public function getSchema(): Schema|string
{
return $this->schema;
}
/**
* Can be either a schema $ref string such as '#/components/schemas/Pet' or a Schema instance.
*
* @param \SwaggerBake\Lib\OpenApi\Schema|string $schema Schema
* @return $this
*/
public function setSchema(Schema|string $schema)
{
$this->schema = $schema;
return $this;
}
}