From c711397635b61819baef7cd404d6480ed3394a0a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 27 Sep 2024 08:52:21 +0200 Subject: [PATCH] fix(OpenApiType): Support non-empty-list Signed-off-by: provokateurin --- src/OpenApiType.php | 5 +++-- tests/lib/ResponseDefinitions.php | 1 + tests/openapi-full.json | 10 +++++++++- tests/openapi.json | 10 +++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/OpenApiType.php b/src/OpenApiType.php index 685ccf5..8d0224a 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -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', @@ -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') { diff --git a/tests/lib/ResponseDefinitions.php b/tests/lib/ResponseDefinitions.php index 46f9571..a99ee94 100644 --- a/tests/lib/ResponseDefinitions.php +++ b/tests/lib/ResponseDefinitions.php @@ -43,6 +43,7 @@ * messageRichParameters?: array, * icon?: string, * shouldNotify?: bool, + * nonEmptyList: non-empty-list, * } * * @psalm-type NotificationsPushDeviceBase = array{ diff --git a/tests/openapi-full.json b/tests/openapi-full.json index 3e382f6..6147403 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -61,7 +61,8 @@ "subject", "message", "link", - "actions" + "actions", + "nonEmptyList" ], "properties": { "notification_id": { @@ -121,6 +122,13 @@ }, "shouldNotify": { "type": "boolean" + }, + "nonEmptyList": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 } } }, diff --git a/tests/openapi.json b/tests/openapi.json index 4e60b80..c53cff8 100644 --- a/tests/openapi.json +++ b/tests/openapi.json @@ -61,7 +61,8 @@ "subject", "message", "link", - "actions" + "actions", + "nonEmptyList" ], "properties": { "notification_id": { @@ -121,6 +122,13 @@ }, "shouldNotify": { "type": "boolean" + }, + "nonEmptyList": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 } } },