Skip to content

fix(metadata): stop emitting withBuiltinTypes deprecation from internal callers#8228

Closed
soyuka wants to merge 2 commits into
api-platform:4.3from
soyuka:fix/internal-withbuiltintypes-deprecation-8173
Closed

fix(metadata): stop emitting withBuiltinTypes deprecation from internal callers#8228
soyuka wants to merge 2 commits into
api-platform:4.3from
soyuka:fix/internal-withbuiltintypes-deprecation-8173

Conversation

@soyuka

@soyuka soyuka commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary

ApiProperty::withBuiltinTypes() / getBuiltinTypes() were deprecated in 4.2 in favor of the native-type equivalents, but API Platform's own factories and normalizers still call them on the legacy symfony/property-info code path. On Symfony 6.4 this produced ~600 deprecation entries per request even though no userland code touches the deprecated API.

This PR adds two @internal methods on ApiProperty (internalGetBuiltinTypes() / internalWithBuiltinTypes()) that perform the same storage/conversion without emitting the deprecation, and routes every internal call site through them. The public methods keep emitting the deprecation for external callers, preserving the existing BC promise.

Reproduction

On Symfony < 7.1 (or any property-info without getType()) vendor/api-platform/metadata/ApiProperty.php:551 fires withBuiltinTypes() deprecations from ExtractorPropertyMetadataFactory, AttributePropertyMetadataFactory, PropertyInfoPropertyMetadataFactory, and several normalizers/restrictions during normal property metadata building.

Test plan

  • Added failing test covering the bug.
  • Test passes after the fix.
  • Related test classes still pass locally (src/Metadata/Tests/Property/, src/JsonSchema/Tests/, src/Hal/Tests/, src/JsonApi/Tests/, src/Hydra/Tests/, src/Serializer/Tests/, src/GraphQl/Tests/, src/Elasticsearch/Tests/, src/Symfony/Tests/Validator/Metadata/Property/Restriction/). The two pre-existing failures in ResourceMetadataCompatibilityTest and three in src/Hal/Tests/ reproduce on upstream/4.3 and are unrelated to this change.

Fixes #8173

soyuka added 2 commits June 3, 2026 10:10
…al callers

ApiProperty::withBuiltinTypes() and getBuiltinTypes() were deprecated in 4.2 in
favor of withNativeType()/getNativeType(), but API Platform's own factories and
normalizers still call them on the legacy symfony/property-info code path. On
Symfony 6.4 this yields hundreds of deprecation entries per request even though
no userland code calls the deprecated API.

Introduce two @internal methods on ApiProperty (internalGetBuiltinTypes() and
internalWithBuiltinTypes()) that perform the same storage/conversion without
triggering the deprecation, and route every internal caller through them. The
public withBuiltinTypes()/getBuiltinTypes() methods keep emitting the
deprecation for external callers.

Fixes api-platform#8173
CI for api-platform#8228 failed on multiple split-package suites because the new
internal*BuiltinTypes() helpers are only available on the metadata
HEAD; "lowest" dependency builds resolve api-platform/metadata to a
released 4.3.x that does not have them yet.

- Guard every cross-package caller with method_exists() and fall back
  to the public getBuiltinTypes() so old metadata installs still work
  (the legacy deprecation re-emerges only on those old installs, i.e.
  pre-existing behaviour).
- Filter the regression test to ApiProperty-targeted deprecations so
  the unrelated Symfony\Component\PropertyInfo\Type class deprecation
  (symfony/property-info 7.3+) no longer trips the assertion.
- Drop unused imports flagged by php-cs-fixer.
- Add narrow PHPStan ignores for function.alreadyNarrowedType in the
  guarded files (the methods are always defined on the monorepo HEAD,
  so the runtime guards look redundant to static analysis).
@soyuka soyuka closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant