Skip to content

Commit

Permalink
Merge pull request #146 from vitormattos/fix/use-schemas-from-request…
Browse files Browse the repository at this point in the history
…-body
  • Loading branch information
provokateurin authored Aug 5, 2024
2 parents 89600bc + b73c587 commit 46061fc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
16 changes: 7 additions & 9 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -955,20 +955,18 @@ foreach ($scopePaths as $scope => $paths) {
foreach ($paths as $url => $urlRoutes) {
foreach ($urlRoutes as $httpMethod => $routeData) {
foreach ($routeData['responses'] as $statusCode => $responseData) {
if (empty($responseData['content'])) {
continue;
}

foreach ($responseData['content'] as $contentType => $contentData) {
if (isset($contentData['schema']) && is_array($contentData['schema'])) {
$newSchemas = Helpers::collectUsedRefs($contentData['schema']);
$usedSchemas = array_merge($usedSchemas, $newSchemas);
}
if (!empty($responseData['content'])) {
$usedSchemas[] = Helpers::collectUsedRefs($responseData['content']);
}
}
if (!empty($routeData['requestBody']['content'])) {
$usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']);
}
}
}

$usedSchemas = array_merge(...$usedSchemas);

$scopedSchemas = [];
while ($usedSchema = array_shift($usedSchemas)) {
if (!str_starts_with($usedSchema, '#/components/schemas/')) {
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @psalm-import-type NotificationsPushDevice from ResponseDefinitions
* @psalm-import-type NotificationsNotification from ResponseDefinitions
* @psalm-import-type NotificationsCollection from ResponseDefinitions
* @psalm-import-type NotificationsRequestProperty from ResponseDefinitions
*/
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
class FederationController extends OCSController {
Expand All @@ -58,12 +59,13 @@ public function federationByController(): DataResponse {
*
* Route is only in the default scope (moved from federation)
*
* @param NotificationsRequestProperty $property Property
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[OpenAPI]
public function movedToDefaultScope(): DataResponse {
public function movedToDefaultScope(array $property): DataResponse {
return new DataResponse();
}
}
5 changes: 5 additions & 0 deletions tests/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
* publicKey: string,
* signature: string,
* }
*
* @psalm-type NotificationsRequestProperty = array{
* publicKey: string,
* signature: string,
* }
*/
class ResponseDefinitions {
}
34 changes: 34 additions & 0 deletions tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@
"type": "string"
}
}
},
"RequestProperty": {
"type": "object",
"required": [
"publicKey",
"signature"
],
"properties": {
"publicKey": {
"type": "string"
},
"signature": {
"type": "string"
}
}
}
}
},
Expand Down Expand Up @@ -4367,6 +4382,25 @@
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"property"
],
"properties": {
"property": {
"$ref": "#/components/schemas/RequestProperty",
"description": "Property"
}
}
}
}
}
},
"parameters": [
{
"name": "apiVersion",
Expand Down
34 changes: 34 additions & 0 deletions tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@
"type": "string"
}
}
},
"RequestProperty": {
"type": "object",
"required": [
"publicKey",
"signature"
],
"properties": {
"publicKey": {
"type": "string"
},
"signature": {
"type": "string"
}
}
}
}
},
Expand Down Expand Up @@ -261,6 +276,25 @@
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"property"
],
"properties": {
"property": {
"$ref": "#/components/schemas/RequestProperty",
"description": "Property"
}
}
}
}
}
},
"parameters": [
{
"name": "apiVersion",
Expand Down

0 comments on commit 46061fc

Please sign in to comment.