diff --git a/src/OpenApiType.php b/src/OpenApiType.php index dbb7e54..24c5a5f 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -220,9 +220,10 @@ public static function resolve(string $context, array $definitions, ParamTagValu ); } - if ($node instanceof GenericTypeNode && $node->type->name === 'array' && count($node->genericTypes) === 2 && $node->genericTypes[0] instanceof IdentifierTypeNode) { - $allowedTypes = ['string', 'lowercase-string', 'non-empty-string', 'non-empty-lowercase-string']; - if (in_array($node->genericTypes[0]->name, $allowedTypes, true)) { + if ($node instanceof GenericTypeNode && $node->type->name === 'array' && count($node->genericTypes) === 2 && ($node->genericTypes[0] instanceof IdentifierTypeNode || $node->genericTypes[0] instanceof GenericTypeNode)) { + $key = $node->genericTypes[0] instanceof IdentifierTypeNode ? $node->genericTypes[0]->name : $node->genericTypes[0]->type->name; + $allowedTypes = ['string', 'lowercase-string', 'non-empty-string', 'non-empty-lowercase-string', 'class-string']; + if (in_array($key, $allowedTypes, true)) { return new OpenApiType( context: $context, type: 'object', diff --git a/tests/lib/ResponseDefinitions.php b/tests/lib/ResponseDefinitions.php index 126f319..f37a73c 100644 --- a/tests/lib/ResponseDefinitions.php +++ b/tests/lib/ResponseDefinitions.php @@ -18,6 +18,7 @@ * type: string, * primary: bool, * class: class-string, + * arrayClass: array, int>, * } * * @psalm-type NotificationsCollection = list diff --git a/tests/openapi-full.json b/tests/openapi-full.json index 8552f7c..27c91d1 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -53,7 +53,8 @@ "link", "type", "primary", - "class" + "class", + "arrayClass" ], "properties": { "label": { @@ -71,6 +72,13 @@ "class": { "type": "string", "minLength": 1 + }, + "arrayClass": { + "type": "object", + "additionalProperties": { + "type": "integer", + "format": "int64" + } } } }, diff --git a/tests/openapi.json b/tests/openapi.json index 8a3b651..13269ee 100644 --- a/tests/openapi.json +++ b/tests/openapi.json @@ -53,7 +53,8 @@ "link", "type", "primary", - "class" + "class", + "arrayClass" ], "properties": { "label": { @@ -71,6 +72,13 @@ "class": { "type": "string", "minLength": 1 + }, + "arrayClass": { + "type": "object", + "additionalProperties": { + "type": "integer", + "format": "int64" + } } } },