GithubHelp home page GithubHelp logo

Comments (6)

seriousme avatar seriousme commented on July 19, 2024

Hi,

fastify-openapi-glue only supports the bodypart types that Fastify supports and Fastify does not support multipart/form-data out of the box.

There is however a multipart/form-data plugin for fastify that you could try. You would need to register both openapi-glue and multiPart on the same fastify instance. Fastify-openapi-glue will still report the:

body type: multipart/form-data found

On startup as it does not have a way to detect that you have a plugin loaded for that specific body type.

I haven't tried it myself so I'd be happy to hear if that works !

Kind regards,
Hans

from fastify-openapi-glue.

batodev avatar batodev commented on July 19, 2024

I tried, now it returns Bad Request

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "body should be object"
}

and it lets me send Json body even if multipart/form-data is the only allowed content-type in Swagger spec.

Thank you for your help!
Tommaso

from fastify-openapi-glue.

seriousme avatar seriousme commented on July 19, 2024

From: https://github.com/fastify/fastify-multipart

You can also use all the parsed HTTP request parameters to the body:

const options = {
  addToBody: true,
  sharedSchemaId: 'MultipartFileType', // Optional shared schema id
  onFile: (fieldName, stream, filename, encoding, mimetype, body) => {
    // Manage the file stream like you need
    // By default the data will be added in a Buffer
    // Be careful to accumulate the file in memory!
    // It is MANDATORY consume the stream, otherwise the response will not be processed!
    // The body parameter is the object that will be added to the request
    stream.resume()
  },
  limit: { /*...*/ } // You can the limit options in any case
}

fastify.register(require('fastify-multipart'), options)

That should solve your empty body problem.

As for blocking normal JSON payloads you could either look at req.headers in your service.js or you could try to modify the application/json parser so that it always returns an error.

Kind regards,
Hans

from fastify-openapi-glue.

batodev avatar batodev commented on July 19, 2024

Thank you again, I will try! :)

Tommaso

from fastify-openapi-glue.

github-actions avatar github-actions commented on July 19, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'

from fastify-openapi-glue.

jonasgroendahl avatar jonasgroendahl commented on July 19, 2024

im struggling on this

did you solve it @batodev ?

from fastify-openapi-glue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.