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

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

Open
cay89 opened this issue Oct 21, 2024 · 5 comments
Open

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

cay89 opened this issue Oct 21, 2024 · 5 comments

Comments

@cay89
Copy link
Contributor

cay89 commented Oct 21, 2024

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 cay89 changed the title For JSON:API, the ID is nor in the POST request For JSON:API, the ID is not required in the POST request Oct 21, 2024
@cay89
Copy link
Contributor Author

cay89 commented Oct 21, 2024

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

image

@dunglas
Copy link
Member

dunglas commented Oct 21, 2024

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

@cay89
Copy link
Contributor Author

cay89 commented Oct 21, 2024

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

I think I turned it off:

image

@dunglas
Copy link
Member

dunglas commented Oct 21, 2024

Indeed, that's a bug then!

@cay89
Copy link
Contributor Author

cay89 commented Dec 19, 2024

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.

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

No branches or pull requests

3 participants