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

bug: ajv example validation

Open mosoriob opened this issue 2 years ago • 4 comments

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

mosoriob avatar Mar 01 '23 18:03 mosoriob

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);

nflaig avatar Mar 01 '23 18:03 nflaig

Your workaround works! Thanks! :)

mosoriob avatar Mar 01 '23 21:03 mosoriob

@nflaig what to write if I want to remove any defined keyword like minimum or maximum. So that I can redefine that

jashanbaatth avatar Jun 30 '23 18:06 jashanbaatth

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

nflaig avatar Jun 30 '23 19:06 nflaig