ajv

How to validate json schema using avj and postman

心不动则不痛 提交于 2021-02-15 07:00:58
问题 I'm trying to validate the following json that looks like this: { "errors": false, } using this on postman: var Ajv = require('ajv'), ajv = new Ajv({logger: console, coerceTypes: false}), schema = { "errors": { "type": "number" } }; pm.test('Schema is valid', function() { var error = pm.response.json()['errors']; console.log("this is error: " +error); pm.expect(ajv.validate(schema, {errors: error})).to.be.true; }); pm.test('Schema is valid different way', function() { var error = pm.response

How to validate json schema using avj and postman

心不动则不痛 提交于 2021-02-15 07:00:55
问题 I'm trying to validate the following json that looks like this: { "errors": false, } using this on postman: var Ajv = require('ajv'), ajv = new Ajv({logger: console, coerceTypes: false}), schema = { "errors": { "type": "number" } }; pm.test('Schema is valid', function() { var error = pm.response.json()['errors']; console.log("this is error: " +error); pm.expect(ajv.validate(schema, {errors: error})).to.be.true; }); pm.test('Schema is valid different way', function() { var error = pm.response

Is it possible to reference property name in enum from another AJV definitions?

家住魔仙堡 提交于 2021-02-05 07:47:26
问题 I'm looking if it's possible to reference property names as enum values in AJV definitions. Here is an example: { "$id": "modes.json", "description": "Example modes", "type": "object", "properties": { "MODE_WALK": { "$ref": "walk.json" }, "MODE_BICYCLE": { "$ref": "bicycle.json" }, } } Then I have another file with: { "$id": "another.json", "description": "Example object", "type": "object", "properties": { "text": { "type": "string", "maxLength": 128 }, "mode": { "description": "Allowed modes

AJV always returns true

徘徊边缘 提交于 2021-01-29 18:00:21
问题 Why does the validate function always return true even if the object is wrong? const Ajv = require('ajv') const ajv = new Ajv() const schema = { query: { type: 'object', required: ['locale'], properties: { locale: { type: 'string', minLength: 1, }, }, }, } const test = { a: 1, } const validate = ajv.compile(schema) const valid = validate(test) console.log(valid) // TRUE What is wrong with my code? It is a basic example. 回答1: An empty schema is either {} or an object which none of its keys

Empty values validation in json schema using AJV

家住魔仙堡 提交于 2021-01-27 04:44:12
问题 I am using Ajv for validating my JSON data. I am unable to find a way to validate empty string as a value of a key. I tried using pattern, but it does not throw appropriate message. Here is my schema { "type": "object", "properties": { "user_name": { "type": "string" , "minLength": 1}, "user_email": { "type": "string" , "minLength": 1}, "user_contact": { "type": "string" , "minLength": 1} }, "required": [ "user_name", 'user_email', 'user_contact'] } I am using minLength to check that value

Empty values validation in json schema using AJV

喜夏-厌秋 提交于 2021-01-27 04:44:07
问题 I am using Ajv for validating my JSON data. I am unable to find a way to validate empty string as a value of a key. I tried using pattern, but it does not throw appropriate message. Here is my schema { "type": "object", "properties": { "user_name": { "type": "string" , "minLength": 1}, "user_email": { "type": "string" , "minLength": 1}, "user_contact": { "type": "string" , "minLength": 1} }, "required": [ "user_name", 'user_email', 'user_contact'] } I am using minLength to check that value

JSON schema conditional check on certain object attribute within an array

允我心安 提交于 2020-03-03 10:54:05
问题 What I want to do either via AJV - JSON Schema validation or Custom Keywords (preferably I would go with this): The Array can have 1 or 2 JSON objects with type as 'admin' and 'guest'. The "type":"guest" object will always be there and "type":"admin" object is optional. Extra Notes: -The object itself may contain addition attributes and nested objects, in future -The other valid enums aresuperadmin, admin,user and guest -The type sequence in array is: superadmin, admin,user and guest. Is it

How to use definitions from external files in JSON Schema?

徘徊边缘 提交于 2020-01-03 18:00:29
问题 I'm trying to import the definitions from another json schema using $ref but getting the following error: can't resolve reference ../base/definitions.schema.json#/definitions/datetime from id # { "$schema": "http://json-schema.org/draft-06/schema#", "definitions": { "datetime": { "type": "string" }, "name": { "type": "string" }, } } { "$schema": "http://json-schema.org/draft-06/schema#", "properties": { "active": {"type": "boolean"}, "created_at": { "$ref": "../base/definitions.schema.json#

JSON Schema - conditional validation

倾然丶 夕夏残阳落幕 提交于 2019-12-24 10:51:21
问题 I have the following Schema. I've implemented it as best I can, but it's still not working quite as I want it to. { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "title": "Ordering pizza", "propertyNames": { "enum": [ "q-who-did-you-order-from", "q-did-they-accept-your-order", "q-how-much-was-the-bill", "q-why-didnt-they-accept" ] }, "properties": { "q-who-did-you-order-from": { "type": "string", "title": "Who have you ordered pizza from?", "maxLength": 50,

Error “custom keyword definition is invalid: data.errors should be boolean”

南笙酒味 提交于 2019-12-22 01:28:33
问题 I just created a new React application using this command: create-react-app mysite.com After installation, when I tried to open it using npm start and yarn start , I got the following error. throw new Error('custom keyword definition is invalid: ' + this.errorsText(validateDefinition.errors)); ^ Error: custom keyword definition is invalid: data.errors should be boolean at Ajv.addKeyword (/Users/myAccount/Documents/Dev/Projects/ReactJS/mysite.com/node_modules/ajv/lib/keyword.js:65:13) How can