Skip to content

Commit cbc89b6

Browse files
Merge pull request #169 from nextcloud/fix/openapitype/non-empty-list
fix(OpenApiType): Support non-empty-list
2 parents 2acf86d + c711397 commit cbc89b6

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/OpenApiType.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public static function resolve(string $context, array $definitions, ParamTagValu
180180
items: self::resolve($context . ': items', $definitions, $node->type),
181181
);
182182
}
183-
if ($node instanceof GenericTypeNode && ($node->type->name == 'array' || $node->type->name == 'list') && count($node->genericTypes) == 1) {
184-
if ($node->genericTypes[0] instanceof IdentifierTypeNode && $node->genericTypes[0]->name == 'empty') {
183+
if ($node instanceof GenericTypeNode && ($node->type->name === 'array' || $node->type->name === 'list' || $node->type->name === 'non-empty-list') && count($node->genericTypes) === 1) {
184+
if ($node->genericTypes[0] instanceof IdentifierTypeNode && $node->genericTypes[0]->name === 'empty') {
185185
return new OpenApiType(
186186
context: $context,
187187
type: 'array',
@@ -192,6 +192,7 @@ public static function resolve(string $context, array $definitions, ParamTagValu
192192
context: $context,
193193
type: 'array',
194194
items: self::resolve($context, $definitions, $node->genericTypes[0]),
195+
minItems: $node->type->name === 'non-empty-list' ? 1 : null,
195196
);
196197
}
197198
if ($node instanceof GenericTypeNode && $node->type->name === 'value-of') {

tests/lib/ResponseDefinitions.php

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* messageRichParameters?: array<string, mixed>,
4444
* icon?: string,
4545
* shouldNotify?: bool,
46+
* nonEmptyList: non-empty-list<string>,
4647
* }
4748
*
4849
* @psalm-type NotificationsPushDeviceBase = array{

tests/openapi-full.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"subject",
6262
"message",
6363
"link",
64-
"actions"
64+
"actions",
65+
"nonEmptyList"
6566
],
6667
"properties": {
6768
"notification_id": {
@@ -121,6 +122,13 @@
121122
},
122123
"shouldNotify": {
123124
"type": "boolean"
125+
},
126+
"nonEmptyList": {
127+
"type": "array",
128+
"items": {
129+
"type": "string"
130+
},
131+
"minItems": 1
124132
}
125133
}
126134
},

tests/openapi.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"subject",
6262
"message",
6363
"link",
64-
"actions"
64+
"actions",
65+
"nonEmptyList"
6566
],
6667
"properties": {
6768
"notification_id": {
@@ -121,6 +122,13 @@
121122
},
122123
"shouldNotify": {
123124
"type": "boolean"
125+
},
126+
"nonEmptyList": {
127+
"type": "array",
128+
"items": {
129+
"type": "string"
130+
},
131+
"minItems": 1
124132
}
125133
}
126134
},

0 commit comments

Comments
 (0)