fastify / fastify/fastify-multipart

The coerceTypes: 'array' doesn't coerce one parameter to a single element in array

Open
#318 9 comments 1 reaction 0 assignees View on GitHub
documentation good first issue
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.