ajv

JSONSchema - Required property dependent on parent property

纵然是瞬间 提交于 2019-12-20 05:47:04
问题 I would like to apply an additional "required" property in an array sub schema based on the presence of a property in the root schema. I have my schema set like this: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required":[ "isParentDependency", "subArray" ], "properties": { "isParentDependency": { "$id": "#/properties/isParentDependency", "type": "boolean" }, "subArray": { "$id": "#/properties/subArray", "type": "array", "items": { "$id": "#/properties

JSON schema validate oneOf two or allOf

巧了我就是萌 提交于 2019-12-14 02:07:38
问题 i want to validate following json schema, i am using Ajv npm package. { "email": "xyzmail@gmail.com", "phone": "1112223334", "country_code": "91" } i want either email only, or phone and country_code only, or a ll of three properties should be there. i have tried oneOf, allOf, anyOf also have tried nested of theme but in some conditions its working and in some condidions its not working. i have tried following code { "type": "object", "properties": { "email": { "type": "string", "format":

AJV schema validation for array of objects

萝らか妹 提交于 2019-12-14 01:04:22
问题 I am trying to validate array of objects using AJV schema validation. Below is the sample code var Ajv = require('ajv'); var schemaValidator = Ajv(); var innerSchema = { "type" : "object", "properties" : { "c" : { "type" : "string" }, "d" : { "type" : "number" } }, "required" : ["c"] } var innerArraySchema = { "type": "array", "items" : { "#ref": innerSchema } } var schema = { "type" : "object", "properties" : { "a" : { "type" : "string" }, "b" : { "type" : "string" }, "obj" :

Why not to consider models in REST API versioning?

冷暖自知 提交于 2019-12-14 00:04:42
问题 There was an answer to similar question but that was too specific to an example and doesn't answer in general. Can any one please tell how to handle the below scenario if models are not versioned? PUT /v1/users username (string) email (string) (required) password (string) (required) POST /v2/users username (string) (required) email (string) required password (string) (required) Assuming the model name is UserModel , in v1 version username is optional but in V2 it's required. If we use a

How to remove dependencies of order in Json schema in case of Array of objects

99封情书 提交于 2019-12-13 06:27:50
问题 I have one Json schema template, which contains array of objects. And I need to verify Json input with that template. But I want this should not dependent on order for object in array. And below we have array of 3 different object in template i.e. abs, endpoint and dispatch. I want to remove dependency of order from here. I can provide ant order of items in Json input schema. It should not dependent on template. I am using 'ajv' node js template to validate the Json input with template data.

AJV schema validation for nested object

爷,独闯天下 提交于 2019-12-12 04:46:55
问题 Functions returns object which looks something like this: { "answer": { "vehicle_type": 1, "message": "Car" }, "model": "VW", "color": "red" } 'Answer' object is always there. Other fields are there based on 'vehicle_type'. E.g. if vehicle_type = 1 there are 'model' and 'color'. if vehicle_type = 2 there are 'engine_count', 'seat_count' and 'wing_count'. I am trying to write JSON-schema which I will use to validate returned object. I would like to set 'model' and 'color' as required

TypeError: Ajv is not a constructor

橙三吉。 提交于 2019-12-11 04:25:32
问题 I have this class where I try to instantiate Ajv with the new keyword and I get this error: TypeError: Ajv is not a constructor Code: import * as Ajv from "ajv"; export class ValidateJsonService { validateJson(json, schema) { console.log(Ajv); let ajv = new Ajv({ allErrors: true }); if (!ajv.validate(schema, json)) { throw new Error("JSON does not conform to schema: " + ajv.errorsText()) } } } The console log: This code used to be working and it is how Ajv is used. From the Ajv docs: The

Use json-schema to require or disallow properties based on another property value?

耗尽温柔 提交于 2019-12-11 04:14:51
问题 What I'm trying to accomplish in json-schema: when the property enabled is true , certain other properties should be required. When false , those properties should be disallowed. Here's my json-schema: { "type": "object", "properties": { "enabled": { "type": "boolean" } }, "required" : ["enabled"], "additionalProperties" : false, "if": { "properties": { "enabled": true } }, "then": { "properties": { "description" : { "type" : "string" }, "count": { "type": "number" } }, "required" : [

Use object property keys as enum in JSON schema

坚强是说给别人听的谎言 提交于 2019-12-07 11:14:09
问题 I'm trying to validate a JSON file using JSON Schema, in order to find cases of "broken references". Essentially my file consists of items and groups, with each item belonging to a single group referenced by the groups property key, like so: { "items": { "banana": { "name": "Banana", "group": "fruits" }, "apple": { "name": "Apple", "group": "fruits" }, "carrot": { "name": "Carrot", "group": "vegetables" }, "potato": { "name": "Potato", "group": "vegetables" }, "cheese": { "name": "Cheese",

Use object property keys as enum in JSON schema

落爺英雄遲暮 提交于 2019-12-05 15:53:59
I'm trying to validate a JSON file using JSON Schema, in order to find cases of "broken references". Essentially my file consists of items and groups, with each item belonging to a single group referenced by the groups property key, like so: { "items": { "banana": { "name": "Banana", "group": "fruits" }, "apple": { "name": "Apple", "group": "fruits" }, "carrot": { "name": "Carrot", "group": "vegetables" }, "potato": { "name": "Potato", "group": "vegetables" }, "cheese": { "name": "Cheese", "group": "dairy" } }, "groups": { "fruits": { "name": "Fruits" }, "vegetables": { "name": "Vegetables" }