From 5ca25cb21871cd2ba811dd1f3b437f3e5c1ffdaa Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 16 Jul 2024 08:16:30 +0200 Subject: [PATCH] fix(OpenApiType): Prevent arrays indexed by non-strings Signed-off-by: provokateurin --- src/OpenApiType.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OpenApiType.php b/src/OpenApiType.php index 9251f8c..e23c011 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -165,13 +165,12 @@ public static function resolve(string $context, array $definitions, ParamTagValu return new OpenApiType(type: "object", properties: $properties, required: count($required) > 0 ? $required : null); } - if ($node instanceof GenericTypeNode && $node->type->name == "array" && count($node->genericTypes) == 2 && $node->genericTypes[0] instanceof IdentifierTypeNode) { - if ($node->genericTypes[0]->name == "array-key") { - Logger::error($context, "Instead of 'array-key' use 'string' or 'int'"); - } - if ($node->genericTypes[0]->name == "string" || $node->genericTypes[0]->name == "array-key") { + if ($node instanceof GenericTypeNode && $node->type->name === "array" && count($node->genericTypes) === 2 && $node->genericTypes[0] instanceof IdentifierTypeNode) { + if ($node->genericTypes[0]->name === "string") { return new OpenApiType(type: "object", additionalProperties: self::resolve($context, $definitions, $node->genericTypes[1])); } + + Logger::panic($context, "JSON objects can only be indexed by 'string' but got '" . $node->genericTypes[0]->name . "'"); } if ($node instanceof GenericTypeNode && $node->type->name == "int" && count($node->genericTypes) == 2) {