fix(jsonapi): do not require id in input schema for post operations#8252
Merged
soyuka merged 1 commit intoJun 5, 2026
Merged
Conversation
Per the JSON:API spec (https://jsonapi.org/format/#crud-creating), a client MAY supply a client-generated id when creating a resource. The schema factory unconditionally marked id as required for any input schema, which forced clients to invent ids on POST. Mark id as required only for non-POST HTTP operations. Fixes api-platform#6738
soyuka
added a commit
to abderrahimghazali/core
that referenced
this pull request
Jun 5, 2026
Per https://jsonapi.org/format/#crud-creating-client-ids a client MAY supply an id when creating a resource. The JSON:API ItemNormalizer previously treated any incoming `data.id` on POST as a hint to load an existing resource, throwing "Update is not allowed for this operation" or failing the IRI lookup, even when the application is designed for client-generated identifiers. A new opt-in `ALLOW_CLIENT_GENERATED_ID` denormalization context flag lets the client id flow through to the entity setter without querying the IriConverter. Off by default to avoid an id-spoofing footgun on public endpoints. Configurable globally via the Symfony bundle (`api_platform.jsonapi.allow_client_generated_id`) and Laravel (`api-platform.jsonapi.allow_client_generated_id`), per-operation via `denormalizationContext`. Also tightens the input-schema guard added in api-platform#8252 with a `Schema::TYPE_INPUT === $type` check so POST response schemas keep requiring `id`. Refs api-platform#6738
soyuka
added a commit
to abderrahimghazali/core
that referenced
this pull request
Jun 5, 2026
Per https://jsonapi.org/format/#crud-creating-client-ids a client MAY supply an id when creating a resource. The JSON:API ItemNormalizer previously treated any incoming `data.id` on POST as a hint to load an existing resource, throwing "Update is not allowed for this operation" or failing the IRI lookup, even when the application is designed for client-generated identifiers. A new opt-in `ALLOW_CLIENT_GENERATED_ID` denormalization context flag lets the client id flow through to the entity setter without querying the IriConverter. Off by default to avoid an id-spoofing footgun on public endpoints. Configurable globally via the Symfony bundle (`api_platform.jsonapi.allow_client_generated_id`) and Laravel (`api-platform.jsonapi.allow_client_generated_id`), per-operation via `denormalizationContext`. Also tightens the input-schema guard added in api-platform#8252 with a `Schema::TYPE_INPUT === $type` check so POST response schemas keep requiring `id`. Refs api-platform#6738
soyuka
added a commit
to abderrahimghazali/core
that referenced
this pull request
Jun 5, 2026
Per https://jsonapi.org/format/#crud-creating-client-ids a client MAY supply an id when creating a resource. The JSON:API ItemNormalizer previously treated any incoming `data.id` on POST as a hint to load an existing resource, throwing "Update is not allowed for this operation" or failing the IRI lookup, even when the application is designed for client-generated identifiers. A new opt-in `ALLOW_CLIENT_GENERATED_ID` denormalization context flag lets the client id flow through to the entity setter without querying the IriConverter. Off by default to avoid an id-spoofing footgun on public endpoints. Configurable globally via the Symfony bundle (`api_platform.jsonapi.allow_client_generated_id`) and Laravel (`api-platform.jsonapi.allow_client_generated_id`), per-operation via `denormalizationContext`. Also tightens the input-schema guard added in api-platform#8252: adds a `Schema::TYPE_INPUT === $type` check so POST response schemas keep requiring `id`, and captures the resource operation before the relationship loop reassigns `$operation` so the requirement check targets the correct operation when the resource has relationships. Refs api-platform#6738 Co-authored-by: soyuka <soyuka@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The JSON:API input schema marked
idas required for every operation, but the spec (https://jsonapi.org/format/#crud-creating) lets a client supply a client-generated id when creating a resource — it is not required. POST schemas now require onlytype; PATCH/PUT/GET still requireid.Reproduction
Calling POST against a JSON:API resource with a body lacking
data.idwas rejected because the generated input schema markedidas required.Test plan
id.id.Fixes #6738