Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@property.array ignores json schema definition #9807

Open
nathHy opened this issue Aug 2, 2023 · 0 comments
Open

@property.array ignores json schema definition #9807

nathHy opened this issue Aug 2, 2023 · 0 comments
Labels

Comments

@nathHy
Copy link

nathHy commented Aug 2, 2023

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 nathHy added the bug label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant