4
4
5
5
namespace Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Endpoint ;
6
6
7
+ use Assert \Assertion ;
7
8
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Contract \Endpoint ;
8
9
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Contract \Response ;
9
10
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Contract \Schema ;
10
11
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Response \CollectionResponse ;
12
+ use Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Schema \Filter \Filter ;
11
13
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Schema \Filter \FilterSetQueryParam ;
12
14
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Schema \Query \IncludeQueryParam ;
13
15
use Undabot \SymfonyJsonApi \Bridge \OpenApi \Model \JsonApi \Schema \Resource \ReadSchema ;
@@ -26,24 +28,25 @@ class ResourceCollectionEndpoint implements Endpoint
26
28
/** @var mixed[] */
27
29
private $ filters ;
28
30
29
- /** @var mixed[] */
31
+ /** @var array<string, ReadSchema> */
30
32
private $ includes ;
31
33
32
34
/** @var mixed[] */
33
35
private $ fields ;
34
36
35
- /** @var mixed[] */
37
+ /**
38
+ * @var mixed[]
39
+ *
40
+ * @psalm-suppress UnusedProperty
41
+ */
36
42
private $ sorts ;
37
43
38
44
/** @var null|Schema */
39
45
private $ pagination ;
40
46
41
47
/**
42
- * @param mixed[] $filters
43
- * @param mixed[] $sorts
44
- * @param mixed[] $includes
45
- * @param mixed[] $fields
46
- * @param mixed[] $errorResponses
48
+ * @param Filter[] $filters
49
+ * @param array<string, ReadSchema> $includes
47
50
*/
48
51
public function __construct (
49
52
ReadSchema $ schema ,
@@ -59,13 +62,17 @@ public function __construct(
59
62
$ this ->path = $ path ;
60
63
$ this ->includes = $ includes ;
61
64
62
- $ this ->responses = array_merge (
65
+ Assertion::allIsInstanceOf ($ this ->includes , ReadSchema::class);
66
+
67
+ /** @var Response[] $responses */
68
+ $ responses = array_merge (
63
69
[
64
70
new CollectionResponse ($ this ->schema , $ this ->includes ),
65
71
],
66
72
$ errorResponses
67
73
);
68
74
75
+ $ this ->responses = $ responses ;
69
76
$ this ->filters = $ filters ;
70
77
$ this ->sorts = $ sorts ;
71
78
$ this ->fields = $ fields ;
@@ -101,6 +108,7 @@ public function getParams(): array
101
108
}
102
109
103
110
if (false === empty ($ this ->filters )) {
111
+ Assertion::allIsInstanceOf ($ this ->filters , Filter::class);
104
112
$ filterSet = new FilterSetQueryParam ('filter ' , $ this ->filters );
105
113
$ queryParams [] = $ filterSet ->toOpenApi ();
106
114
}
@@ -116,7 +124,6 @@ public function toOpenApi(): array
116
124
{
117
125
$ responses = [];
118
126
119
- /** @var Response $response */
120
127
foreach ($ this ->responses as $ response ) {
121
128
$ responses [$ response ->getStatusCode ()] = $ response ->toOpenApi ();
122
129
}
@@ -130,4 +137,9 @@ public function toOpenApi(): array
130
137
'responses ' => $ responses ,
131
138
];
132
139
}
140
+
141
+ public function getSorts (): array
142
+ {
143
+ return $ this ->sorts ;
144
+ }
133
145
}
0 commit comments