loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

Issue with loopback controller @param.array #6750

Closed Ricardope3 closed 3 years ago

Ricardope3 commented 3 years ago

There is another issue I noticed that if you only pass one value e.g. ?numberArray=123 then it throws the error with the code INVALID_PARAMETER_VALUE and in details with the message should be array, however ?numberArray=123&numberArray=12345 works just fine.

I also noticed that ?numberArray[]=123 works but thats different from how it used to work and also is not how the api explorer sends the values.

Seems like there is a general issue with the @param.array with parameter location query

Originally posted by @nflaig in https://github.com/strongloop/loopback-next/issues/5793#issuecomment-703927426

Ricardope3 commented 3 years ago

Having the same issue as @nflaig in #5793 (comment)

My code is like this

@param.array('skillNames', 'query', { type: 'string' }) skillNames: string[],

When I only add one element to the string array the following error is displayed

{
  "error": {
    "statusCode": 400,
    "name": "BadRequestError",
    "message": "Invalid data \"\" for parameter \"skillNames\".",
    "code": "INVALID_PARAMETER_VALUE",
    "details": [
      {
        "path": "",
        "code": "type",
        "message": "should be array",
        "info": {
          "type": "array"
        }
      }
    ]
  }
}

The url that is being sended looks like this

curl -X GET "http://[::1]:3000/skills/report/{skillNames}?skillNames=elemOne"
Ricardope3 commented 3 years ago

@bajtos @dhmlau

mrmodise commented 3 years ago

Thanks for raising the issue. However, the specific issue you are referring has been resolved by this pull request

nflaig commented 3 years ago

@Ricardope3 I created an issue for this and it was fixed by @mrmodise.

A new version of @loopback/rest has been released and it should be fixed, see changelog.

dhmlau commented 3 years ago

Closing as resolved. Thanks!