Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pupaxxo
Copy link

@pupaxxo pupaxxo commented Mar 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant