7
7
use Tobyz \JsonApiServer \Endpoint \Index ;
8
8
use Tobyz \JsonApiServer \JsonApi ;
9
9
use Tobyz \JsonApiServer \Resource \Collection ;
10
- use Tobyz \JsonApiServer \Resource \Listable ;
11
10
use Tobyz \JsonApiServer \Resource \Resource ;
12
11
use Tobyz \JsonApiServer \Schema \Field \Field ;
13
12
use Tobyz \JsonApiServer \Schema \Field \Relationship ;
@@ -21,6 +20,8 @@ private function buildOpenApiContent(
21
20
bool $ multiple = false ,
22
21
bool $ included = true ,
23
22
bool $ links = false ,
23
+ bool $ countable = false ,
24
+ bool $ paginatable = false ,
24
25
): array {
25
26
$ item = count ($ resources ) === 1 ? $ resources [0 ] : ['oneOf ' => $ resources ];
26
27
@@ -33,6 +34,7 @@ private function buildOpenApiContent(
33
34
'links ' => $ links ? $ this ->buildLinksObject ($ name ) : [],
34
35
'data ' => $ multiple ? ['type ' => 'array ' , 'items ' => $ item ] : $ item ,
35
36
'included ' => $ included ? ['type ' => 'array ' ] : [],
37
+ 'meta ' => $ this ->buildMetaObject ($ countable , $ paginatable ),
36
38
]),
37
39
],
38
40
],
@@ -79,6 +81,27 @@ private function buildLinksObject(string $name): array
79
81
];
80
82
}
81
83
84
+ private function buildMetaObject (bool $ countable , bool $ paginatable ): array
85
+ {
86
+ if (!($ countable || $ paginatable )) {
87
+ return [];
88
+ }
89
+
90
+ return [
91
+ 'type ' => 'object ' ,
92
+ 'properties ' => [
93
+ 'page ' => [
94
+ 'type ' => 'object ' ,
95
+ 'properties ' => array_filter ([
96
+ 'total ' => $ countable ? ['type ' => 'integer ' ] : [],
97
+ 'limit ' => $ paginatable ? ['type ' => 'integer ' ] : [],
98
+ 'offset ' => $ paginatable ? ['type ' => 'integer ' ] : [],
99
+ ]),
100
+ ],
101
+ ],
102
+ ];
103
+ }
104
+
82
105
/**
83
106
* @throws ReflectionException
84
107
*/
0 commit comments