Tag: ajv

AJVvalidation:数据path不一致

我有一个像这样的AJV模式: // schema.js module.exports = { title: 'task', description: 'A Task Schema', type: 'object', properties: { object_city: { title: 'City', type:'string' }, object_zip: { title: 'Zip Code', type: 'string', maxLength: 5, minLength: 5 } }, required: ['object_zip', 'object_city'], additionalProperties: false }; 当我对这个模式运行我的validationtesting时,丢失object_city的结果是: { keyword: 'required', dataPath: '', schemaPath: '#/required', params: { missingProperty: 'object_city' }, message: […]

如何创buildtypes为string或null的JSON模式属性

我的模式看起来像这样: schema: { type: 'object', properties: { id: { type: 'string' } } } 我想被允许设置string或null,我该怎么做?

Json Schema:validation数组

我试图validation包含两个键, tags和parameters的模式,这些键是用于任意键值对的数组。 出于某种原因,但我无法得到任何我指定这两个键validation失败(我使用nodejs库ajv )。 这是模式定义: var cfStackSchema = { name: { type: "string" }, application: { type: "string" }, account: { type: "string" }, environment: { type: "string" }, tags: { type: "array", items: { type: "object", patternProperties: { "^[a-zA-z0-9]$": { type: "string" } }, additionalProperties: false }, additionalItems: false }, parameters: { type: "array", […]

为什么Ajv在编译期间无法parsing引用?

以下是我试图编译和用于validation的JSON模式的示例。 为了完成这个,我使用'ajv'npm模块 。 这是我正在运行的代码… var ajv = require('ajv')(); var contactSchema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Contact", "type": "object", "additionalProperties": false, "properties": { "work": { "$ref": "#definitions/phone" }, "home": { "$ref": "#definitions/phone" }, }, "definitions": { "phone": { "type": "object", "required": ["number"], "properties": { "number": { "type": "string" }, "extension": { "type": "string" } } } […]

用于json对象的NodeJSvalidation库

我需要在我的NodeJS应用程序中validation一些对象。 我已经使用了一个很棒的库express-validator ,它完美的工作,但是现在我需要validation不同的对象,不仅仅是请求,而且就expression式validationvalidator ,它使用validationvalidator库,而不是支持stringtypes以外的types。 我发现不同的变体,如Jsonschema , Ajv 他们提供了很好的function,但我需要能够设置错误消息,而不是只是捕获exception或从返回对象parsing它。 像那样 var schema = { "id": "/SimplePerson", "type": "object", "properties": { "name": {"type": "string", "error": "A name should be provided"}, "address": {"$ref": "/SimpleAddress"}, "votes": {"type": "integer", "minimum": 1} } }; 所以我可以为每个属性设置一个错误消息。 有没有现成的解决scheme来实现这个function? 可能的解决scheme 我find了一个伟大的图书馆JSEN它提供了必要的function。