diff --git a/ModelDescriber/ApplyOpenApiDiscriminatorTrait.php b/ModelDescriber/ApplyOpenApiDiscriminatorTrait.php index dd551fd..d3e5fe9 100644 --- a/ModelDescriber/ApplyOpenApiDiscriminatorTrait.php +++ b/ModelDescriber/ApplyOpenApiDiscriminatorTrait.php @@ -21,18 +21,19 @@ use Symfony\Component\PropertyInfo\Type; * Open API schemas to support poly morphism. * * @see https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ + * * @internal */ trait ApplyOpenApiDiscriminatorTrait { /** - * @param Model $model the model that's being described, This is used to pass groups and config - * down to the children models in `oneOf` - * @param OA\Schema $schema The Open API schema to which `oneOf` and `discriminator` properties - * will be added - * @param string $discriminatorProperty The property that determine which model will be unsierailized - * @param array $typeMap the map of $discriminatorProperty values to their - * types + * @param Model $model the model that's being described, This is used to pass groups and config + * down to the children models in `oneOf` + * @param OA\Schema $schema The Open API schema to which `oneOf` and `discriminator` properties + * will be added + * @param string $discriminatorProperty The property that determine which model will be unsierailized + * @param array $typeMap the map of $discriminatorProperty values to their + * types */ protected function applyOpenApiDiscriminator( Model $model, @@ -40,7 +41,7 @@ trait ApplyOpenApiDiscriminatorTrait ModelRegistry $modelRegistry, string $discriminatorProperty, array $typeMap - ) : void { + ): void { $schema->oneOf = []; $schema->discriminator = new OA\Discriminator([]); $schema->discriminator->propertyName = $discriminatorProperty; @@ -54,7 +55,6 @@ trait ApplyOpenApiDiscriminatorTrait )); $schema->oneOf[] = $oneOfSchema; $schema->discriminator->mapping[$propertyValue] = clone $oneOfSchema; - } } } diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index 893ae96..5260da8 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -74,7 +74,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar $annotationsReader->updateDefinition($reflClass, $schema); $discriminatorMap = $this->doctrineReader->getClassAnnotation($reflClass, DiscriminatorMap::class); - if ($discriminatorMap && $schema->discriminator === OA\UNDEFINED) { + if ($discriminatorMap && OA\UNDEFINED === $schema->discriminator) { $this->applyOpenApiDiscriminator( $model, $schema, diff --git a/Tests/ModelDescriber/ApplyOpenApiDiscriminatorTraitTest.php b/Tests/ModelDescriber/ApplyOpenApiDiscriminatorTraitTest.php index 0644a8b..9ad9c8a 100644 --- a/Tests/ModelDescriber/ApplyOpenApiDiscriminatorTraitTest.php +++ b/Tests/ModelDescriber/ApplyOpenApiDiscriminatorTraitTest.php @@ -11,13 +11,12 @@ namespace Nelmio\ApiDocBundle\Tests\ModelDescriber; -use Doctrine\Common\Annotations\AnnotationReader; use Nelmio\ApiDocBundle\Model\Model; use Nelmio\ApiDocBundle\Model\ModelRegistry; use Nelmio\ApiDocBundle\ModelDescriber\ApplyOpenApiDiscriminatorTrait; use OpenApi\Annotations as OA; -use Symfony\Component\PropertyInfo\Type; use PHPUnit\Framework\TestCase; +use Symfony\Component\PropertyInfo\Type; class ApplyOpenApiDiscriminatorTraitTest extends TestCase { @@ -70,14 +69,14 @@ class ApplyOpenApiDiscriminatorTraitTest extends TestCase ); } - protected function setUp() : void + protected function setUp(): void { $this->schema = new OA\Schema([]); $this->model = $this->createModel(__CLASS__); $this->modelRegistry = new ModelRegistry([], new OA\OpenApi([])); } - private function createModel(string $className) : Model + private function createModel(string $className): Model { return new Model( new Type(Type::BUILTIN_TYPE_OBJECT, false, $className),