diff --git a/src/Processors/ExpandEnums.php b/src/Processors/ExpandEnums.php index 6865fb85..4a7cd30d 100644 --- a/src/Processors/ExpandEnums.php +++ b/src/Processors/ExpandEnums.php @@ -79,7 +79,19 @@ protected function expandSchemaEnum(Analysis $analysis): void } else { // might be an array of \UnitEnum::class, string, int, etc... assert(is_array($schema->enum)); - $cases = $schema->enum; + + $cases = []; + + // transform each Enum cases into UnitEnum + foreach ($schema->enum as $enum) { + if (is_string($enum) && enum_exists($enum)) { + foreach ($enum::cases() as $case) { + $cases[] = $case; + } + } else { + $cases[] = $enum; + } + } } $enums = []; diff --git a/tests/Fixtures/PHP/Enums/TypeEnumStringBacked.php b/tests/Fixtures/PHP/Enums/TypeEnumStringBacked.php new file mode 100644 index 00000000..586bd2f1 --- /dev/null +++ b/tests/Fixtures/PHP/Enums/TypeEnumStringBacked.php @@ -0,0 +1,17 @@ + StatusEnumStringBacked array */ #[OAT\Property( title: 'statusEnums', diff --git a/tests/Processors/ExpandEnumsTest.php b/tests/Processors/ExpandEnumsTest.php index c917e64d..1af5af41 100644 --- a/tests/Processors/ExpandEnumsTest.php +++ b/tests/Processors/ExpandEnumsTest.php @@ -14,6 +14,7 @@ use OpenApi\Tests\Fixtures\PHP\Enums\StatusEnumBacked; use OpenApi\Tests\Fixtures\PHP\Enums\StatusEnumIntegerBacked; use OpenApi\Tests\Fixtures\PHP\Enums\StatusEnumStringBacked; +use OpenApi\Tests\Fixtures\PHP\Enums\TypeEnumStringBacked; use OpenApi\Tests\OpenApiTestCase; class ExpandEnumsTest extends OpenApiTestCase @@ -136,6 +137,16 @@ public function expandEnumClassStringFixtures(): iterable 'itemsStatusEnumStringBackedMixed', $mapValues([StatusEnumStringBacked::DRAFT, StatusEnumStringBacked::ARCHIVED, 'other']), ], + 'multipleEnumsClassNames' => [ + ['PHP/ReferencesEnum.php'], + 'multipleEnumsClassNames', + $mapValues(array_merge(StatusEnumStringBacked::cases(), TypeEnumStringBacked::cases())), + ], + 'mixedMultipleEnumsClassNames' => [ + ['PHP/ReferencesEnum.php'], + 'mixedMultipleEnumsClassNames', + $mapValues(array_merge(StatusEnumStringBacked::cases(), TypeEnumStringBacked::cases(), ['OTHER'])), + ], ]; }