core icon indicating copy to clipboard operation
core copied to clipboard

For JSON:API, the ID is not required in the POST request

Open cay89 opened this issue 1 year ago • 5 comments

API Platform version(s) affected: 4.0.4

Description
According to the JSON:API documentation, an ID is not required in a POST request, but Api Platform requires it in OpenAPI documentation.

image

Can this be resolved so that the ID is not mandatory in a POST request? It also throws an error when I include an ID.

cay89 avatar Oct 21 '24 07:10 cay89

I wouldn't create a new issue, but I don't think the link in the response header is good either:

image

cay89 avatar Oct 21 '24 17:10 cay89

If you didn't disable JSON-LD, this link is expected for autodiscoverability of the Hydra docs.

dunglas avatar Oct 21 '24 17:10 dunglas

If you didn't disable JSON-LD, this link is expected for autodiscoverability of the Hydra docs.

I think I turned it off:

image

cay89 avatar Oct 21 '24 17:10 cay89

Indeed, that's a bug then!

dunglas avatar Oct 21 '24 20:10 dunglas

I’ve tried to achieve a setup where the "ID" field would be removed (or mark as not required) specifically for the POST endpoint in the ApiPlatform\JsonApi\JsonSchema\SchemaFactory. Unfortunately, I’ve only found partial solutions because the schema is built once for the model, and I’m unsure how to configure the POST endpoint to use a different schema (one without the ID) compared to the others. According to the JSON:API specification, the ID can be generated on the client side, making it possible to send the ID in a POST request. However, the API Platform does not support this—it throws an exception if I include an ID.

cay89 avatar Dec 19 '24 08:12 cay89