fastify / fastify/fastify-multipart
The coerceTypes: 'array' doesn't coerce one parameter to a single element in array
- Dominant language
- JavaScript
- Stars
- 539
- Forks
- 126
- PR merge metrics
- No merged PRs in 30d
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
3.x.x
### Plugin version
5.x.x
### Node.js version
14.x
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
10
### Description
I have got this error when send a POST request.
```js
{statusCode: 400, error: "Bad Request", message: "body.authors should be array"}
error: "Bad Request"
message: "body.authors should be array"
statusCode: 400
```
My schema
```js
const body = {
type: "object",
properties: {
authors: {
type: "array",
items: {
type: "object"
}
}
}
```
Fastify configuration
```js
server.register(fastifyMultipart, {
attachFieldsToBody: true,
sharedSchemaId: "#mySharedSchema",
})
const ajv = new Ajv({
removeAdditional: true,
useDefaults: true,
coerceTypes: "array",
nullable: true
})
fastify.setValidatorCompiler(({ schema }) => {
return ajv.compile(schema)
})
```
### Steps to Reproduce
It is straightforward.
### Expected Behavior
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.