core icon indicating copy to clipboard operation
core copied to clipboard

Allow IRI to be pre-configured in context when serializing in HAL or JsonApi format

Open pupaxxo opened this issue 1 year ago • 1 comments

The AbstractItemNormalizer allows for the pre-configuration of the IRI within the context. It is proposed that this feature be extended to both the HAL and JsonApi normalizers for consistency and flexibility.

Example usage:

#[ApiResource(
    operations: [
        new Get(),
        new Post(
            uriTemplate: '/search/parse-query',
            controller: SearchController::class.'::parseQuery',
            normalizationContext: ['groups' => ['api:read'], 'iri' => 'not-existing'],
            write: false,
        ),
        new Post(
            uriTemplate: '/search/parse-url',
            controller: SearchController::class.'::parseUrl',
            normalizationContext: ['groups' => ['api:read'], 'iri' => 'not-existing'],
            input: SearchParseUrlDto::class,
            validate: false,
            write: false,
        ),
    ],
    normalizationContext: ['groups' => ['api:read']],
    denormalizationContext: ['groups' => ['api:write']],
)]
class Search { ... }

This modification addresses the issue where POST requests that accept HAL data and target the parse-query and parse-url methods (which return a Search object) might trigger an IRI-related error. This is because the returned Search object does not actually exist in the database.

pupaxxo avatar Mar 13 '24 15:03 pupaxxo

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 May 12 '24 15:05 stale[bot]