ajv-validator / ajv-validator/ajv

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

Abierto
#2,517 0 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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
},
});
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.