Skip to content

Commit 3874ffb

Browse files
Merge pull request #274 from nextcloud/fix/openapitype/class-string-array-key
2 parents 73a9a17 + e906ac2 commit 3874ffb

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/OpenApiType.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ public static function resolve(string $context, array $definitions, ParamTagValu
220220
);
221221
}
222222

223-
if ($node instanceof GenericTypeNode && $node->type->name === 'array' && count($node->genericTypes) === 2 && $node->genericTypes[0] instanceof IdentifierTypeNode) {
224-
$allowedTypes = ['string', 'lowercase-string', 'non-empty-string', 'non-empty-lowercase-string'];
225-
if (in_array($node->genericTypes[0]->name, $allowedTypes, true)) {
223+
if ($node instanceof GenericTypeNode && $node->type->name === 'array' && count($node->genericTypes) === 2 && ($node->genericTypes[0] instanceof IdentifierTypeNode || $node->genericTypes[0] instanceof GenericTypeNode)) {
224+
$key = $node->genericTypes[0] instanceof IdentifierTypeNode ? $node->genericTypes[0]->name : $node->genericTypes[0]->type->name;
225+
$allowedTypes = ['string', 'lowercase-string', 'non-empty-string', 'non-empty-lowercase-string', 'class-string'];
226+
if (in_array($key, $allowedTypes, true)) {
226227
return new OpenApiType(
227228
context: $context,
228229
type: 'object',

tests/lib/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* type: string,
1919
* primary: bool,
2020
* class: class-string<AdminSettingsController>,
21+
* arrayClass: array<class-string<AdminSettingsController>, int>,
2122
* }
2223
*
2324
* @psalm-type NotificationsCollection = list<NotificationsItem>

tests/openapi-full.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"link",
5858
"type",
5959
"primary",
60-
"class"
60+
"class",
61+
"arrayClass"
6162
],
6263
"properties": {
6364
"label": {
@@ -75,6 +76,13 @@
7576
"class": {
7677
"type": "string",
7778
"minLength": 1
79+
},
80+
"arrayClass": {
81+
"type": "object",
82+
"additionalProperties": {
83+
"type": "integer",
84+
"format": "int64"
85+
}
7886
}
7987
}
8088
},

tests/openapi.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"link",
5858
"type",
5959
"primary",
60-
"class"
60+
"class",
61+
"arrayClass"
6162
],
6263
"properties": {
6364
"label": {
@@ -75,6 +76,13 @@
7576
"class": {
7677
"type": "string",
7778
"minLength": 1
79+
},
80+
"arrayClass": {
81+
"type": "object",
82+
"additionalProperties": {
83+
"type": "integer",
84+
"format": "int64"
85+
}
7886
}
7987
}
8088
},

0 commit comments

Comments
 (0)