validator: implement minProperties and maxProperties
This commit is contained in:
parent
e0a69cff39
commit
f59b151974
@ -84,9 +84,9 @@ int main(void)
|
|||||||
There is an application which can be used for testing the validator with the
|
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).
|
[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
|
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
|
# Additional features
|
||||||
|
|
||||||
|
|||||||
@ -185,8 +185,6 @@ class json_validator
|
|||||||
|
|
||||||
void validate_object(json &instance, const json &schema, const std::string &name)
|
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");
|
not_yet_implemented(schema, "dependencies", "object");
|
||||||
|
|
||||||
validate_type(schema, "object", name);
|
validate_type(schema, "object", name);
|
||||||
@ -212,6 +210,18 @@ class json_validator
|
|||||||
instance[it.key()] = default_value.value();
|
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
|
// additionalProperties
|
||||||
enum {
|
enum {
|
||||||
True,
|
True,
|
||||||
|
|||||||
16
test-schema.sh
Executable file
16
test-schema.sh
Executable file
@ -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
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user