英文:
Ajv validation always returns true
问题
I try to validate JSON
data regarding an existing JSON schema.
我尝试验证现有的 JSON 模式。
I tried
我尝试过以下代码:
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)
这里我尝试验证 JSON 数据,但是无论如何它都返回 true
,我是否有做错什么?
英文:
I try to validate JSON
data ragarding an existing JSON schema.
I tried
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)
where I expect false
but the validation always returns true
does anyone know what I am doing wrong here?
答案1
得分: 0
那个JSON文档不是JSON模式。
根据https://developers.google.com/discovery
基于JSON模式的受支持API模式目录。
每个受支持API的可机器读取的“发现文档”。
您必须使用他们提供的客户端库,或编写自己的“发现文档”处理器。
英文:
That JSON document is not a JSON Schema.
According to https://developers.google.com/discovery
> A directory of supported APIs schemas based on JSON Schema.
>
> A machine-readable "Discovery Document" for each of the supported
> APIs.
You'll have to either use the client libraries they supply, or write your own "Discovery Document" processor.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论