loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

@property.array ignores json schema definition

Open nathHy opened this issue 2 years ago • 0 comments

Describe the bug

I was attempting to use the property array decorator alongside the jsonschema definition to ensure at least one item existed in the array at request time via validation within @requestBody However when using the @property.array decorator it seems to just drop all the jsonSchema fields and ignore them

I've made a repro here. https://codesandbox.io/p/sandbox/infallible-scott-64xtwg?welcome=true

Run this request

curl -X 'POST' \
  'https://64xtwg-3000.csb.app/ping' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "subModel": [
    {
      "childProperty": [
      ]
    }
  ]
}'

This line here https://github.com/loopbackio/loopback-next/blob/master/packages/repository-json-schema/src/build-schema.ts#L269C46-L269C46 seems to be the culprit. If i change that to result = Object.assign({}, meta.jsonSchema, { type: 'array', items: propDef }) it appears to work as expected (throw a 422 error)

Logs

No response

Additional information

No response

Reproduction

https://codesandbox.io/p/sandbox/infallible-scott-64xtwg?welcome=true

nathHy avatar Aug 02 '23 08:08 nathHy