From 0eca9677a1e56b66105586bf28f8076212b4b209 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 1 Oct 2025 14:51:57 +0200 Subject: [PATCH] fix(generate-spec): Include schemas only used in capabilities Signed-off-by: provokateurin --- generate-spec.php | 17 ++++++++--------- tests/lib/Capabilities.php | 5 ++++- tests/lib/ResponseDefinitions.php | 4 ++++ tests/openapi-administration.json | 17 ++++++++++++++++- tests/openapi-ex_app.json | 17 ++++++++++++++++- tests/openapi-federation.json | 17 ++++++++++++++++- tests/openapi-full.json | 17 ++++++++++++++++- tests/openapi.json | 17 ++++++++++++++++- 8 files changed, 96 insertions(+), 15 deletions(-) diff --git a/generate-spec.php b/generate-spec.php index 5b3515a..6136148 100755 --- a/generate-spec.php +++ b/generate-spec.php @@ -1014,9 +1014,15 @@ } } - $usedRefs = array_merge(...$usedRefs); - $scopedSchemas = []; + foreach (['Capabilities', 'PublicCapabilities'] as $class) { + if (isset($schemas[$class])) { + $scopedSchemas[$class] = $schemas[$class]; + $usedRefs[] = Helpers::collectUsedRefs($schemas[$class]); + } + } + + $usedRefs = array_merge(...$usedRefs); while ($usedRef = array_shift($usedRefs)) { if (!str_starts_with((string)$usedRef, '#/components/schemas/')) { continue; @@ -1039,13 +1045,6 @@ $usedSchemas[] = $schemaName; } - if (isset($schemas['Capabilities'])) { - $scopedSchemas['Capabilities'] = $schemas['Capabilities']; - } - if (isset($schemas['PublicCapabilities'])) { - $scopedSchemas['PublicCapabilities'] = $schemas['PublicCapabilities']; - } - if ($scopedSchemas === []) { $scopedSchemas = new stdClass(); } else { diff --git a/tests/lib/Capabilities.php b/tests/lib/Capabilities.php index fd415d5..389c680 100644 --- a/tests/lib/Capabilities.php +++ b/tests/lib/Capabilities.php @@ -11,9 +11,12 @@ use OCP\Capabilities\ICapability; +/** + * @psalm-import-type NotificationsSchemaOnlyInCapabilities from ResponseDefinitions + */ class Capabilities implements ICapability { /** - * @return array{test: array{a: int}} + * @return array{test: array{a: int, b: NotificationsSchemaOnlyInCapabilities}} */ public function getCapabilities(): array { return []; diff --git a/tests/lib/ResponseDefinitions.php b/tests/lib/ResponseDefinitions.php index 126f319..30cd20f 100644 --- a/tests/lib/ResponseDefinitions.php +++ b/tests/lib/ResponseDefinitions.php @@ -70,6 +70,10 @@ * ref2: null|NotificationsPushDevice, * ref3: string|null|NotificationsPushDevice, * } + * + * @psalm-type NotificationsSchemaOnlyInCapabilities = array{ + * key: string, + * } */ class ResponseDefinitions { } diff --git a/tests/openapi-administration.json b/tests/openapi-administration.json index ca4f4d3..c1b8450 100644 --- a/tests/openapi-administration.json +++ b/tests/openapi-administration.json @@ -29,12 +29,16 @@ "test": { "type": "object", "required": [ - "a" + "a", + "b" ], "properties": { "a": { "type": "integer", "format": "int64" + }, + "b": { + "$ref": "#/components/schemas/SchemaOnlyInCapabilities" } } } @@ -115,6 +119,17 @@ "type": "string" } } + }, + "SchemaOnlyInCapabilities": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + } + } } } }, diff --git a/tests/openapi-ex_app.json b/tests/openapi-ex_app.json index 8bd2e74..66967d6 100644 --- a/tests/openapi-ex_app.json +++ b/tests/openapi-ex_app.json @@ -29,12 +29,16 @@ "test": { "type": "object", "required": [ - "a" + "a", + "b" ], "properties": { "a": { "type": "integer", "format": "int64" + }, + "b": { + "$ref": "#/components/schemas/SchemaOnlyInCapabilities" } } } @@ -82,6 +86,17 @@ } } } + }, + "SchemaOnlyInCapabilities": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + } + } } } }, diff --git a/tests/openapi-federation.json b/tests/openapi-federation.json index fc73217..e4ca6f0 100644 --- a/tests/openapi-federation.json +++ b/tests/openapi-federation.json @@ -29,12 +29,16 @@ "test": { "type": "object", "required": [ - "a" + "a", + "b" ], "properties": { "a": { "type": "integer", "format": "int64" + }, + "b": { + "$ref": "#/components/schemas/SchemaOnlyInCapabilities" } } } @@ -82,6 +86,17 @@ } } } + }, + "SchemaOnlyInCapabilities": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + } + } } } }, diff --git a/tests/openapi-full.json b/tests/openapi-full.json index 8552f7c..95e1bed 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -29,12 +29,16 @@ "test": { "type": "object", "required": [ - "a" + "a", + "b" ], "properties": { "a": { "type": "integer", "format": "int64" + }, + "b": { + "$ref": "#/components/schemas/SchemaOnlyInCapabilities" } } } @@ -307,6 +311,17 @@ ] } } + }, + "SchemaOnlyInCapabilities": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + } + } } } }, diff --git a/tests/openapi.json b/tests/openapi.json index 8a3b651..39d1856 100644 --- a/tests/openapi.json +++ b/tests/openapi.json @@ -29,12 +29,16 @@ "test": { "type": "object", "required": [ - "a" + "a", + "b" ], "properties": { "a": { "type": "integer", "format": "int64" + }, + "b": { + "$ref": "#/components/schemas/SchemaOnlyInCapabilities" } } } @@ -307,6 +311,17 @@ ] } } + }, + "SchemaOnlyInCapabilities": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string" + } + } } } },