Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions tests/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* type: string,
* primary: bool,
* class: class-string<AdminSettingsController>,
* arrayClass: array<class-string<AdminSettingsController>, int>,
* }
*
* @psalm-type NotificationsCollection = list<NotificationsItem>
Expand Down
10 changes: 9 additions & 1 deletion tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"link",
"type",
"primary",
"class"
"class",
"arrayClass"
],
"properties": {
"label": {
Expand All @@ -71,6 +72,13 @@
"class": {
"type": "string",
"minLength": 1
},
"arrayClass": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"link",
"type",
"primary",
"class"
"class",
"arrayClass"
],
"properties": {
"label": {
Expand All @@ -71,6 +72,13 @@
"class": {
"type": "string",
"minLength": 1
},
"arrayClass": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
}
}
},
Expand Down