diff --git a/src/ModelDescriber/JMSModelDescriber.php b/src/ModelDescriber/JMSModelDescriber.php index 49da02fb2..b6793889f 100644 --- a/src/ModelDescriber/JMSModelDescriber.php +++ b/src/ModelDescriber/JMSModelDescriber.php @@ -328,9 +328,14 @@ public function describeItem(array $type, OA\Schema $property, Context $context, if ('enum' === $type['name'] && isset($type['params'][0]) && function_exists('enum_exists') - && enum_exists($type['params'][0]) ) { - $type = ['name' => $type['params'][0]]; + $typeParam = $type['params'][0]; + if (isset($typeParam['name'])) { + $typeParam = $typeParam['name']; + } + if (is_string($typeParam) && enum_exists($typeParam)) { + $type['name'] = $typeParam; + } } $groups = $this->computeGroups($context, $type); diff --git a/tests/Functional/Controller/JMSController81.php b/tests/Functional/Controller/JMSController81.php index 8848e196a..e0e93fa4a 100644 --- a/tests/Functional/Controller/JMSController81.php +++ b/tests/Functional/Controller/JMSController81.php @@ -16,6 +16,7 @@ use Nelmio\ApiDocBundle\Tests\Functional\Entity\DiscriminatorMap\JMSAbstractUser; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex81; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex; +use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSEnum81; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints; use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser; use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat; @@ -141,4 +142,14 @@ public function enum() public function discriminatorMapAction() { } + + #[Route('/api/jms_enum_array', methods: ['GET'])] + #[OA\Response( + response: 200, + description: 'Success', + content: new Model(type: JMSEnum81::class)) + ] + public function enumArrayAction() + { + } } diff --git a/tests/Functional/Entity/JMSEnum81.php b/tests/Functional/Entity/JMSEnum81.php new file mode 100644 index 000000000..ee5b48ee1 --- /dev/null +++ b/tests/Functional/Entity/JMSEnum81.php @@ -0,0 +1,25 @@ +")] + #[Serializer\Expose] + public $enumValue; + + #[Serializer\Type('array>")] + #[Serializer\Expose] + public $enumValues; +} diff --git a/tests/Functional/JMSFunctionalTest.php b/tests/Functional/JMSFunctionalTest.php index fb671d3b4..d491b9f00 100644 --- a/tests/Functional/JMSFunctionalTest.php +++ b/tests/Functional/JMSFunctionalTest.php @@ -370,6 +370,36 @@ public function testEnumSupport(): void 'final', ], ], json_decode($this->getModel('ArticleType81')->toJson(), true)); + + self::assertEquals([ + 'schema' => 'ArticleType81', + 'type' => 'string', + 'enum' => [ + 'draft', + 'final' + ] + ], json_decode($this->getModel('ArticleType81')->toJson(), true)); + + if (TestKernel::isAnnotationsAvailable()) { + // Further tests have only been defined with attributes + return; + } + + self::assertEquals([ + 'schema' => 'JMSEnum81', + 'type' => 'object', + 'properties' => [ + 'enum_value' => [ + '$ref' => '#/components/schemas/ArticleType81' + ], + 'enum_values' => [ + 'type' => 'array', + 'items' => [ + '$ref' => '#/components/schemas/ArticleType81' + ] + ], + ] + ], json_decode($this->getModel('JMSEnum81')->toJson(), true)); } public function testModeDiscriminatorMap(): void