You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
I would like to have a way to mark a request bodies as required, even if the body only has optional properties.
Motivation
This is a follow-up to #541. While this solves part of my problem, it still does not reflect the defined schema.
The following example illustrates the problem (it uses typebox for schema generation):
Because no property inside the body is required, fastify-swagger will not mark the request body as required.
In theory this would allow me to send a fetch request with an empty body:
constresponse=awaitfetch("http://localhost:300/user",{method: "put",headers: {"Content-Type": "application/json"},};console.log(awaitresponse.json())// => [400] Body cannot be empty when content-type is set to 'application/json'
… but fastify always prevents this, because it is not valid JSON. You could argue, that this is not a problem, because you would never do something like this, but if you generate your frontend client with something like oazapfts, you will end up with a signature that has an optional body. And not sending a body will always result in a failed request.
Example
See above
The text was updated successfully, but these errors were encountered:
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.
Prerequisites
🚀 Feature Proposal
I would like to have a way to mark a request bodies as required, even if the body only has optional properties.
Motivation
This is a follow-up to #541. While this solves part of my problem, it still does not reflect the defined schema.
The following example illustrates the problem (it uses typebox for schema generation):
Because no property inside the body is required,
fastify-swagger
will not mark the request body as required.In theory this would allow me to send a fetch request with an empty body:
… but fastify always prevents this, because it is not valid JSON. You could argue, that this is not a problem, because you would never do something like this, but if you generate your frontend client with something like
oazapfts
, you will end up with a signature that has an optional body. And not sending a body will always result in a failed request.Example
See above
The text was updated successfully, but these errors were encountered: