core icon indicating copy to clipboard operation
core copied to clipboard

Add updatable to ApiProperty

Open KDederichs opened this issue 2 years ago • 4 comments

Description
We currently have writable and 'readable' on ApiProperty attributes. This is great to reduce the amount of serialization group management you have to juggle.

You'll run into an issue when you try to have fields that are writable but ONLY during updates (PATCH, PUT), in cases like this you'd have to start adding serialization groups again, which is a bit annoying when you try to serialize objects as well as you then have to propagate that down.

I'd suggest adding an updateable field to ApiProperty that'll only include/exclude fields based on if it's a PUSH or POST operation.

Example

class Foo {
    #[ApiProperty(writable: false, updateable:true)]
    private ?Bar bar = null;
}

KDederichs avatar Nov 10 '23 13:11 KDederichs

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 09 '24 13:01 stale[bot]

I'd still like something like that, so not stale

KDederichs avatar Jan 09 '24 16:01 KDederichs

okay added the enhancement label, I think that you should use a DTO for each of the use cases so that you can have writable only for PATCH

soyuka avatar Jan 10 '24 11:01 soyuka

You could yeah.

I've run into this while using the setup with Micro Mapper Ryan introduced in https://symfonycasts.com/screencast/api-platform-extending .

It mainly enabled me to seperate it in that way, but using it I've run into the "need" for an updatable only property to keep it "simple"

KDederichs avatar Jan 10 '24 11:01 KDederichs