10000 Default serialization and validation groups · Issue #1901 · api-platform/core · GitHub
[go: up one dir, main page]

Skip to content
Default serialization and validation groups #1901
@backbone87

Description

@backbone87

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:

  1. create events and triggers to configure the serialization context and validation groups via event listeneres
  2. provide event listeners that generically provided commonly used serialization context settings and validation groups:
  • AttributeAccessControlSerializationContextListener: loops through ApiProperty 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0