-
-
Notifications
You must be signed in to change notification settings - Fork 924
Description
From my experience with api platform, it is a common task to use different serialization/validation groups for different circumstances. These circumstances are most of the time only a few different main scenarios. it would be helpful, if for these situations certain default groups are provided.
e.g. serialization:
different serialization groups depending on operation/method.
different serialization groups depending on general intention (READ, WRITE, UPDATE, CREATE).
while it is possible to manipulate serialization groups in a generic cross resource way (via SerializerContextBuilder), this is not possible for validation (except for decorating the validator itself).
In general i think it would be very helpful being able to manipulate the serialization context and validation groups via listeners.
so this is a 2-part feature request:
- create events and triggers to configure the serialization context and validation groups via event listeneres
- provide event listeners that generically provided commonly used serialization context settings and validation groups:
AttributeAccessControlSerializationContextListener
: loops throughApiProperty
data and check the (to be introduced) access_control.OperationSerializationContextListener
: adds serialization groups based on operation, once prefixed only the operation name (get
) and once with FCQN prefixed (App\Entity\Dummy::get
). the latter is used to allow fine grained control of embedded (de)serialization.RoleValidationGroupsListener
: adds a validation group for each role of the currently logged in user
this opens up for more specific integration of other symfony components:
WorkflowValidationGroupsListener
adds a validation group for each place the current entity is in
i can provide PRs, if this idea gets accepted