Skip to content
New issue

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

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

Already on GitHub? # to your account

ability to generate standalone code from the callback specified in the validate property #2517

Open
denisovan31415 opened this issue Dec 23, 2024 · 0 comments

Comments

@denisovan31415
Copy link

If a callback function inputted to the validate property is self contained, then it could be used to generate the standalone code.

Why not allow the client to specify a flag that would use the validate callback to generate standalone code?

ajv.addKeyword({
  keyword: "even",
  type: "number",
  schemaType: "boolean",
  // $data: true // to support [$data reference](./guide/combining-schemas.md#data-reference), ...
  validate: (schema, data) => {
    return true;
  },
  code(cxt) {
    const { data, schema } = cxt;
    const op = schema ? Ajv._`!==` : Ajv._`===`;
    cxt.fail(Ajv._`${data} %2 ${op} 0`); // ... the only code change needed is to use `cxt.fail$data` here
  },
});
# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

1 participant