Ajv Number Discriminator

node v18.11.0
version: 1.0.3
endpointsharetweet
var Ajv = require('ajv'); ajv = new Ajv({ discriminator: true, }); var schema = { type: "object", discriminator: {propertyName: "typeId"}, required: ["typeId"], oneOf: [ { properties: { typeId: {const:1}, val: {type: "number"}, } }, { properties: { typeId: {const:2}, val: {type: "string"}, } }, ] }; var data = { typeId: 1, val: 7, }; var validate = ajv.compile(schema); console.log(validate(data)); console.log(validate.errors);
Loading…

no comments

    sign in to comment