core icon indicating copy to clipboard operation
core copied to clipboard

feat: BackedEnum resources

Open GwendolenLynch opened this issue 1 year ago • 4 comments

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 value by default, and implementing function getId(), etc, works too
  • Resource operations will default to only Get & GetCollection unless 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
}

GwendolenLynch avatar Apr 13 '24 14:04 GwendolenLynch

I would use URIs in GraphQL too, as we do for existing IDs and relations. WDYT?

dunglas avatar Apr 15 '24 14:04 dunglas

@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?

GwendolenLynch avatar Apr 16 '24 12:04 GwendolenLynch

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.

gnito-org avatar Apr 18 '24 16:04 gnito-org

Thank you @gnito-org, I can reproduce it here.

GwendolenLynch avatar Apr 18 '24 17:04 GwendolenLynch

@GwendolenLynch I merged #6288 could you rebase I this should fix some of the failing tests right?

soyuka avatar May 30 '24 11:05 soyuka

I'll continue working on this tomorrow, hopefully merging it!

soyuka avatar Jun 17 '24 16:06 soyuka

Thanks @GwendolenLynch!

soyuka avatar Jun 18 '24 09:06 soyuka