ajv-validator / ajv-validator/ajv-keywords

Example of async keyword with a standalone gen

未關閉
#389 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
257
分支
51
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。