Commit 8c182e51 authored by Yuri Khan's avatar Yuri Khan

Flatten allOf keyword violations

parent 8353e868
...@@ -2011,7 +2011,9 @@ public: ...@@ -2011,7 +2011,9 @@ public:
AddCurrentError(SchemaType::GetTypeString()); AddCurrentError(SchemaType::GetTypeString());
} }
void NotAllOf(ISchemaValidator** subvalidators, SizeType count) { void NotAllOf(ISchemaValidator** subvalidators, SizeType count) {
AddErrorArray(SchemaType::GetAllOfString(), subvalidators, count); for (SizeType i = 0; i < count; ++i) {
MergeError(static_cast<GenericSchemaValidator*>(subvalidators[i])->GetError());
}
} }
void NoneOf(ISchemaValidator** subvalidators, SizeType count) { void NoneOf(ISchemaValidator** subvalidators, SizeType count) {
AddErrorArray(SchemaType::GetAnyOfString(), subvalidators, count); AddErrorArray(SchemaType::GetAnyOfString(), subvalidators, count);
......
...@@ -236,15 +236,9 @@ TEST(SchemaValidator, AllOf) { ...@@ -236,15 +236,9 @@ TEST(SchemaValidator, AllOf) {
VALIDATE(s, "\"ok\"", true); VALIDATE(s, "\"ok\"", true);
INVALIDATE(s, "\"too long\"", "", "allOf", "", INVALIDATE(s, "\"too long\"", "", "allOf", "",
"{ \"allOf\": {" "{ \"maxLength\": { "
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
" \"errors\": [" " \"expected\": 5, \"actual\": \"too long\""
" {},"
" { \"maxLength\": { "
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
" \"expected\": 5, \"actual\": \"too long\""
" }}"
" ]"
"}}"); "}}");
} }
{ {
...@@ -254,14 +248,8 @@ TEST(SchemaValidator, AllOf) { ...@@ -254,14 +248,8 @@ TEST(SchemaValidator, AllOf) {
VALIDATE(s, "\"No way\"", false); VALIDATE(s, "\"No way\"", false);
INVALIDATE(s, "-1", "", "allOf", "", INVALIDATE(s, "-1", "", "allOf", "",
"{ \"allOf\": {" "{ \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"expected\": [\"string\"], \"actual\": \"integer\""
" \"errors\": ["
" { \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"expected\": [\"string\"], \"actual\": \"integer\""
" }},"
" {}"
" ]"
"}}"); "}}");
} }
} }
...@@ -387,16 +375,11 @@ TEST(SchemaValidator, Ref_AllOf) { ...@@ -387,16 +375,11 @@ TEST(SchemaValidator, Ref_AllOf) {
SchemaDocument s(sd); SchemaDocument s(sd);
INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address", INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address",
"{ \"allOf\": {" "{ \"required\": {"
" \"instanceRef\": \"#/shipping_address\"," " \"instanceRef\": \"#/shipping_address\","
" \"schemaRef\": \"#/properties/shipping_address\"," " \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
" \"errors\": [" " \"missing\": [\"type\"]"
" {}," "}}");
" { \"required\": {"
" \"instanceRef\": \"#/shipping_address\","
" \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
" \"missing\": [\"type\"]"
"}} ] }}");
VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true); VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true);
} }
...@@ -1537,87 +1520,48 @@ TEST(SchemaValidator, AllOf_Nested) { ...@@ -1537,87 +1520,48 @@ TEST(SchemaValidator, AllOf_Nested) {
VALIDATE(s, "\"ok\"", true); VALIDATE(s, "\"ok\"", true);
VALIDATE(s, "\"OK\"", true); VALIDATE(s, "\"OK\"", true);
INVALIDATE(s, "\"okay\"", "", "allOf", "", INVALIDATE(s, "\"okay\"", "", "allOf", "",
"{ \"allOf\": {" "{ \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
" \"errors\": [" "}}");
" {}, "
" {}, "
" { \"allOf\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
" \"errors\": ["
" {}, "
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
"}} ] }} ] }}");
INVALIDATE(s, "\"o\"", "", "allOf", "", INVALIDATE(s, "\"o\"", "", "allOf", "",
"{ \"allOf\": {" "{ \"minLength\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"errors\": [" " \"expected\": 2, \"actual\": \"o\""
" { \"minLength\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"expected\": 2, \"actual\": \"o\""
" }},"
" {},"
" {}"
" ]"
"}}"); "}}");
INVALIDATE(s, "\"n\"", "", "allOf", "", INVALIDATE(s, "\"n\"", "", "allOf", "",
"{ \"allOf\": {" "{ \"minLength\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"errors\": [" " \"expected\": 2, \"actual\": \"n\""
" { \"minLength\": {" " },"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\"," " \"enum\": ["
" \"expected\": 2, \"actual\": \"n\"" " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
" }}," " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
" {}, " " ]"
" { \"allOf\": {" "}")
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
" \"errors\": ["
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
" }},"
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
"}} ] }} ] }}");
INVALIDATE(s, "\"too long\"", "", "allOf", "", INVALIDATE(s, "\"too long\"", "", "allOf", "",
"{ \"allOf\": {" "{ \"maxLength\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
" \"errors\": [" " \"expected\": 5, \"actual\": \"too long\""
" {}, " " },"
" { \"maxLength\": {" " \"enum\": ["
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\"," " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
" \"expected\": 5, \"actual\": \"too long\"" " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
" }}," " ]"
" { \"allOf\": {" "}");
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\","
" \"errors\": ["
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
" }},"
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
"}} ] }} ] }}");
INVALIDATE(s, "123", "", "allOf", "", INVALIDATE(s, "123", "", "allOf", "",
"{ \"allOf\": {" "{ \"type\": ["
" \"instanceRef\": \"#\", \"schemaRef\": \"#\"," " { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
" \"errors\": [" " \"expected\": [\"string\"], \"actual\": \"integer\""
" { \"type\": {" " },"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\"," " { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
" \"expected\": [\"string\"], \"actual\": \"integer\"" " \"expected\": [\"string\"], \"actual\": \"integer\""
" }}," " }"
" { \"type\": {" " ],"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\"," " \"enum\": ["
" \"expected\": [\"string\"], \"actual\": \"integer\"" " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
" }}," " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
" { \"allOf\": {" " ]"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\"," "}");
" \"errors\": ["
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\""
" }}, "
" { \"enum\": {"
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
"}} ] }} ] }}");
} }
TEST(SchemaValidator, EscapedPointer) { TEST(SchemaValidator, EscapedPointer) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment