loopbackio / loopbackio/loopback-next

ajv request body validation regression following an upgrade to @loopback/rest 15.0.3

Open
#11,096 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

Describe the bug

Since after upgrading to @loopback/rest 15.0.3 , ajv request body validation fail when the schema contain the "discriminator" key word.

Logs
equest POST /accounts/7342217301273/actions failed with status code 500. Error: strict mode: unknown keyword: "discriminator"
    at checkStrictMode (/home/fidgi/my-app/node_modules/ajv/lib/compile/util.ts:211:28)
    at checkUnknownRules (/home/fidgi/my-app/node_modules/ajv/lib/compile/util.ts:27:22)
    at checkKeywords (/home/fidgi/my-app/node_modules/ajv/lib/compile/validate/index.ts:153:20)
    at validateFunctionCode (/home/fidgi/my-app/node_modules/ajv/lib/compile/validate/index.ts:40:5)
    at Ajv.compileSchema (/home/fidgi/my-app/node_modules/ajv/lib/compile/index.ts:163:25)
    at Ajv._compileSchemaEnv (/home/fidgi/my-app/node_modules/ajv/lib/core.ts:737:24)
    at Ajv.compile (/home/fidgi/my-app/node_modules/ajv/lib/core.ts:389:34)
    at createValidator (/home/fidgi/my-app/node_modules/@loopback/rest/src/validation/request-body.validator.ts:236:18)
    at validateValueAgainstSchema (/home/fidgi/my-app/node_modules/@loopback/rest/src/validation/request-body.validator.ts:153:16)
    at validateRequestBody (/home/fidgi/my-app/node_modules/@loopback/rest/src/validation/request-body.validator.ts:76:9)
    at buildOperationArguments (/home/fidgi/my-app/node_modules/@loopback/rest/src/parser.ts:92:28)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async MySequence.handle (/home/fidgi/my-app/src/sequence.ts:51:20)
    at async HttpHandler._handleRequest (/home/fidgi/my-app/node_modules/@loopback/rest/src/http-handler.ts:115:5)
Additional information

This seems to be related to this commit

Reproduction

n/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked commit and the validation flow in @loopback/rest/src/validation/request-body.validator.ts, especially createValidator and validateValueAgainstSchema. Reproduce the request-body schema failure with the discriminator keyword, then verify that validation no longer rejects it after the regression is addressed.

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
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.