-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Json schema validation fails with fastify-multipart #525
Comments
Hi @guerrap, thanks for submitting this issue. There are two problems in your case. 1st problem: The way you are defining the JSON schema for validation is not the same as it's mentioned in the documentation. The way you defined the validation for the name and lastname fields was:
but it should be like this:
The reason is that the plugin first converts the non-file fields into a object that looks like this:
After the conversion the object gets validated against the defined schema. The documentation of the fastify-multipart plugin doesn't mention this conversion, unfortunately. Once you change your schema - you will not get the error you mentioned. I've opened an issue to improve the documentation, you can find it here: fastify/fastify-multipart#277 2nd problem: (which you would only notice after you fix the 1st problem) is that you are trying to sent a non-file field with a stringified JSON object as the value. At this moment the plugin doesn't support having objects as the field value. |
Hi, thank you for your answer |
I will close this issue and you can keep track on the issue open by radomird on |
💬 Question here
Hello,
I'm trying to implement an API using
fastify-multipart
plugin, that applies a schema validation of a simple body.When calling the API I'm getting a bad request error
body.name should be string
, but thebody.name
field is correctly sent as a string, so I don't understand why the validation fails. Am I missing something? I followed the example in the README.Below there's the code for both the server and the client.
server:
client:
full error:
Your Environment
The text was updated successfully, but these errors were encountered: