Skip to content

Commit 0eca967

Browse files
committed
fix(generate-spec): Include schemas only used in capabilities
Signed-off-by: provokateurin <[email protected]>
1 parent edecd1d commit 0eca967

File tree

8 files changed

+96
-15
lines changed

8 files changed

+96
-15
lines changed

generate-spec.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,15 @@
10141014
}
10151015
}
10161016

1017-
$usedRefs = array_merge(...$usedRefs);
1018-
10191017
$scopedSchemas = [];
1018+
foreach (['Capabilities', 'PublicCapabilities'] as $class) {
1019+
if (isset($schemas[$class])) {
1020+
$scopedSchemas[$class] = $schemas[$class];
1021+
$usedRefs[] = Helpers::collectUsedRefs($schemas[$class]);
1022+
}
1023+
}
1024+
1025+
$usedRefs = array_merge(...$usedRefs);
10201026
while ($usedRef = array_shift($usedRefs)) {
10211027
if (!str_starts_with((string)$usedRef, '#/components/schemas/')) {
10221028
continue;
@@ -1039,13 +1045,6 @@
10391045
$usedSchemas[] = $schemaName;
10401046
}
10411047

1042-
if (isset($schemas['Capabilities'])) {
1043-
$scopedSchemas['Capabilities'] = $schemas['Capabilities'];
1044-
}
1045-
if (isset($schemas['PublicCapabilities'])) {
1046-
$scopedSchemas['PublicCapabilities'] = $schemas['PublicCapabilities'];
1047-
}
1048-
10491048
if ($scopedSchemas === []) {
10501049
$scopedSchemas = new stdClass();
10511050
} else {

tests/lib/Capabilities.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
use OCP\Capabilities\ICapability;
1313

14+
/**
15+
* @psalm-import-type NotificationsSchemaOnlyInCapabilities from ResponseDefinitions
16+
*/
1417
class Capabilities implements ICapability {
1518
/**
16-
* @return array{test: array{a: int}}
19+
* @return array{test: array{a: int, b: NotificationsSchemaOnlyInCapabilities}}
1720
*/
1821
public function getCapabilities(): array {
1922
return [];

tests/lib/ResponseDefinitions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
* ref2: null|NotificationsPushDevice,
7171
* ref3: string|null|NotificationsPushDevice,
7272
* }
73+
*
74+
* @psalm-type NotificationsSchemaOnlyInCapabilities = array{
75+
* key: string,
76+
* }
7377
*/
7478
class ResponseDefinitions {
7579
}

tests/openapi-administration.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"test": {
3030
"type": "object",
3131
"required": [
32-
"a"
32+
"a",
33+
"b"
3334
],
3435
"properties": {
3536
"a": {
3637
"type": "integer",
3738
"format": "int64"
39+
},
40+
"b": {
41+
"$ref": "#/components/schemas/SchemaOnlyInCapabilities"
3842
}
3943
}
4044
}
@@ -115,6 +119,17 @@
115119
"type": "string"
116120
}
117121
}
122+
},
123+
"SchemaOnlyInCapabilities": {
124+
"type": "object",
125+
"required": [
126+
"key"
127+
],
128+
"properties": {
129+
"key": {
130+
"type": "string"
131+
}
132+
}
118133
}
119134
}
120135
},

tests/openapi-ex_app.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"test": {
3030
"type": "object",
3131
"required": [
32-
"a"
32+
"a",
33+
"b"
3334
],
3435
"properties": {
3536
"a": {
3637
"type": "integer",
3738
"format": "int64"
39+
},
40+
"b": {
41+
"$ref": "#/components/schemas/SchemaOnlyInCapabilities"
3842
}
3943
}
4044
}
@@ -82,6 +86,17 @@
8286
}
8387
}
8488
}
89+
},
90+
"SchemaOnlyInCapabilities": {
91+
"type": "object",
92+
"required": [
93+
"key"
94+
],
95+
"properties": {
96+
"key": {
97+
"type": "string"
98+
}
99+
}
85100
}
86101
}
87102
},

tests/openapi-federation.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"test": {
3030
"type": "object",
3131
"required": [
32-
"a"
32+
"a",
33+
"b"
3334
],
3435
"properties": {
3536
"a": {
3637
"type": "integer",
3738
"format": "int64"
39+
},
40+
"b": {
41+
"$ref": "#/components/schemas/SchemaOnlyInCapabilities"
3842
}
3943
}
4044
}
@@ -82,6 +86,17 @@
8286
}
8387
}
8488
}
89+
},
90+
"SchemaOnlyInCapabilities": {
91+
"type": "object",
92+
"required": [
93+
"key"
94+
],
95+
"properties": {
96+
"key": {
97+
"type": "string"
98+
}
99+
}
85100
}
86101
}
87102
},

tests/openapi-full.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"test": {
3030
"type": "object",
3131
"required": [
32-
"a"
32+
"a",
33+
"b"
3334
],
3435
"properties": {
3536
"a": {
3637
"type": "integer",
3738
"format": "int64"
39+
},
40+
"b": {
41+
"$ref": "#/components/schemas/SchemaOnlyInCapabilities"
3842
}
3943
}
4044
}
@@ -307,6 +311,17 @@
307311
]
308312
}
309313
}
314+
},
315+
"SchemaOnlyInCapabilities": {
316+
"type": "object",
317+
"required": [
318+
"key"
319+
],
320+
"properties": {
321+
"key": {
322+
"type": "string"
323+
}
324+
}
310325
}
311326
}
312327
},

tests/openapi.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"test": {
3030
"type": "object",
3131
"required": [
32-
"a"
32+
"a",
33+
"b"
3334
],
3435
"properties": {
3536
"a": {
3637
"type": "integer",
3738
"format": "int64"
39+
},
40+
"b": {
41+
"$ref": "#/components/schemas/SchemaOnlyInCapabilities"
3842
}
3943
}
4044
}
@@ -307,6 +311,17 @@
307311
]
308312
}
309313
}
314+
},
315+
"SchemaOnlyInCapabilities": {
316+
"type": "object",
317+
"required": [
318+
"key"
319+
],
320+
"properties": {
321+
"key": {
322+
"type": "string"
323+
}
324+
}
310325
}
311326
}
312327
},

0 commit comments

Comments
 (0)