Skip to content

Commit 46061fc

Browse files
Merge pull request #146 from vitormattos/fix/use-schemas-from-request-body
2 parents 89600bc + b73c587 commit 46061fc

File tree

5 files changed

+83
-10
lines changed

5 files changed

+83
-10
lines changed

generate-spec

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -955,20 +955,18 @@ foreach ($scopePaths as $scope => $paths) {
955955
foreach ($paths as $url => $urlRoutes) {
956956
foreach ($urlRoutes as $httpMethod => $routeData) {
957957
foreach ($routeData['responses'] as $statusCode => $responseData) {
958-
if (empty($responseData['content'])) {
959-
continue;
960-
}
961-
962-
foreach ($responseData['content'] as $contentType => $contentData) {
963-
if (isset($contentData['schema']) && is_array($contentData['schema'])) {
964-
$newSchemas = Helpers::collectUsedRefs($contentData['schema']);
965-
$usedSchemas = array_merge($usedSchemas, $newSchemas);
966-
}
958+
if (!empty($responseData['content'])) {
959+
$usedSchemas[] = Helpers::collectUsedRefs($responseData['content']);
967960
}
968961
}
962+
if (!empty($routeData['requestBody']['content'])) {
963+
$usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']);
964+
}
969965
}
970966
}
971967

968+
$usedSchemas = array_merge(...$usedSchemas);
969+
972970
$scopedSchemas = [];
973971
while ($usedSchema = array_shift($usedSchemas)) {
974972
if (!str_starts_with($usedSchema, '#/components/schemas/')) {

tests/lib/Controller/FederationController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @psalm-import-type NotificationsPushDevice from ResponseDefinitions
3737
* @psalm-import-type NotificationsNotification from ResponseDefinitions
3838
* @psalm-import-type NotificationsCollection from ResponseDefinitions
39+
* @psalm-import-type NotificationsRequestProperty from ResponseDefinitions
3940
*/
4041
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
4142
class FederationController extends OCSController {
@@ -58,12 +59,13 @@ public function federationByController(): DataResponse {
5859
*
5960
* Route is only in the default scope (moved from federation)
6061
*
62+
* @param NotificationsRequestProperty $property Property
6163
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
6264
*
6365
* 200: Personal settings updated
6466
*/
6567
#[OpenAPI]
66-
public function movedToDefaultScope(): DataResponse {
68+
public function movedToDefaultScope(array $property): DataResponse {
6769
return new DataResponse();
6870
}
6971
}

tests/lib/ResponseDefinitions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
* publicKey: string,
7171
* signature: string,
7272
* }
73+
*
74+
* @psalm-type NotificationsRequestProperty = array{
75+
* publicKey: string,
76+
* signature: string,
77+
* }
7378
*/
7479
class ResponseDefinitions {
7580
}

tests/openapi-full.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@
203203
"type": "string"
204204
}
205205
}
206+
},
207+
"RequestProperty": {
208+
"type": "object",
209+
"required": [
210+
"publicKey",
211+
"signature"
212+
],
213+
"properties": {
214+
"publicKey": {
215+
"type": "string"
216+
},
217+
"signature": {
218+
"type": "string"
219+
}
220+
}
206221
}
207222
}
208223
},
@@ -4367,6 +4382,25 @@
43674382
"basic_auth": []
43684383
}
43694384
],
4385+
"requestBody": {
4386+
"required": true,
4387+
"content": {
4388+
"application/json": {
4389+
"schema": {
4390+
"type": "object",
4391+
"required": [
4392+
"property"
4393+
],
4394+
"properties": {
4395+
"property": {
4396+
"$ref": "#/components/schemas/RequestProperty",
4397+
"description": "Property"
4398+
}
4399+
}
4400+
}
4401+
}
4402+
}
4403+
},
43704404
"parameters": [
43714405
{
43724406
"name": "apiVersion",

tests/openapi.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@
170170
"type": "string"
171171
}
172172
}
173+
},
174+
"RequestProperty": {
175+
"type": "object",
176+
"required": [
177+
"publicKey",
178+
"signature"
179+
],
180+
"properties": {
181+
"publicKey": {
182+
"type": "string"
183+
},
184+
"signature": {
185+
"type": "string"
186+
}
187+
}
173188
}
174189
}
175190
},
@@ -261,6 +276,25 @@
261276
"basic_auth": []
262277
}
263278
],
279+
"requestBody": {
280+
"required": true,
281+
"content": {
282+
"application/json": {
283+
"schema": {
284+
"type": "object",
285+
"required": [
286+
"property"
287+
],
288+
"properties": {
289+
"property": {
290+
"$ref": "#/components/schemas/RequestProperty",
291+
"description": "Property"
292+
}
293+
}
294+
}
295+
}
296+
}
297+
},
264298
"parameters": [
265299
{
266300
"name": "apiVersion",

0 commit comments

Comments
 (0)