bug: ajv example validation
Describe the bug
Steps to reproduce
git clone https://github.com/mosoriob/loopback-next.git
cd loopback-next/
cd sandbox/validation-ajv
npm install
npm test
Current Behavior
The test fail with error:
Request POST /pets failed with status code 500. Error: strict mode: unknown keyword: "example"
Link to reproduction sandbox
https://github.com/mosoriob/loopback-next.git
More details
The API was generated using lb4 openapi
$ lb4 openapi pet.yaml
Loading pet.yaml...
? Select controllers and/or service proxies to be generated: OpenApiController
create src/models/pet.model.ts
create src/models/new-pet.model.ts
create src/models/error.model.ts
create src/controllers/open-api.controller.ts
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
added 38 packages, and audited 609 packages in 10s
80 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Logs
No response
Additional information
Similar to: https://github.com/loopbackio/loopback-next/issues/4939
Reproduction
https://github.com/mosoriob/loopback-next.git
this seems to be an issue with the current ajv version, a workaround to fix this is to manually add example as a keyword to your loopback 4 application
src/application.ts
this.bind<AjvKeyword>("ajv.keywords.example").to({ keyword: "example" }).tag(RestTags.AJV_KEYWORD);
Your workaround works! Thanks! :)
@nflaig what to write if I want to remove any defined keyword like minimum or maximum. So that I can redefine that
No idea if that works, naively would assume just overriding it but that might not be possible if it already exists. There might be other ways but that's rather ajv specific.
Let's wait and see if there is a response in the issue you opened
- https://github.com/ajv-validator/ajv/issues/2301