From 2907df9050b1b2e1bb14723315e6153fb47bcbed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 10 Nov 2023 12:51:01 +0100 Subject: [PATCH] fix(parameters): Support int numerals Signed-off-by: Joas Schilling --- src/OpenApiType.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/OpenApiType.php b/src/OpenApiType.php index b86e85e..07f9b31 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -161,6 +161,27 @@ static function resolve(string $context, array $definitions, ParamTagValueNode|N return new OpenApiType(type: "string", enum: $values); } + if ($isUnion && count($node->types) == count(array_filter($node->types, fn($type) => $type instanceof ConstTypeNode && $type->constExpr instanceof ConstExprIntegerNode))) { + $values = []; + /** @var ConstTypeNode $type */ + foreach ($node->types as $type) { + $values[] = (int) $type->constExpr->value; + } + + if (count(array_filter($values, fn(string $value) => $value == '')) > 0) { + // Not a valid enum + return new OpenApiType( + type: "integer", + format: "int64", + ); + } + + return new OpenApiType( + type: "integer", + format: "int64", + enum: $values, + ); + } if ($isUnion || $isIntersection) { $nullable = false; @@ -205,6 +226,7 @@ enum: [$node->constExpr->value], return new OpenApiType( type: "integer", format: "int64", + enum: [(int) $node->constExpr->value], ); }