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
8
votes
4 answers

Advanced conditions with class-validator (possible)?

I have TypeScript NestJS project. I need to validate incoming DTO to my API. It can be described as "creating of project" where we have type of building (House, Flat, Garden) and depending on that type we need to define: House: FLOORS including…
Baterka
  • 622
  • 4
  • 9
  • 20
8
votes
2 answers

Ajv custom error message for type

i was exploring Ajv with ajv-errors for validating json schema and producing custom error messages. everything works as of now but i can't set custom error message for type for individual values. const emailSchema = { type: 'object', required:…
Nikhil Pujari
  • 143
  • 1
  • 2
  • 13
7
votes
3 answers

AJV: no schema with key or ref "https://json-schema.org/draft-07/schema"

I am using ajv 8.6.2 I have schemas that validate against draft-07 using the default export When I use the draft-09 export all of my schemas give me this error: no schema with key or ref "https://json-schema.org/draft-07/schema" Same error exists…
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100
7
votes
3 answers

user-friendly error message using ajv json schema validator

Assuming I have the schema & JSON: JSON Schema: const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "countries" ], "definitions": { "europeDef": { "type": "object", …
user8479984
  • 451
  • 2
  • 9
  • 23
7
votes
1 answer

Use object property keys as enum in JSON schema

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: { …
Simon
  • 3,667
  • 1
  • 35
  • 49
7
votes
1 answer

How to validate empty array of strings with ajv?

I make json validation with ajv. I need to validate array of strings. I know which elements can be placed there so I make appropriate 'enum'. But in some case enum can be empty and array can be empty too. Here is simple test: var schema = { …
NtsDK
  • 951
  • 1
  • 9
  • 19
6
votes
0 answers

Ajv: Error: strict mode: unknown keyword: "$schema"

Using ajv v8.6.3 nodejs and typescript Trying to parse JSON however I am getting this Error: strict mode: unknown keyword: "$schema" anyone shed some light on this? export const mySchema ={ "$schema": "http://json-schema.org/draft-07/schema#", …
succeed
  • 834
  • 1
  • 11
  • 28
6
votes
1 answer

ajv-errors plugin with Fastify gives error as Cannot find module 'ajv/dist/compile/codegen'

To give some background, I am trying to add proper schema validation error message formatting (to sugercoat the validation errors) for AJV JSON Schema Validation. I am using Fastify middleware. My purpose is to wrap the default schema error…
Pradip
  • 509
  • 1
  • 5
  • 22
6
votes
1 answer

JSONSchema - Required property dependent on parent property

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", …
Mike Miller
  • 3,071
  • 3
  • 25
  • 32
6
votes
2 answers

How can I fix "Can't resolve reference" error when referencing an $id in the same document?

I want to validate a JSON against a JSON schema with Ajv in JavaScript. I get the error: throw new it.MissingRefError(it.baseId, $schema, $message); ^ Error: can't resolve reference #/definitions/requestGraph from id requestGetGraphs When…
Skvupp
  • 155
  • 2
  • 3
  • 12
6
votes
1 answer

How can I get AJV (v5.0.0) to resolve $schema?

I'm having trouble getting this line to resolve at the top of my JSON Schema when compiling it with AJV: "$schema": "node_modules/ajv/lib/refs/json-schema-draft-04#" I've also tried this line to work, to no avail: "$schema":…
DEzell
  • 83
  • 4
6
votes
0 answers

"Uncaught Error: Keyword if is already defined" using ajv-keywords

I am trying to create conditional validation using if / then / else keywords from ajv-keywords, however I am getting the following error in my browser console: “Uncaught Error: Keyword if is already defined”. What am I doing wrong? import * as…
Ruth
  • 614
  • 2
  • 6
  • 20
5
votes
1 answer

How to set up a custom AJV keyword?

I'm using ajv and want to add a custom validator inspecting a given object. This custom validator should either return true or fail with the correct error message. Based on (deprecated syntax) AJV custom keyword…
user17298649
5
votes
1 answer

How to get property name from ajv output to map validation errors to human friendly messages?

I am using AJV library https://github.com/ajv-validator/ajv to validate the input of my nodejs express api. However, im having trouble extracting the property name in question for each error object in the returned array. [{ instancePath: '', …
Kay
  • 17,906
  • 63
  • 162
  • 270
5
votes
1 answer

how to make ajv-cli to consider formats

I have been experimenting with ajv-cli and trying to make it to verify a json scheme that makes use of standard formats like "ipv4" and "host-name". Despite of having ajv-formats installed, when invoked as: ajv --strict=false --validate-formats=true…
1
2
3
24 25