diff --git a/src/Metadata/ApiProperty.php b/src/Metadata/ApiProperty.php index be5a791801..597f64c3ba 100644 --- a/src/Metadata/ApiProperty.php +++ b/src/Metadata/ApiProperty.php @@ -513,6 +513,10 @@ public function getBuiltinTypes(): ?array { trigger_deprecation('api-platform/metadata', '4.2', 'The "%s()" method is deprecated, use "%s::getNativeType()" instead.', __METHOD__, self::class); + if (null === $this->builtinTypes && null !== $this->nativeType) { + $this->builtinTypes = PropertyInfoToTypeInfoHelper::convertTypeToLegacyTypes($this->nativeType) ?? []; + } + return $this->builtinTypes; } @@ -541,7 +545,6 @@ public function withNativeType(?Type $nativeType): self { $self = clone $this; $self->nativeType = $nativeType; - $self->builtinTypes = PropertyInfoToTypeInfoHelper::convertTypeToLegacyTypes($nativeType) ?? []; return $self; } diff --git a/src/Serializer/composer.json b/src/Serializer/composer.json index f0e023e6e0..dc89d23d46 100644 --- a/src/Serializer/composer.json +++ b/src/Serializer/composer.json @@ -23,7 +23,7 @@ ], "require": { "php": ">=8.2", - "api-platform/metadata": "^4.1.11", + "api-platform/metadata": "^4.1.16", "api-platform/state": "^4.1.11", "symfony/property-access": "^6.4 || ^7.0", "symfony/property-info": "^6.4 || ^7.1", diff --git a/src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaFormatTest.php b/src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaFormatTest.php index 2acc7f8074..d6a21c0cad 100644 --- a/src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaFormatTest.php +++ b/src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaFormatTest.php @@ -46,7 +46,11 @@ public function testSupports(Constraint $constraint, ApiProperty $propertyMetada public static function supportsProvider(): \Generator { yield 'email' => [new Email(), new ApiProperty(), true]; - yield 'url' => [new Url(), new ApiProperty(), true]; + if (property_exists(Url::class, 'requireTld')) { + yield 'url' => [new Url(requireTld: true), new ApiProperty(), true]; + } else { + yield 'url' => [new Url(), new ApiProperty(), true]; + } if (class_exists(Hostname::class)) { yield 'hostname' => [new Hostname(), new ApiProperty(), true]; } @@ -67,7 +71,11 @@ public function testCreate(Constraint $constraint, ApiProperty $propertyMetadata public static function createProvider(): \Generator { yield 'email' => [new Email(), new ApiProperty(), ['format' => 'email']]; - yield 'url' => [new Url(), new ApiProperty(), ['format' => 'uri']]; + if (property_exists(Url::class, 'requireTld')) { + yield 'url' => [new Url(requireTld: true), new ApiProperty(), ['format' => 'uri']]; + } else { + yield 'url' => [new Url(), new ApiProperty(), ['format' => 'uri']]; + } if (class_exists(Hostname::class)) { yield 'hostname' => [new Hostname(), new ApiProperty(), ['format' => 'hostname']]; }