我尝试通过现有的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
的地方,有人知道我在做什么错吗?
答案 0 :(得分:0)
该JSON文档不是JSON架构。
根据https://developers.google.com/discovery
基于JSON架构 的受支持API架构的目录 。
每种支持的机器可读的“发现文档” API。
您将不得不使用它们提供的客户端库,或者编写自己的“发现文档”处理器。