Skip to content

Commit 8c182e5

Browse files
committed
Flatten allOf keyword violations
1 parent 8353e86 commit 8c182e5

File tree

2 files changed

+49
-103
lines changed

2 files changed

+49
-103
lines changed

include/rapidjson/schema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,9 @@ class GenericSchemaValidator :
20112011
AddCurrentError(SchemaType::GetTypeString());
20122012
}
20132013
void NotAllOf(ISchemaValidator** subvalidators, SizeType count) {
2014-
AddErrorArray(SchemaType::GetAllOfString(), subvalidators, count);
2014+
for (SizeType i = 0; i < count; ++i) {
2015+
MergeError(static_cast<GenericSchemaValidator*>(subvalidators[i])->GetError());
2016+
}
20152017
}
20162018
void NoneOf(ISchemaValidator** subvalidators, SizeType count) {
20172019
AddErrorArray(SchemaType::GetAnyOfString(), subvalidators, count);

test/unittest/schematest.cpp

Lines changed: 46 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,9 @@ TEST(SchemaValidator, AllOf) {
236236

237237
VALIDATE(s, "\"ok\"", true);
238238
INVALIDATE(s, "\"too long\"", "", "allOf", "",
239-
"{ \"allOf\": {"
240-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
241-
" \"errors\": ["
242-
" {},"
243-
" { \"maxLength\": { "
244-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
245-
" \"expected\": 5, \"actual\": \"too long\""
246-
" }}"
247-
" ]"
239+
"{ \"maxLength\": { "
240+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
241+
" \"expected\": 5, \"actual\": \"too long\""
248242
"}}");
249243
}
250244
{
@@ -254,14 +248,8 @@ TEST(SchemaValidator, AllOf) {
254248

255249
VALIDATE(s, "\"No way\"", false);
256250
INVALIDATE(s, "-1", "", "allOf", "",
257-
"{ \"allOf\": {"
258-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
259-
" \"errors\": ["
260-
" { \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
261-
" \"expected\": [\"string\"], \"actual\": \"integer\""
262-
" }},"
263-
" {}"
264-
" ]"
251+
"{ \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
252+
" \"expected\": [\"string\"], \"actual\": \"integer\""
265253
"}}");
266254
}
267255
}
@@ -387,16 +375,11 @@ TEST(SchemaValidator, Ref_AllOf) {
387375
SchemaDocument s(sd);
388376

389377
INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address",
390-
"{ \"allOf\": {"
378+
"{ \"required\": {"
391379
" \"instanceRef\": \"#/shipping_address\","
392-
" \"schemaRef\": \"#/properties/shipping_address\","
393-
" \"errors\": ["
394-
" {},"
395-
" { \"required\": {"
396-
" \"instanceRef\": \"#/shipping_address\","
397-
" \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
398-
" \"missing\": [\"type\"]"
399-
"}} ] }}");
380+
" \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
381+
" \"missing\": [\"type\"]"
382+
"}}");
400383
VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true);
401384
}
402385

@@ -1537,87 +1520,48 @@ TEST(SchemaValidator, AllOf_Nested) {
15371520
VALIDATE(s, "\"ok\"", true);
15381521
VALIDATE(s, "\"OK\"", true);
15391522
INVALIDATE(s, "\"okay\"", "", "allOf", "",
1540-
"{ \"allOf\": {"
1541-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1542-
" \"errors\": ["
1543-
" {}, "
1544-
" {}, "
1545-
" { \"allOf\": {"
1546-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
1547-
" \"errors\": ["
1548-
" {}, "
1549-
" { \"enum\": {"
1550-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1551-
"}} ] }} ] }}");
1523+
"{ \"enum\": {"
1524+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1525+
"}}");
15521526
INVALIDATE(s, "\"o\"", "", "allOf", "",
1553-
"{ \"allOf\": {"
1554-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1555-
" \"errors\": ["
1556-
" { \"minLength\": {"
1557-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1558-
" \"expected\": 2, \"actual\": \"o\""
1559-
" }},"
1560-
" {},"
1561-
" {}"
1562-
" ]"
1527+
"{ \"minLength\": {"
1528+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1529+
" \"expected\": 2, \"actual\": \"o\""
15631530
"}}");
15641531
INVALIDATE(s, "\"n\"", "", "allOf", "",
1565-
"{ \"allOf\": {"
1566-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1567-
" \"errors\": ["
1568-
" { \"minLength\": {"
1569-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1570-
" \"expected\": 2, \"actual\": \"n\""
1571-
" }},"
1572-
" {}, "
1573-
" { \"allOf\": {"
1574-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
1575-
" \"errors\": ["
1576-
" { \"enum\": {"
1577-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
1578-
" }},"
1579-
" { \"enum\": {"
1580-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1581-
"}} ] }} ] }}");
1532+
"{ \"minLength\": {"
1533+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1534+
" \"expected\": 2, \"actual\": \"n\""
1535+
" },"
1536+
" \"enum\": ["
1537+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1538+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1539+
" ]"
1540+
"}")
15821541
INVALIDATE(s, "\"too long\"", "", "allOf", "",
1583-
"{ \"allOf\": {"
1584-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1585-
" \"errors\": ["
1586-
" {}, "
1587-
" { \"maxLength\": {"
1588-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1589-
" \"expected\": 5, \"actual\": \"too long\""
1590-
" }},"
1591-
" { \"allOf\": {"
1592-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
1593-
" \"errors\": ["
1594-
" { \"enum\": {"
1595-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
1596-
" }},"
1597-
" { \"enum\": {"
1598-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1599-
"}} ] }} ] }}");
1542+
"{ \"maxLength\": {"
1543+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1544+
" \"expected\": 5, \"actual\": \"too long\""
1545+
" },"
1546+
" \"enum\": ["
1547+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1548+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1549+
" ]"
1550+
"}");
16001551
INVALIDATE(s, "123", "", "allOf", "",
1601-
"{ \"allOf\": {"
1602-
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1603-
" \"errors\": ["
1604-
" { \"type\": {"
1605-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1606-
" \"expected\": [\"string\"], \"actual\": \"integer\""
1607-
" }},"
1608-
" { \"type\": {"
1609-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1610-
" \"expected\": [\"string\"], \"actual\": \"integer\""
1611-
" }},"
1612-
" { \"allOf\": {"
1613-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
1614-
" \"errors\": ["
1615-
" { \"enum\": {"
1616-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
1617-
" }}, "
1618-
" { \"enum\": {"
1619-
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1620-
"}} ] }} ] }}");
1552+
"{ \"type\": ["
1553+
" { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1554+
" \"expected\": [\"string\"], \"actual\": \"integer\""
1555+
" },"
1556+
" { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1557+
" \"expected\": [\"string\"], \"actual\": \"integer\""
1558+
" }"
1559+
" ],"
1560+
" \"enum\": ["
1561+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1562+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1563+
" ]"
1564+
"}");
16211565
}
16221566

16231567
TEST(SchemaValidator, EscapedPointer) {

0 commit comments

Comments
 (0)