@@ -440,7 +440,8 @@ class Schema {
440
440
minLength_(0 ),
441
441
maxLength_(~SizeType (0 )),
442
442
exclusiveMinimum_(false ),
443
- exclusiveMaximum_(false )
443
+ exclusiveMaximum_(false ),
444
+ defaultValue_()
444
445
{
445
446
typedef typename SchemaDocumentType::ValueType ValueType;
446
447
typedef typename ValueType::ConstValueIterator ConstValueIterator;
@@ -635,6 +636,12 @@ class Schema {
635
636
if (const ValueType* v = GetMember (value, GetMultipleOfString ()))
636
637
if (v->IsNumber () && v->GetDouble () > 0.0 )
637
638
multipleOf_.CopyFrom (*v, *allocator_);
639
+
640
+ // Default
641
+ if (const ValueType* v = GetMember (value, GetDefaultValueString ()))
642
+ if (v->IsString ())
643
+ defaultValue_ = v->GetString ();
644
+
638
645
}
639
646
640
647
~Schema () {
@@ -935,8 +942,14 @@ class Schema {
935
942
if (hasRequired_) {
936
943
context.error_handler .StartMissingProperties ();
937
944
for (SizeType index = 0 ; index < propertyCount_; index++)
938
- if (properties_[index].required && !context.propertyExist [index])
939
- context.error_handler .AddMissingProperty (properties_[index].name );
945
+ if (properties_[index].required && !context.propertyExist [index]){
946
+ if (properties_[index].schema ->defaultValue_ .empty () || properties_[index].schema ->defaultValue_ == " " ){
947
+ context.error_handler .AddMissingProperty (properties_[index].name );
948
+ } else {
949
+ // std::cout << "default value of " << properties_[index].name.GetString()
950
+ // << " is:" << properties_[index].schema->defaultValue_ << "\n";
951
+ }
952
+ }
940
953
if (context.error_handler .EndMissingProperties ())
941
954
RAPIDJSON_INVALID_KEYWORD_RETURN (GetRequiredString ());
942
955
}
@@ -1046,6 +1059,7 @@ class Schema {
1046
1059
RAPIDJSON_STRING_(ExclusiveMinimum, ' e' , ' x' , ' c' , ' l' , ' u' , ' s' , ' i' , ' v' , ' e' , ' M' , ' i' , ' n' , ' i' , ' m' , ' u' , ' m' )
1047
1060
RAPIDJSON_STRING_(ExclusiveMaximum, ' e' , ' x' , ' c' , ' l' , ' u' , ' s' , ' i' , ' v' , ' e' , ' M' , ' a' , ' x' , ' i' , ' m' , ' u' , ' m' )
1048
1061
RAPIDJSON_STRING_(MultipleOf, ' m' , ' u' , ' l' , ' t' , ' i' , ' p' , ' l' , ' e' , ' O' , ' f' )
1062
+ RAPIDJSON_STRING_(DefaultValue, ' d' , ' e' , ' f' , ' a' , ' u' , ' l' , ' t' )
1049
1063
1050
1064
#undef RAPIDJSON_STRING_
1051
1065
@@ -1426,6 +1440,8 @@ class Schema {
1426
1440
SValue multipleOf_;
1427
1441
bool exclusiveMinimum_;
1428
1442
bool exclusiveMaximum_;
1443
+
1444
+ std::string defaultValue_;
1429
1445
};
1430
1446
1431
1447
template <typename Stack, typename Ch>
0 commit comments