Skip to content

Commit

Permalink
Merge pull request #38 from nextcloud/bugfix/noid/support-int-enums-n…
Browse files Browse the repository at this point in the history
…o-tests

fix(parameters): Support int numerals
  • Loading branch information
nickvergessen authored Dec 6, 2023
2 parents 16c27a1 + 2907df9 commit fe3d059
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,6 +226,7 @@ enum: [$node->constExpr->value],
return new OpenApiType(
type: "integer",
format: "int64",
enum: [(int) $node->constExpr->value],
);
}

Expand Down

0 comments on commit fe3d059

Please sign in to comment.