loopbackio / loopbackio/loopback-next
@param.array throws INVALID_PARAMETER_VALUE:must be string if more than 20 elements are sent
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
### Describe the bug
Hello, I have an LB application running correctly in prod for couple years. I used LB4 CLI `update` command in my test environment, and now I'm getting `INVALID_PARAMETER_VALUE:must be string` error code for a REST request -that works fine in prod- when sending more than 20 values on a @param.array query param.
I assume its handled by @loopback/rest. If so, prod has v12 and my test environment v15.0.9.
1.- How to reproduce:
Having the following code in my controller:
```typescript
@param({
name: 'vendorNumbers', in: 'query', schema: { type: 'array', items: { type: 'string' } }
}) vendorNumbers: string[],`
```
and calling
```
http://{url}/queries/selectShipments?vendorNumbers=1000294151&vendorNumbers=1000486268&vendorNumbers=1000107612&vendorNumbers=1000433151&vendorNumbers=1000353795&vendorNumbers=1000059059&vendorNumbers=1000046043&vendorNumbers=1000328740&vendorNumbers=1000353800&vendorNumbers=1000254679&vendorNumbers=1000468101&vendorNumbers=1000493680&vendorNumbers=1000483049&vendorNumbers=1000479051&vendorNumbers=1000346467&vendorNumbers=1000478186&vendorNumbers=1000428780&vendorNumbers=1000064789&vendorNumbers=1000411703&vendorNumbers=1000120574&vendorNumbers=1000056801
```
I get the following error:
```javascript
{
"error": {
"statusCode": 400,
"name": "BadRequestError",
"message": "Invalid data [{\"0\":\"1000294151\",\"1\":\"1000486268\",\"2\":\"1000107612\",\"3\":\"1000433151\",\"4\":\"1000353795\",\"5\":\"1000059059\",\"6\":\"1000046043\",\"7\":\"1000328740\",\"8\":\"1000353800\",\"9\":\"1000254679\",\"10\":\"1000468101\",\"11\":\"1000493680\",\"12\":\"1000483049\",\"13\":\"1000479051\",\"14\":\"1000346467\",\"15\":\"1000478186\",\"16\":\"1000428780\",\"17\":\"1000064789\",\"18\":\"1000411703\",\"19\":\"1000120574\",\"20\":\"1000056801\"}] for parameter \"vendorNumbers\".",
"code": "INVALID_PARAMETER_VALUE",
"details": [
{
"path": "/0",
"code": "type",
"message": "must be string",
"info": {
"type": "string"
}
}
]
}
}
```
Have in mind that:
- if I send less than 20, works fine.
- it is not related to query length nor number of other params, cause I already tried with different lengths and number of 'other' parameters.
- If I add `maxItems` of 30, I still get `INVALID_PARAMETER_VALUE:must be string` when sending more than 20 values.
- During one of my tests, I set `maxItems` at 10, and the error changed to INVALID_PARAMETER_VALUE:must NOT have more than 10 items
Thanks
### Logs
```shell
```
### Additional information
_No response_
### Reproduction
-
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the @loopback/rest query-parameter parsing and validation path, comparing the reported v12 behavior with v15.0.9. Reproduce the request using the 21 repeated vendorNumbers values shown, then verify why values beyond 20 are treated incorrectly while maxItems validation still works. Done means arrays longer than 20 validate as strings without regressing maxItems errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100