Issue on validation when exposing a multipart/form-data API
The feauture or bug you are proposing
Issue on validating a multipart/form-data request
The description of the bug or the rationale of your proposal
The schema definition of a mutlipart/form-data part requires the following body structure:
{
additionalProperties: false,
properties: {
part: {
description: 'Binary content of the file to upload',
format: 'binary',
type: 'string',
},
},
required: ['part'],
type: 'object',
}
Calling the endpoint with a binary file uploaded through the part field does return a validation error which states: 'body.part must be string`
The expected result for your bug
I expect that this validation error should not happen
Your environment
node: 8.15.0
custom-plugin-lib: 4.3.2
os: 20.04.5 LTS (Focal Fossa), Ubuntu
Hi @marco-basso I'm not entirely sure this is an issue with the library; it seems an issue with @fastify/swagger 🤔
Also consider that node 8 is not supported, you need at least node 12
Sorry, I inserted the wrong version on my issue, the actual node version is v16.17.0.
I do not know if it is an issue with @fastify/swagger since he does its job fine. The problem appears when I try to do a request with a binary file and the validation does not succes because it expect a string. I would argue it could be a problem with ajv compiler or with the fastify ajv plugin.
My current workaround is to avoid to specify the type: string on the body of my request, BUT this does not let me upload a file from the swagger ui because the right specification should contain such type.
I do not know if it is an issue with @fastify/swagger since he does its job fine. The problem appears when I try to do a request with a binary file and the validation does not succes because it expect a string. I would argue it could be a problem with ajv compiler or with the fastify ajv plugin.
Regardless of being a @fastify/swagger or ajv issue I don't think it is a bug of the custom plugin lib or lc39 🤔
The only setup that is done of the libraries related to the openapi specification are:
- fastify route creation in cplib
- @fastify/swagger setup in lc39
- swagger definition customization function in lc39
I'd try to update the library and understand whether this is a bug with @fastify/swagger or ajv and if there is a fix available we could update the libraries :)