Questions tagged [ajv]

Ajv is a JSON schema validators for node.js and browser. It supports draft 4, 6, and 7, and additional extras beyond JSON Schema that make it more useful.

Ajv is a JSON Schema validator for Node.js and the browser. It supports draft 4, 6, and 7, and additional extras beyond JSON Schema that make it more useful.

Related tags:

375 questions
0
votes
1 answer

> Error: schema is invalid: data should be equal to constant in ajv JSON Schema

I'm trying to compare parced JSON to JSON reference by following code: const Ajv = require("ajv"); const parsedData = JSON.parse(fs.readFileSync(jsonDataPath, 'utf8')); const parsedSchema = JSON.parse(fs.readFileSync(jsonSchemaPath,…
overdd
  • 71
  • 1
  • 13
0
votes
2 answers

json schema to validate property value with its dynamic key

data: { "dynamic_key_1": { "key1": "value1" "id": "dynamic_key_1" }, "dynamic_key_2": { "key1": "value2" "id": "some_random" } } schema: { "patternProperties": { "^[^{}\"/\\\\]+$": { "type": "object", …
Sandeep
  • 2,041
  • 21
  • 34
0
votes
0 answers

Validate root Dictionary structure in JSON

I need to validate a JSON file which is structured as a Dictionary (key-value list) on the root level. The JSON file was initially a one-off, 5 years ago but unfortunately the entire web application is now build upon that JSON file and it would be a…
dotnetCarpenter
  • 10,019
  • 6
  • 32
  • 54
0
votes
1 answer

AJV if-then-else conditional type based on enum

I've searched examples of using if-then-else in AJV schemas but haven't found a specific case where the property type and required list change based on the value of another property. Case: I need to upgrade userSchema so that if property role =…
ndemasie
  • 590
  • 1
  • 6
  • 17
0
votes
2 answers

fastify schema validation with trim

I have written a schema as follows input: { type: "string", allOf: [ { transform: [ "trim" ] }, { …
user3740951
  • 1,109
  • 2
  • 20
  • 39
0
votes
0 answers

how can we use ''$data'' with ''required'' in ajv?

I have a json schema like this : let schema = { type: 'object', properties : { first: { type : 'object', properties : { foo : {type : 'string'} } }, second: { type : 'object', properties : { …
hoj
  • 158
  • 1
  • 1
  • 8
0
votes
1 answer

How to use hyper-schema with AJV?

I need to implement a json schema validator based on existing schemas that use hyper-schema To do so I tried to take advantage of the ajv library (version 6.12.2), here is my implementation: const Ajv = require('ajv'); // Ajv does not allow to…
0
votes
1 answer

openapi-generator codegen: Ajv cannot resolve reference to requestBodies from openapi 3.0.0

I created a server stub using my own openapi-3.0.0 template from openapi-generator. While implementing the API logic for creating resource, I'm referencing a component declared under requestBodies as follows components: requestBodies: …
Naveen Karnam
  • 433
  • 2
  • 9
  • 26
0
votes
2 answers

IE 11 "Expected Identifier" error on spread operator found in AJV code

In my Angular 6 app, I'm getting a console error in IE 11 as "Script1010: "Expected Identifier". No issues with evergreen browsers. The error occurs at the first "." in the spread operator function, identified in the bundled js file…
Scott B
  • 38,833
  • 65
  • 160
  • 266
0
votes
0 answers

I'm trying to use AJV to validate a file but it always says valid even when I try to make it error

I'm trying to use AJV to validate a file but it always says valid even when I try to make it error. It there something that needs to be set to get it to report errors? Any pointers would be helpful. Code sample - My schema and JSON file is too…
mtod
  • 11
  • 2
0
votes
1 answer

Understanding JSON Schema errors using ajv

I have the following schema and json to validate using ajv. const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "countries" ], "definitions": { "europeDef": { "type": "object", …
user8479984
  • 451
  • 2
  • 9
  • 23
0
votes
1 answer

JSON Schema / Ajv - How to validate the combined lengths of an array of strings?

Let's say that I need to validate the shipping address of an order: { "id": 1 , "recipient": "John Doe" , "shipping_address": [ "address line 1" , "address line 2" , "address line 3" …
customcommander
  • 17,580
  • 5
  • 58
  • 84
0
votes
2 answers

Fastify response schema with $merge-keyword throws FST_ERR_SCH_BUILD

When adding a response schema to a fastify resource that leverages the $merge keyword, an error FST_ERR_SCH_BUILD: Failed building the schema for GET: /, due error undefined unsupported is thrown. Schema looks like the following, but the same error…
tuberains
  • 191
  • 9
0
votes
1 answer

Ajv validation always returns 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 =…
Stephan Ahlf
  • 3,310
  • 5
  • 39
  • 68
0
votes
1 answer

AJV - Validation of complex schema

I am using AJV as my schema validator for API inputs. I need to validate if I received data in this format: floors: [ { name: "Floor 1", rooms: [ { name: "Room 1" }, ... more…
Baterka
  • 3,075
  • 5
  • 31
  • 60