javascript - Ajv 验证始终返回 true
问题描述
我尝试验证JSON
现有 JSON 模式的数据。
我试过了
const filename = path.join(__dirname, 'google-wallet-object-schema.json') // from https://walletobjects.googleapis.com/$discovery/rest?version=v1
const schemas = require(filename)
const ajv = new Ajv({
schemaId: 'auto',
additionalProperties: false,
$data: true,
// unknownFormats: 'ignore',
allErrors: true,
validateSchema: true,
format: 'full',
//jsonPointers :true
/* schemas: schemas.schemas */
})
ajv.addSchema(schemas.schemas).compile(schemas.resources);
const v = ajv.getSchema('#/flightobject/methods/insert')
const test = v({ dddd: '1' })
console.log(test)
console.log(ajv.errors)
我期望false
但验证总是返回true
有谁知道我在这里做错了什么?
解决方案
该 JSON 文档不是 JSON 模式。
根据https://developers.google.com/discovery
基于 JSON Schema的受支持 API 模式目录。
每个受支持 API 的机器可读“发现文档”。
您必须要么使用他们提供的客户端库,要么编写自己的“发现文档”处理器。
推荐阅读
- google-chrome - 保存来自 Chrome(或其他浏览器)开发者工具的所有 XHR 请求
- javascript - 将对象属性(列名)从对象数组映射到行和标题(列)Javascript
- javascript - 使用 laravel 和 vue js 时,在 css 应用之前渲染 html
- r - 仅显示列之间的差异小于 30 的行值
- mysql - mysql根据条件使用一条语句更新多张表的多条记录
- c++ - 睡眠功能的合适替代品以使我的程序在 C++ 中更流畅?
- python - 生产者-消费者问题 - 尝试保存到 csv 文件中
- r - 如何在ggplot中镜像y轴
- ruby - Bundler 错误 - 无法找到 rake-13.0.1,即使它已安装
- python - 这个类装饰器中的 get 特殊方法是做什么的?