Skip to content

Commit

Permalink
Merge pull request #169 from nextcloud/fix/openapitype/non-empty-list
Browse files Browse the repository at this point in the history
fix(OpenApiType): Support non-empty-list
  • Loading branch information
nickvergessen authored Sep 27, 2024
2 parents 2acf86d + c711397 commit cbc89b6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public static function resolve(string $context, array $definitions, ParamTagValu
items: self::resolve($context . ': items', $definitions, $node->type),
);
}
if ($node instanceof GenericTypeNode && ($node->type->name == 'array' || $node->type->name == 'list') && count($node->genericTypes) == 1) {
if ($node->genericTypes[0] instanceof IdentifierTypeNode && $node->genericTypes[0]->name == 'empty') {
if ($node instanceof GenericTypeNode && ($node->type->name === 'array' || $node->type->name === 'list' || $node->type->name === 'non-empty-list') && count($node->genericTypes) === 1) {
if ($node->genericTypes[0] instanceof IdentifierTypeNode && $node->genericTypes[0]->name === 'empty') {
return new OpenApiType(
context: $context,
type: 'array',
Expand All @@ -192,6 +192,7 @@ public static function resolve(string $context, array $definitions, ParamTagValu
context: $context,
type: 'array',
items: self::resolve($context, $definitions, $node->genericTypes[0]),
minItems: $node->type->name === 'non-empty-list' ? 1 : null,
);
}
if ($node instanceof GenericTypeNode && $node->type->name === 'value-of') {
Expand Down
1 change: 1 addition & 0 deletions tests/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* messageRichParameters?: array<string, mixed>,
* icon?: string,
* shouldNotify?: bool,
* nonEmptyList: non-empty-list<string>,
* }
*
* @psalm-type NotificationsPushDeviceBase = array{
Expand Down
10 changes: 9 additions & 1 deletion tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"subject",
"message",
"link",
"actions"
"actions",
"nonEmptyList"
],
"properties": {
"notification_id": {
Expand Down Expand Up @@ -121,6 +122,13 @@
},
"shouldNotify": {
"type": "boolean"
},
"nonEmptyList": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"subject",
"message",
"link",
"actions"
"actions",
"nonEmptyList"
],
"properties": {
"notification_id": {
Expand Down Expand Up @@ -121,6 +122,13 @@
},
"shouldNotify": {
"type": "boolean"
},
"nonEmptyList": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
}
},
Expand Down

0 comments on commit cbc89b6

Please sign in to comment.