core
core copied to clipboard
feat: BackedEnum resources
| Q | A |
|---|---|
| Branch? | main |
| Tickets | Closes #6298, closes #6317 |
| License | MIT |
| Doc PR | api-platform/docs#... |
Intended for 3.4, so now it is just for review.
Depends on #6288 as I want to refactor BackedEnumPlainResourceTest test methods into those classes.
- Add a provider for
BackedEnums - Identifier is
valueby default, and implementingfunction getId(), etc, works too - Resource operations will default to only
Get&GetCollectionunless otherwise configured
#[ApiResource]
enum Status: int
{
case DRAFT = 0;
case PUBLISHED = 1;
}
GET /statuses
[
{
"name": "DRAFT",
"value": 0
},
{
"name": "PUBLISHED",
"value": 1
}
]
GET /statuses/1
{
"name": "PUBLISHED",
"value": 1
}
I would use URIs in GraphQL too, as we do for existing IDs and relations. WDYT?
@dunglas it must be my week for getting confused. :sun_with_face:
I'm very happy to make required changes, but could you be so kind as to give a bit more context, please?
Please look at how I configure a backed enum as an API resource so that each instance has an IRI just like any other API resource.
https://github.com/gnito-org/problem-replicator-api-platform-enum-example
This is important for machine discovery of APIs and for consistency.
Thank you @gnito-org, I can reproduce it here.
@GwendolenLynch I merged #6288 could you rebase I this should fix some of the failing tests right?
I'll continue working on this tomorrow, hopefully merging it!
Thanks @GwendolenLynch!