Skip to content

Commit edecd1d

Browse files
Merge pull request #273 from nextcloud/fix/openapitype/support-class-string
fix(OpenApiType): Support class-string
2 parents 18efd57 + 7b953bc commit edecd1d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

src/OpenApiType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ enum: [(int)$node->constExpr->value],
397397
);
398398
}
399399

400+
if ($node instanceof GenericTypeNode && $node->type->name === 'class-string') {
401+
return new OpenApiType(
402+
context: $context,
403+
type: 'string',
404+
minLength: 1,
405+
);
406+
}
407+
400408
if ($node instanceof ConstTypeNode) {
401409
Logger::panic($context, 'Constants are not supported');
402410
}

tests/lib/ResponseDefinitions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
namespace OCA\Notifications;
1111

12+
use OCA\Notifications\Controller\AdminSettingsController;
13+
1214
/**
1315
* @psalm-type NotificationsItem = array{
1416
* label: string,
1517
* link: string,
1618
* type: string,
1719
* primary: bool,
20+
* class: class-string<AdminSettingsController>,
1821
* }
1922
*
2023
* @psalm-type NotificationsCollection = list<NotificationsItem>

tests/openapi-full.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"label",
5353
"link",
5454
"type",
55-
"primary"
55+
"primary",
56+
"class"
5657
],
5758
"properties": {
5859
"label": {
@@ -66,6 +67,10 @@
6667
},
6768
"primary": {
6869
"type": "boolean"
70+
},
71+
"class": {
72+
"type": "string",
73+
"minLength": 1
6974
}
7075
}
7176
},

tests/openapi.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"label",
5353
"link",
5454
"type",
55-
"primary"
55+
"primary",
56+
"class"
5657
],
5758
"properties": {
5859
"label": {
@@ -66,6 +67,10 @@
6667
},
6768
"primary": {
6869
"type": "boolean"
70+
},
71+
"class": {
72+
"type": "string",
73+
"minLength": 1
6974
}
7075
}
7176
},

0 commit comments

Comments
 (0)