custom-plugin-lib icon indicating copy to clipboard operation
custom-plugin-lib copied to clipboard

Issue on validation when exposing a multipart/form-data API

Open marco-basso opened this issue 2 years ago • 3 comments

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

marco-basso avatar Mar 06 '23 11:03 marco-basso

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

fredmaggiowski avatar Mar 06 '23 11:03 fredmaggiowski

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.

marco-basso avatar Mar 06 '23 13:03 marco-basso

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:

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 :)

fredmaggiowski avatar Mar 06 '23 15:03 fredmaggiowski