Comments (6)
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.
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.
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.
Thank you again, I will try! :)
Tommaso
from fastify-openapi-glue.
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.
im struggling on this
did you solve it @batodev ?
from fastify-openapi-glue.
Related Issues (20)
- Support for union types in schema? HOT 2
- OpenAPI spec parameters are mapped incorrectly HOT 4
- Opentelemetry Support HOT 5
- Error [ERR_REQUIRE_ESM]: Must use import to load ES Module HOT 6
- example fails with FST_ERR_SCH_VALIDATION_BUILD HOT 3
- Validation Errors when embedding $refs to models that contain "x-" or "example" keywords HOT 3
- Error in Response Validation Message HOT 9
- Middleware HOT 3
- [email protected] deprecation notice (FSTDEP012) "Request#context will be removed in `fastify@5` HOT 4
- No validation error when non `application/json` response provided by API HOT 2
- Return route options from operationResolver HOT 2
- [Discussion] [Request] Rename `service` => `handlers` in options HOT 4
- Suggestion about the TS imports errors HOT 7
- using "example" in swagger api HOT 7
- PARAMETERS method is not supported: when using cross-method parameters HOT 3
- Schema validation HOT 2
- Presence of cookie not being validated HOT 5
- and connected security requirements not possible. HOT 7
- Multiple Security Handlers Error Handling HOT 4
- "Error: 'specification' parameter must contain a valid version" when trying to reference schema from another file HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-openapi-glue.