Comments (6)
That's possible as for 10 or less items ajv generates a single expression and for more than 10 generates a "for" loop. Although there is a test for "required" it is obviously missing your case. Could you please post your schema and the data that fails?
from ajv.
Sure.
On a side note, this bug happens to all the schemas I created.
Schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "NodeJS Search Result Response without Hotel Infos",
"description": "A response from a Search Result Call without hotel data",
"type": "object",
"properties": {
"error": {
"description": "error code if an error occurs",
"type": ["integer", "null"]
},
"errorDesc": {
"description": "error description",
"type": ["string", "null"]
},
"status": {
"description": "operation status",
"type": "integer"
},
"statusDesc": {
"description": "status description",
"type": "string"
},
"sid": {
"description": "search Id",
"type": "integer"
},
"offers":{
"description": "List of Offers",
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"description": "an offer",
"type": "object",
"properties": {
"shop": {
"description": "shop offer is from",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "integer"
}
},
"required": [
"name",
"id"
]
},
"shopId": {
"type": "integer"
},
"bookingId": {
"description": "generated booking ID reflecting this offer, used later for deeplink logging",
"type": "string"
},
"partnerHotelId": {
"description": "the shops ID for this hotel",
"type": "string"
},
"arrival": {
"description": "arrival date",
"type": "string",
"pattern": "^(\\d{4})\\-(\\d{2})\\-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})$"
},
"departure": {
"description": "departure date",
"type": "string",
"pattern": "^(\\d{4})\\-(\\d{2})\\-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})$"
},
"hotelId": {
"description": "idealo hotel id",
"type": "integer"
},
"rooms": {
"description": "room definition",
"type": "array",
"items": {
"type": "object",
"properties": {
"roomDesc": {
"type": ["string", "null"]
},
"roomType": {
"description": "usually the number of beds",
"type": ["string", "integer"]
},
"deeplinkOffer": {
"description": "link to the hotel on the shop site",
"type": "string",
"format": "uri"
},
"priceTotal": {
"type": ["number", "string"]
},
"priceAvg": {
"type": ["number", "string"]
},
"partnerRoomType": {
"description": "room description by the shop",
"type": ["null", "string"]
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$"
},
"breakfast": {
"type": "string"
},
"storno": {
"type": "string"
},
"stornoText": {
"type": ["string", "null"]
},
"creditcard": {
"type": ["string", "null"]
},
"bookingId": {
"description": "generated booking ID reflecting this offer, used later for deeplink logging",
"type": "string"
}
},
"required": [
"creditcard",
"bookingId",
"roomDesc",
"roomType",
"deeplinkOffer",
"priceTotal",
"priceAvg",
"partnerRoomType",
"currency",
"breakfast",
"storno",
"stornoText"
]
},
"minItems": 1
}
},
"required": [
"shop",
"shopId",
"bookingId",
"partnerHotelId",
"arrival",
"departure",
"hotelId",
"rooms"
]
}
},
"additionalProperties": false
}
},
"required": [
"error",
"errorDesc",
"status",
"statusDesc",
"sid",
"offers"
]
}
Data:
{
"cachedSid": null,
"error": null,
"errorDesc": null,
"sid": 808,
"status": 250,
"statusDesc": "Request Completed",
"last": 0,
"offers": {
"0": {
"shop": {
"name": "",
"id": 1
},
"shopId": 1,
"bookingId": "df449f7fd1cb27005bac2d2c66f190f9",
"partnerHotelId": "219587",
"arrival": "2015-08-08 00:00:00",
"departure": "2015-08-13 00:00:00",
"hotelId": 47503,
"rooms": [
{
"roomDesc": "Economy Class Double",
"roomType": 2,
"deeplinkOffer": "http://example.com",
"priceTotal": "336.00",
"priceAvg": "67.20",
"partnerRoomType": "Doppelzimmer",
"currency": "EUR",
"breakfast": "unknown",
"storno": "yes",
"stornoText": null,
"creditcard": "unknown",
"bookingId": "df449f7fd1cb27005bac2d2c66f190f9"
}
]
},
"1": {
"shop": {
"name": "",
"id": 1
},
"shopId": 1,
"bookingId": "81d87fb7e7acbf599c11cc4039460106",
"partnerHotelId": "558193",
"arrival": "2015-08-08 00:00:00",
"departure": "2015-08-13 00:00:00",
"hotelId": 85077,
"rooms": [
{
"roomDesc": "Standard-Doppel- oder -Zweibettzimmer - Super Sparangebot, ohne Erstattung, ohne Frühstück",
"roomType": 2,
"deeplinkOffer": "http://example.com",
"priceTotal": "323.00",
"priceAvg": "64.60",
"partnerRoomType": "Doppelzimmer",
"currency": "EUR",
"breakfast": "unknown",
"storno": "no",
"stornoText": null,
"creditcard": "unknown",
"bookingId": "81d87fb7e7acbf599c11cc4039460106"
}
]
},
"2": {
"shop": {
"name": "",
"id": 10
},
"shopId": 10,
"bookingId": "55855141486aa48a540cb92469912ad9",
"partnerHotelId": "219587",
"arrival": "2015-08-08 00:00:00",
"departure": "2015-08-13 00:00:00",
"hotelId": 47503,
"rooms": [
{
"roomDesc": "Economy Class Double",
"roomType": 2,
"deeplinkOffer": "http://example.com",
"priceTotal": "336.00",
"priceAvg": "67.20",
"partnerRoomType": "Doppelzimmer",
"currency": "EUR",
"breakfast": "unknown",
"storno": "yes",
"stornoText": null,
"creditcard": "unknown",
"bookingId": "55855141486aa48a540cb92469912ad9"
}
]
}
},
"parserErrors": [],
"statistic": {
"offers": 17,
"uniqueHotelIds": 8,
"hotelInfos": 8,
"shops": 19,
"uniqueTagIds": 90,
"tags": 90,
"resultRequestCount": 3
},
"data": {
},
"searchFinished": true
}
This is a little test script I use:
"use strict";
var ajv = new require('ajv')({"allErrors": true}),
fs = require('fs');
var schema = JSON.parse(fs.readFileSync('schema.json'));
var data = JSON.parse(fs.readFileSync('data.json'));
var valid = ajv.validate(schema, data);
if (!valid) {
console.log(ajv.errors);
} else {
console.log('JSON valid');
}
from ajv.
Thanks! I'll have a look
from ajv.
It is fixed, it was a bug with "required" validation with many properties (>10 with allErrors, > 20 without - that's why it was passing for you). Instead of testing the data on the current level, it was testing top-level data.
Your data passes too.
Thank you.
from ajv.
Thanks a lot.
from ajv.
You're welcome
from ajv.
Related Issues (20)
- Verify is incorrectly typed for inline schemas HOT 1
- Error: strict mode: unknown keyword: "errorMessage" HOT 3
- Disable reportTypeError to enable users to implement their own coercion rule
- default value not applied when using $ref HOT 1
- / gets converted to ~1 in errors HOT 1
- anyOf is failing, although data is valid HOT 3
- validate.errors format HOT 1
- `oneOf` with coercion produces the wrong coerced value HOT 2
- Change Linter HOT 2
- Why regex pattern not works ? HOT 1
- Runtime discriminator to be able to support useDefaults within anyOf/oneOf HOT 1
- Unexpected behavior with removeAdditional and minProperties HOT 1
- Default export broken for typescript moduleResolution node16 HOT 10
- Contains object property with unknown key matching a schema HOT 1
- Distinction between addVocabulary and addKeyword in the docs
- Documentation dead links HOT 1
- Toss a Warning instead of throwing an error when adding a keyword HOT 6
- Ref within def does not act consistently
- JSONSchemaType $ref doesn't work in array type. HOT 5
- oneOf returns unwanted errors HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ajv.