ajv-validator / ajv-validator/ajv-keywords

Example of async keyword with a standalone gen

Aberta
#389 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
257
Forks
51
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

Hi,

I tried to follow your [doc](https://ajv.js.org/keywords.html#define-keyword-with-compile-function) on adding keywords with a `compile` function. When I try to generate the standalone validator, I get

`ValueError: CodeGen: "code" for keyword0 not defined`

This is the keyword code for reference:

```js
ajv.addKeyword({
keyword: "notExists",
async: true,
schema: true,
valid: true,
modifying: false,
error: {
message: ({data, schema, gen}) => {
return gen.name(schema.column) + " already exists";
}
},
type: ["string", "number"],
schemaType: "object",
compile: (schema) => {
return async function (data) {
try {
const res = await fetch(`/api/ajv/exists`, {
body: JSON.stringify({
column: schema.column,
table: schema.table,
value: data,
}),
method: "GET",
}).then((res) => res.json());
return !res;
} catch (e) {
return true;
}
};
},
metaSchema: {
type: "object",
properties: {
column: { type: "string" },
table: { type: "string" },
},
required: ["column", "table"],
},
});```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.