Skip to content

MeronNagy/api-platform-integer-backed-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-platform-integer-backed-enum

This repository demonstrates a bug in API Platform where the built-in BackedEnumFilter does not support integer-backed enums.

It includes a minimal Symfony application pre-configured to showcase both the broken behavior and a custom workaround that resolves the issue.


🏁 Getting Started

Start the Symfony server:

symfony serve

Once running, access the API docs at:

📘 https://127.0.0.1:8000/api

The SQLite database (var/data_dev.db) is pre-populated with dummy objects for testing.


🐛 The Bug

  • Visit the DummyUsingCurrentFilter resource.

  • Try filtering using the dummyIntBackedEnum property.

  • You'll see that filtering does not work.

  • Symfony logs a warning:

    Invalid filter ignored.
    

This is because the default BackedEnumFilter does not properly handle enums backed by integers.


✅ The Fix

  • The DummyUsingUpdatedFilter resource uses a custom BackedEnumFilter and BackedEnumFilterTrait located in src/ApiFilter.
  • This custom implementation properly handles integer-backed enums.
  • Filtering now works as expected.

🗂️ Contents

  • src/Entity/ – Demo entities
  • src/ApiFilter/ – Custom filter and trait for enum support
  • var/data_dev.db – Pre-filled SQLite DB for quick testing

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published