【发布时间】:2019-08-21 15:16:26
【问题描述】:
我正在使用带有内置 AJV JSON Schema 验证器的 Fastify v2。我正在从另一个服务中提取一些数据,有时字段存在,有时不存在。这很好,但如果该字段未定义,我想将其默认为 null 而不是未定义,因为我依赖于存在的对象的键。
例子:
module.exports = {
$id: "transaction",
type: "object",
required: [
"txnDate",
],
properties: {
txnDate: {type: ["integer", "null"], minimum: 0, default: null},
},
};
当我尝试以这种方式设置默认值时,Fastify 正在抛出 TypeError: Cannot use 'in' operator to search for 'anyOf' in null。有没有办法使用 AJV 在 Fastify 中获得我想要的行为?
【问题讨论】:
标签: javascript node.js jsonschema ajv fastify