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

Merged
merged 1 commit into from
May 24, 2024

Conversation

pupaxxo
Copy link
Contributor

@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.

Copy link

stale bot commented May 12, 2024

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 stale bot added the stale label May 12, 2024
@stale stale bot removed stale labels May 13, 2024
@soyuka soyuka merged commit b47edb2 into api-platform:main May 24, 2024
77 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants