diff --git a/README.md b/README.md index 6252603..7af94f8 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,9 @@ int main(void) There is an application which can be used for testing the validator with the [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). -Currently more 150 tests are still failing, because simply not all keyword and +Currently **145** tests are still failing, because simply not all keywords and their functionalities have been implemented. Some of the missing feature will -require a rework. +require a rework. Some will only work with external libraries. (remote references) # Additional features diff --git a/src/json-schema-validator.hpp b/src/json-schema-validator.hpp index f207b9e..f5b1746 100644 --- a/src/json-schema-validator.hpp +++ b/src/json-schema-validator.hpp @@ -185,8 +185,6 @@ class json_validator void validate_object(json &instance, const json &schema, const std::string &name) { - not_yet_implemented(schema, "maxProperties", "object"); - not_yet_implemented(schema, "minProperties", "object"); not_yet_implemented(schema, "dependencies", "object"); validate_type(schema, "object", name); @@ -212,6 +210,18 @@ class json_validator instance[it.key()] = default_value.value(); } + // maxProperties + const auto &maxProperties = schema.find("maxProperties"); + if (maxProperties != schema.end()) + if (instance.size() > maxProperties.value()) + throw std::out_of_range(name + " has too many properties."); + + // minProperties + const auto &minProperties = schema.find("minProperties"); + if (minProperties != schema.end()) + if (instance.size() < minProperties.value()) + throw std::out_of_range(name + " has too few properties."); + // additionalProperties enum { True, diff --git a/test-schema.sh b/test-schema.sh new file mode 100755 index 0000000..cec4a18 --- /dev/null +++ b/test-schema.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +PWD=$(realpath `dirname $0`/../JSON-Schema-Test-Suite/tests/draft4) + +TESTS=`find $PWD | grep json$` + +FAILCOUNT=0 + +for T in $TESTS +do + ./json-schema-test < $T + FAILCOUNT=$(($FAILCOUNT + $?)) +done + +echo $FAILCOUNT tests failed +