Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use schemas only from request body #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading