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
4
votes
1 answer

How can I validate number of digits in a number using JSON Schema (ajv)?

In a two-factor authentication (2FA) the form ask a code formed by only 6 digits for exampe: 064964 I use the famous Ajv JSON Schema Validator I can not build the validation scheme for this code: export const code = { 'type': 'object', …
Janka
  • 1,908
  • 5
  • 20
  • 41
4
votes
1 answer

Ajv: validate json with dynamic keys

I use ajv to validate JSON data model before inserting/updating my database. Today I want to use this structure: const dataStructure = { xxx1234: { mobile: "ios" }, yyy89B: { mobile: "android" } }; My keys are dynamic because they are…
Vivien Adnot
  • 1,157
  • 3
  • 14
  • 30
4
votes
2 answers

JSON schema validation with perfect messages

I have divided the data entry in a REST call in 4 parts. Data can be sent to REST call via:- headers query params path params request body So in order to validate the presence of any key in any of the above 4 parts I have created a schema in this…
Ankur Verma
  • 5,793
  • 12
  • 57
  • 93
4
votes
2 answers

Using ref in JSON Schema to refer to a local schema on disk

I have a JSON schema file: { "id":"http://schema.acme.com/user", "$schema":"http://json-schema.org/draft-06/schema#", "definitions":{ "user":{ "description":"The name the user has selected", "type":"object", …
Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90
4
votes
3 answers

JSON schema validation in chrome packaged app

I am tring to use AJV JSON schema validator in my chrome app. But I am getting the error EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy…
anton.mo
  • 103
  • 1
  • 11
3
votes
1 answer

how to remove non-schema params from the query

according to the fastify 4.0 docs, the default options for Ajv include removeAdditional: true. I have a queryString schema, and when I send a query with a param that is not in the schema, I expect that param to be removed. But no such thing happens.…
punkish
  • 13,598
  • 26
  • 66
  • 101
3
votes
2 answers

ajv - Ensure that given object structure matches structure of a custom type

I'm using ajv with TypeScript and have a custom type MyCustomType. When creating a validation schema I want to ensure that a specific property is of type MyCustomType. So ajv should validate its structure and decide whether this could be parsed to…
user19025657
3
votes
0 answers

JSON Schema forms and AJV: validation warnings instead of errors

I have a specific use case in which we use several JSON schemas to create forms using @jsonforms/core in combination with @jsonforms/angular (jsonforms.io). The validation happens as recommended with ajv. To approach this as generic as possible (I…
3
votes
1 answer

Error: NOT SUPPORTED: keyword "id", use "$id" for schema ID following Angular13 upgrade

I receive the following error while running my e2e tests after upgrading from Angular12 to Angular13. How do I start to track down the source of this error? I can compile with 'ng build'. …
samneric
  • 3,038
  • 2
  • 28
  • 31
3
votes
1 answer

How to use property names in error messages with AJV errors

I am using ajv-errors with ajv v8 - According to docs I should be able to use a pointer to reference the field name but my attempts are failing with errors such as: Cannot access property/index 0 levels up, current level is 0 Example schema: { …
cyberwombat
  • 38,105
  • 35
  • 175
  • 251
3
votes
1 answer

ajv@7.2.4 - Error: strict mode: unknown keyword: "unevaluatedProperties" -

I expect the ajv keyword a unevaluatedProperties to be defined and working in ajv version 7.2.4, however I get the error message in the title. Here is the npm version listing: $ npm list ajv tscapi@0.0.1 /mnt/common/github/tscapi ├── ajv@7.2.4 └─┬…
Craig Hicks
  • 2,199
  • 20
  • 35
3
votes
1 answer

JSON not being parsed for validation when doing a POST request to Fastify

In my routes, I have the following: const reservationSchema = { body: { type: 'object', required: ['in', 'out', 'guests', 'language', 'roomsSelected'], properties: { language: { type: 'string', }, // ...…
Mike
  • 23,542
  • 14
  • 76
  • 87
3
votes
2 answers

How can i override default error messages text in JSON forms

TLDR: I need to customize the default error messages provided by JSON form. Eg if field is required then JSON form give error like is a required property, I want it to return error message text like Invalid input.... I've created a JSON form with…
Jawad
  • 103
  • 1
  • 8
3
votes
1 answer

Validate using a specific definition with ajv

I have a JSON Schema file describing my API. It consists of some definitions as well as some vestigial parts from codegen that I'd like to ignore (the properties and required fields): { "$schema": "http://json-schema.org/draft-07/schema#", …
danvk
  • 15,863
  • 5
  • 72
  • 116
3
votes
1 answer

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

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"…
iaforek
  • 2,860
  • 5
  • 40
  • 56