19
19
use Astral \Serialize \OpenApi \Storage \OpenAPI \SchemaStorage ;
20
20
use Astral \Serialize \Resolvers \GroupResolver ;
21
21
use Astral \Serialize \Serialize ;
22
- use Astral \Serialize \SerializeContainer ;
23
22
use Astral \Serialize \Support \Factories \ContextFactory ;
24
23
use Psr \SimpleCache \InvalidArgumentException ;
25
24
use ReflectionMethod ;
@@ -32,8 +31,8 @@ public function __construct(
32
31
public string $ methodName ,
33
32
public reflectionMethod $ reflectionMethod ,
34
33
public Tag $ tag ,
35
- public Summary $ summary ,
36
- public Route $ route ,
34
+ public Summary | null $ summary ,
35
+ public Route | null $ route ,
37
36
public Headers |null $ headers ,
38
37
public array $ attributes ,
39
38
public RequestBody |null $ requestBody ,
@@ -58,7 +57,7 @@ public function build(): Method
58
57
$ requestBody = $ this ->buildRequestBody (
59
58
className:$ this ->getRequestBodyClass (),
60
59
contentType:$ this ->requestBody ->contentType ?? ContentTypeEnum::JSON ,
61
- groups: $ this ->requestBody ->groups ?? []
60
+ groups: $ this ->requestBody ->groups ?? []
62
61
);
63
62
64
63
$ response = $ this ->buildResponse (
@@ -71,10 +70,9 @@ className:$this->getResponseClass(),
71
70
return $ openAPIMethod ;
72
71
}
73
72
74
-
75
73
public function getRequestBodyClass (): string
76
74
{
77
- if ($ this ->requestBody ?->className){
75
+ if ($ this ->requestBody ?->className) {
78
76
return $ this ->requestBody ->className ;
79
77
}
80
78
@@ -88,12 +86,11 @@ public function getRequestBodyClass(): string
88
86
return '' ;
89
87
}
90
88
91
-
92
- public function buildRequestBody (string $ className ,ContentTypeEnum $ contentType ,array $ groups = []): RequestBodyStorage
89
+ public function buildRequestBody (string $ className , ContentTypeEnum $ contentType , array $ groups = []): RequestBodyStorage
93
90
{
94
91
$ openAPIRequestBody = new RequestBodyStorage ($ contentType );
95
92
if (is_subclass_of ($ className , Serialize::class)) {
96
- $ schemaStorage = (new SchemaStorage ())->build ($ this ->buildRequestParameterCollections ($ className ,$ groups ));
93
+ $ schemaStorage = (new SchemaStorage ())->build ($ this ->buildRequestParameterCollections ($ className , $ groups ));
97
94
$ openAPIRequestBody ->withParameter ($ schemaStorage );
98
95
}
99
96
@@ -102,7 +99,7 @@ public function buildRequestBody(string $className,ContentTypeEnum $contentType,
102
99
103
100
public function getResponseClass (): string
104
101
{
105
- if ($ this ->response ?->className){
102
+ if ($ this ->response ?->className) {
106
103
return $ this ->response ->className ;
107
104
}
108
105
@@ -118,18 +115,18 @@ public function getResponseClass(): string
118
115
/**
119
116
* @throws InvalidArgumentException
120
117
*/
121
- public function buildResponse (string $ className ,array $ groups = []): ResponseStorage
118
+ public function buildResponse (string $ className , array $ groups = []): ResponseStorage
122
119
{
123
120
$ responseStorage = new ResponseStorage ();
124
121
125
- $ baseResponse = Config::get ('response ' ,[]);
122
+ $ baseResponse = Config::get ('response ' , []);
126
123
127
124
if ($ className ) {
128
- $ schemaStorage = (new SchemaStorage ())->build ($ this ->buildResponseParameterCollections ($ className ,$ groups ));
125
+ $ schemaStorage = (new SchemaStorage ())->build ($ this ->buildResponseParameterCollections ($ className , $ groups ));
129
126
$ responseStorage ->withParameter ($ schemaStorage );
130
127
}
131
128
132
- if ($ baseResponse ){
129
+ if ($ baseResponse ) {
133
130
$ responseStorage ->addGlobParameters ($ baseResponse );
134
131
}
135
132
@@ -148,13 +145,13 @@ public function buildRequestParameterCollections(string $className, array $group
148
145
$ serializeContext = ContextFactory::build ($ className );
149
146
$ serializeContext ->setGroups ($ groups )->from ();
150
147
$ properties = $ serializeContext ->getGroupCollection ()->getProperties ();
151
- $ groups = $ groups ?: [$ className ];
148
+ $ groups = $ groups ?: [$ className ];
152
149
153
150
$ vols = [];
154
151
foreach ($ properties as $ property ) {
155
152
156
153
157
- if ($ property ->isInputIgnoreByGroups ($ groups ) || !$ this ->groupResolver ->resolveExistsGroupsByDataCollection ($ property , $ groups , $ className )){
154
+ if ($ property ->isInputIgnoreByGroups ($ groups ) || !$ this ->groupResolver ->resolveExistsGroupsByDataCollection ($ property , $ groups , $ className )) {
158
155
continue ;
159
156
}
160
157
@@ -192,12 +189,12 @@ public function buildResponseParameterCollections(string $className, array $grou
192
189
$ serializeContext = ContextFactory::build ($ className );
193
190
$ serializeContext ->from ();
194
191
$ properties = $ serializeContext ->getGroupCollection ()->getProperties ();
195
- $ groups = $ groups ?: [$ className ];
192
+ $ groups = $ groups ?: [$ className ];
196
193
197
194
$ vols = [];
198
195
foreach ($ properties as $ property ) {
199
196
200
- if ($ property ->isOutIgnoreByGroups ($ groups ) || !$ this ->groupResolver ->resolveExistsGroupsByDataCollection ($ property , $ groups , $ className )){
197
+ if ($ property ->isOutIgnoreByGroups ($ groups ) || !$ this ->groupResolver ->resolveExistsGroupsByDataCollection ($ property , $ groups , $ className )) {
201
198
continue ;
202
199
}
203
200
0 commit comments