15 #ifndef RAPIDJSON_SCHEMA_H_
16 #define RAPIDJSON_SCHEMA_H_
25 #if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX)
26 #define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1
29 #if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) || \
30 !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
31 #define RAPIDJSON_SCHEMA_USE_STDREGEX 0
34 #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
36 #elif RAPIDJSON_SCHEMA_USE_STDREGEX
40 #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX || RAPIDJSON_SCHEMA_USE_STDREGEX
41 #define RAPIDJSON_SCHEMA_HAS_REGEX 1
43 #define RAPIDJSON_SCHEMA_HAS_REGEX 0
46 #ifndef RAPIDJSON_SCHEMA_VERBOSE
47 #define RAPIDJSON_SCHEMA_VERBOSE 0
53 RAPIDJSON_DIAG_OFF(effc++)
57 RAPIDJSON_DIAG_OFF(weak - vtables)
58 RAPIDJSON_DIAG_OFF(exit - time - destructors)
59 RAPIDJSON_DIAG_OFF(c++ 98 - compat - pedantic)
60 RAPIDJSON_DIAG_OFF(variadic - macros)
61 #elif defined(_MSC_VER)
62 RAPIDJSON_DIAG_OFF(4512)
70 #if RAPIDJSON_SCHEMA_VERBOSE
74 inline void PrintInvalidKeywordData(
const char* keyword)
76 printf(
" Fail keyword: '%s'\n", keyword);
79 inline void PrintInvalidKeywordData(
const wchar_t* keyword)
81 wprintf(L
" Fail keyword: '%ls'\n", keyword);
84 inline void PrintInvalidDocumentData(
const char* document)
86 printf(
" Fail document: '%s'\n", document);
89 inline void PrintInvalidDocumentData(
const wchar_t* document)
91 wprintf(L
" Fail document: '%ls'\n", document);
94 inline void PrintValidatorPointersData(
const char* s,
const char* d,
unsigned depth)
96 printf(
" Sch: %*s'%s'\n Doc: %*s'%s'\n",
depth * 4,
" ", s,
depth * 4,
" ", d);
99 inline void PrintValidatorPointersData(
const wchar_t* s,
const wchar_t* d,
unsigned depth)
101 wprintf(L
" Sch: %*ls'%ls'\n Doc: %*ls'%ls'\n",
depth * 4, L
" ", s,
depth * 4, L
" ", d);
104 inline void PrintSchemaIdsData(
const char* base,
const char* local,
const char* resolved)
106 printf(
" Resolving id: Base: '%s', Local: '%s', Resolved: '%s'\n", base, local, resolved);
109 inline void PrintSchemaIdsData(
const wchar_t* base,
const wchar_t* local,
const wchar_t* resolved)
112 L
" Resolving id: Base: '%ls', Local: '%ls', Resolved: '%ls'\n", base, local, resolved);
115 inline void PrintMethodData(
const char* method) { printf(
"%s\n", method); }
117 inline void PrintMethodData(
const char* method,
bool b)
119 printf(
"%s, Data: '%s'\n", method, b ?
"true" :
"false");
122 inline void PrintMethodData(
const char* method,
int64_t i)
124 printf(
"%s, Data: '%" PRId64 "'\n", method, i);
127 inline void PrintMethodData(
const char* method,
uint64_t u)
129 printf(
"%s, Data: '%" PRIu64 "'\n", method, u);
132 inline void PrintMethodData(
const char* method,
double d)
134 printf(
"%s, Data: '%lf'\n", method, d);
137 inline void PrintMethodData(
const char* method,
const char* s)
139 printf(
"%s, Data: '%s'\n", method, s);
142 inline void PrintMethodData(
const char* method,
const wchar_t* s)
144 wprintf(L
"%hs, Data: '%ls'\n", method, s);
147 inline void PrintMethodData(
const char* method,
const char* s1,
const char* s2)
149 printf(
"%s, Data: '%s', '%s'\n", method, s1, s2);
152 inline void PrintMethodData(
const char* method,
const wchar_t* s1,
const wchar_t* s2)
154 wprintf(L
"%hs, Data: '%ls', '%ls'\n", method, s1, s2);
161 #ifndef RAPIDJSON_SCHEMA_PRINT
162 #if RAPIDJSON_SCHEMA_VERBOSE
163 #define RAPIDJSON_SCHEMA_PRINT(name, ...) internal::Print##name##Data(__VA_ARGS__)
165 #define RAPIDJSON_SCHEMA_PRINT(name, ...)
172 #define RAPIDJSON_INVALID_KEYWORD_RETURN(code) \
173 RAPIDJSON_MULTILINEMACRO_BEGIN \
174 context.invalidCode = code; \
175 context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString(); \
176 RAPIDJSON_SCHEMA_PRINT(InvalidKeyword, context.invalidKeyword); \
178 RAPIDJSON_MULTILINEMACRO_END
189 #ifndef RAPIDJSON_VALIDATE_DEFAULT_FLAGS
190 #define RAPIDJSON_VALIDATE_DEFAULT_FLAGS kValidateNoFlags
260 template <
typename ValueType,
typename Allocator>
265 template <
typename SchemaDocumentType>
283 template <
typename SchemaType>
289 const bool inheritContinueOnErrors) = 0;
301 template <
typename SchemaType>
305 typedef typename SchemaType::Ch
Ch;
306 typedef typename SchemaType::SValue
SValue;
362 template <
typename Encoding,
typename Allocator>
366 typedef typename Encoding::Ch
Ch;
369 : stack_(allocator, stackCapacity)
379 n.d =
static_cast<double>(i);
380 return WriteNumber(n);
386 n.d =
static_cast<double>(u);
387 return WriteNumber(n);
393 n.d =
static_cast<double>(i);
394 return WriteNumber(n);
400 n.d =
static_cast<double>(u);
401 return WriteNumber(n);
407 n.u.i =
static_cast<int64_t>(d);
411 return WriteNumber(n);
431 uint64_t* kv = stack_.template Pop<uint64_t>(memberCount * 2);
432 for(
SizeType i = 0; i < memberCount; i++)
435 h ^= Hash(Hash(0, kv[i * 2]),
437 *stack_.template Push<uint64_t>() = h;
445 uint64_t* e = stack_.template Pop<uint64_t>(elementCount);
446 for(
SizeType i = 0; i < elementCount; i++)
448 *stack_.template Push<uint64_t>() = h;
457 return *stack_.template Top<uint64_t>();
461 static const size_t kDefaultSize = 256;
472 bool WriteType(
Type type) {
return WriteBuffer(type, 0, 0); }
474 bool WriteNumber(
const Number& n) {
return WriteBuffer(
kNumberType, &n,
sizeof(n)); }
476 bool WriteBuffer(
Type type,
const void* data,
size_t len)
480 const unsigned char* d =
static_cast<const unsigned char*
>(data);
481 for(
size_t i = 0; i < len; i++)
483 *stack_.template Push<uint64_t>() = h;
495 Stack<Allocator> stack_;
501 template <
typename SchemaDocumentType>
508 typedef typename ValueType::Ch
Ch;
603 template <
typename SchemaDocumentType>
607 typedef typename SchemaDocumentType::ValueType
ValueType;
611 typedef typename EncodingType::Ch
Ch;
619 Schema(SchemaDocumentType* schemaDocument,
630 typeless_(schemaDocument->GetTypeless()),
634 type_((1 << kTotalSchemaType) - 1),
667 p.StringifyUriFragment(sb);
670 typedef typename ValueType::ConstValueIterator ConstValueIterator;
671 typedef typename ValueType::ConstMemberIterator ConstMemberIterator;
679 typedef typename SchemaDocumentType::SchemaEntry SchemaEntry;
680 SchemaEntry* entry = schemaDocument->schemaMap_.template Push<SchemaEntry>();
682 schemaDocument->AddSchemaRefs(
this);
685 if(!
value.IsObject())
707 else if(
v->IsArray())
708 for(ConstValueIterator itr =
v->Begin(); itr !=
v->End(); ++itr)
714 if(
v->IsArray() &&
v->Size() > 0)
717 for(ConstValueIterator itr =
v->Begin(); itr !=
v->End(); ++itr)
720 char buffer[256u + 24];
722 EnumHasherType h(&hasherAllocator, 256);
740 schemaDocument->CreateSchema(
756 if(properties && properties->IsObject())
757 for(ConstMemberIterator itr = properties->MemberBegin();
758 itr != properties->MemberEnd();
762 if(required && required->IsArray())
763 for(ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
769 if(dependencies && dependencies->IsObject())
770 for(ConstMemberIterator itr = dependencies->MemberBegin();
771 itr != dependencies->MemberEnd();
775 if(itr->value.IsArray())
776 for(ConstValueIterator
i = itr->value.Begin();
i != itr->value.End();
782 if(allProperties.Size() > 0)
796 if(properties && properties->IsObject())
799 for(ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd();
821 for(ConstMemberIterator itr =
v->MemberBegin(); itr !=
v->MemberEnd(); ++itr)
836 if(required && required->IsArray())
837 for(ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
850 if(dependencies && dependencies->IsObject())
854 for(ConstMemberIterator itr = dependencies->MemberBegin();
855 itr != dependencies->MemberEnd();
861 if(itr->value.IsArray())
868 for(ConstValueIterator targetItr = itr->value.Begin();
869 targetItr != itr->value.End();
877 else if(itr->value.IsObject())
880 schemaDocument->CreateSchema(
897 else if(
v->IsObject())
899 p.Append(GetAdditionalPropertiesString(),
allocator_),
914 else if(
v->IsArray())
919 for(ConstValueIterator itr =
v->Begin(); itr !=
v->End(); ++itr, index++)
937 else if(
v->IsObject())
967 if(
v->IsNumber() &&
v->GetDouble() > 0.0)
1011 #if RAPIDJSON_SCHEMA_HAS_REGEX
1071 bool otherValid =
false;
1076 bool patternValid =
true;
1080 patternValid =
false;
1095 if(!patternValid || !otherValid)
1102 else if(!patternValid && !otherValid)
1146 bool oneValid =
false;
1182 if(!(
type_ & (1 << kNullSchemaType)))
1233 if(!(
type_ & (1 << kNumberSchemaType)))
1254 if(!(
type_ & (1 << kStringSchemaType)))
1263 if(internal::CountStringCodePoint<EncodingType>(str, length, &count))
1290 if(!(
type_ & (1 << kObjectSchemaType)))
1391 if(
properties_[index].schema->defaultValueLength_ == 0)
1421 if(
source.dependencies[targetIndex] &&
1427 else if(
source.dependenciesSchema)
1431 if(!dependenciesValidator->
IsValid())
1433 dependenciesValidator);
1450 if(!(
type_ & (1 << kArraySchemaType)))
1481 switch(validateErrorCode)
1517 default:
return GetNullString();
1522 #define RAPIDJSON_STRING_(name, ...) \
1523 static const ValueType& Get##name##String() \
1525 static const Ch s[] = {__VA_ARGS__, '\0'}; \
1526 static const ValueType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1)); \
1543 RAPIDJSON_STRING_(Properties, '
p', '
r', '
o', '
p', '
e', '
r', '
t', '
i', '
e', '
s')
1545 RAPIDJSON_STRING_(Dependencies, '
d', '
e', '
p', '
e', '
n', '
d', '
e', '
n', '
c', '
i', '
e', '
s')
1586 MinProperties, '
m', '
i', '
n', '
P', '
r', '
o', '
p', '
e', '
r', '
t', '
i', '
e', '
s')
1588 MaxProperties, '
m', '
a', '
x', '
P', '
r', '
o', '
p', '
e', '
r', '
t', '
i', '
e', '
s')
1593 AdditionalItems, '
a', '
d', '
d', '
i', '
t', '
i', '
o', '
n', '
a', '
l', 'I', '
t', '
e', '
m', '
s')
1594 RAPIDJSON_STRING_(UniqueItems, '
u', '
n', '
i', 'q', '
u', '
e', 'I', '
t', '
e', '
m', '
s')
1634 RAPIDJSON_STRING_(MultipleOf, '
m', '
u', '
l', '
t', '
i', '
p', '
l', '
e', 'O', 'f')
1645 #undef RAPIDJSON_STRING_
1648 enum SchemaValueType
1660 #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
1662 #elif RAPIDJSON_SCHEMA_USE_STDREGEX
1677 template <
typename V1,
typename V2>
1680 for(
typename V1::ConstValueIterator itr =
a.Begin(); itr !=
a.End(); ++itr)
1689 typename ValueType::ConstMemberIterator itr =
value.FindMember(name);
1690 return itr !=
value.MemberEnd() ? &(itr->value) : 0;
1703 if(
v->IsUint64() &&
v->GetUint64() <=
SizeType(~0))
1704 out =
static_cast<SizeType>(
v->GetUint64());
1708 SchemaDocumentType& schemaDocument,
1716 if(
v->IsArray() &&
v->Size() > 0)
1724 schemaDocument.CreateSchema(
1732 #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
1733 template <
typename ValueType>
1736 if(
value.IsString())
1742 sd->SchemaErrorValue(
1758 #elif RAPIDJSON_SCHEMA_USE_STDREGEX
1759 template <
typename ValueType>
1762 if(
value.IsString())
1768 std::size_t(
value.GetStringLength()),
1769 std::regex_constants::ECMAScript);
1771 catch(
const std::regex_error&
e)
1773 sd->SchemaErrorValue(
1783 std::match_results<const Ch*>
r;
1784 return std::regex_search(str, str + length,
r, *pattern);
1787 template <
typename ValueType>
1798 if(type == GetNullString())
1799 type_ |= 1 << kNullSchemaType;
1800 else if(type == GetBooleanString())
1801 type_ |= 1 << kBooleanSchemaType;
1802 else if(type == GetObjectString())
1803 type_ |= 1 << kObjectSchemaType;
1804 else if(type == GetArrayString())
1805 type_ |= 1 << kArraySchemaType;
1806 else if(type == GetStringString())
1807 type_ |= 1 << kStringSchemaType;
1808 else if(type == GetIntegerString())
1809 type_ |= 1 << kIntegerSchemaType;
1810 else if(type == GetNumberString())
1811 type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType);
1871 const bool inheritContinueOnErrors)
const
1881 SizeType len = name.GetStringLength();
1882 const Ch* str = name.GetString();
1884 if(
properties_[index].name.GetStringLength() == len &&
1895 if(!(
type_ & (1 << kBooleanSchemaType)))
1905 if(!(
type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType))))
1970 if(!(
type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType))))
2056 double a = std::abs(
d), b = std::abs(
multipleOf_.GetDouble());
2059 double scaledEpsilon = (q + qRounded) * std::numeric_limits<double>::epsilon();
2060 double difference = std::abs(qRounded - q);
2076 if(
type_ & (1 << kNullSchemaType))
2078 if(
type_ & (1 << kBooleanSchemaType))
2080 if(
type_ & (1 << kObjectSchemaType))
2082 if(
type_ & (1 << kArraySchemaType))
2084 if(
type_ & (1 << kStringSchemaType))
2087 if(
type_ & (1 << kNumberSchemaType))
2089 else if(
type_ & (1 << kIntegerSchemaType))
2183 template <
typename Stack,
typename Ch>
2188 *documentStack.template Push<Ch>() =
'/';
2190 size_t length =
static_cast<size_t>(
2192 for(
size_t i = 0; i < length; i++)
2193 *documentStack.template Push<Ch>() =
static_cast<Ch
>(buffer[i]);
2198 template <
typename Stack>
2205 char* buffer = documentStack.template Push<char>(1 + 10);
2208 documentStack.template Pop<char>(
static_cast<size_t>(10 - (end - buffer)));
2212 char* buffer = documentStack.template Push<char>(1 + 20);
2215 documentStack.template Pop<char>(
static_cast<size_t>(20 - (end - buffer)));
2225 template <
typename SchemaDocumentType>
2229 typedef typename SchemaDocumentType::Ch
Ch;
2235 virtual const SchemaDocumentType*
2258 template <
typename ValueT,
typename Allocator = CrtAllocator>
2267 typedef typename EncodingType::Ch
Ch;
2274 template <
typename,
typename,
typename>
2297 : remoteProvider_(remoteProvider),
2298 allocator_(allocator),
2302 schemaMap_(allocator, kInitialSchemaMapSize),
2303 schemaRef_(allocator, kInitialSchemaRefSize),
2313 uri_.SetString(uri ? uri : noUri, uriLength, *allocator_);
2314 docId_ =
UriType(uri_, allocator_);
2326 SetSchemaSpecification(document);
2332 if(
pointer.GetTokenCount() == 0)
2334 CreateSchemaRecursive(&root_,
pointer, document, document, docId_);
2338 CreateSchema(&root_,
pointer, *v, document, docId_);
2343 pointer.StringifyUriFragment(sb);
2352 schemaRef_.ShrinkToFit();
2355 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2358 : remoteProvider_(rhs.remoteProvider_),
2359 allocator_(rhs.allocator_),
2360 ownAllocator_(rhs.ownAllocator_),
2362 typeless_(rhs.typeless_),
2363 schemaMap_(std::move(rhs.schemaMap_)),
2364 schemaRef_(std::move(rhs.schemaRef_)),
2365 uri_(std::move(rhs.uri_)),
2366 docId_(std::move(rhs.docId_)),
2368 error_(std::move(rhs.error_)),
2369 currentError_(std::move(rhs.currentError_))
2371 rhs.remoteProvider_ = 0;
2373 rhs.ownAllocator_ = 0;
2381 while(!schemaMap_.Empty())
2382 schemaMap_.template Pop<SchemaEntry>(1)->~SchemaEntry();
2386 typeless_->~SchemaType();
2393 currentError_.SetNull();
2428 switch(schemaErrorCode)
2443 default:
return GetNullString();
2451 AddCurrentError(code, location);
2461 currentError_.AddMember(
2462 GetValueString(),
GValue(
value, length, *allocator_).Move(), *allocator_);
2463 AddCurrentError(code, location);
2474 currentError_.AddMember(
2475 GetValueString(),
GValue(
value, length, *allocator_).Move(), *allocator_);
2476 currentError_.AddMember(GetOffsetString(),
2479 AddCurrentError(code, location);
2493 :
pointer(p, allocator), schema(s), owned(o)
2500 schema->~SchemaType();
2512 location.StringifyUriFragment(sb);
2515 result.AddMember(GetInstanceRefString(), instanceRef, *allocator_);
2521 if(member == error_.MemberEnd())
2522 error_.AddMember(keyword, error, *allocator_);
2525 if(member->value.IsObject())
2528 errors.PushBack(member->value, *allocator_);
2529 member->value = errors;
2531 member->value.PushBack(error, *allocator_);
2538 currentError_.AddMember(GetErrorCodeString(), code, *allocator_);
2539 AddErrorInstanceLocation(currentError_, location);
2543 #define RAPIDJSON_STRING_(name, ...) \
2544 static const StringRefType& Get##name##String() \
2546 static const Ch s[] = {__VA_ARGS__, '\0'}; \
2547 static const StringRefType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1)); \
2551 RAPIDJSON_STRING_(InstanceRef,
'i',
'n',
's',
't',
'a',
'n',
'c',
'e',
'R',
'e',
'f')
2552 RAPIDJSON_STRING_(ErrorCode, 'e', 'r', 'r', 'o', 'r', 'C', 'o', 'd', 'e')
2553 RAPIDJSON_STRING_(
Value, 'v', 'a', 'l', 'u', 'e')
2554 RAPIDJSON_STRING_(Offset, 'o', 'f', 'f', 's', 'e', 't')
2556 RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l')
2557 RAPIDJSON_STRING_(SpecUnknown, 'S', 'p', 'e', 'c', 'U', 'n', 'k', 'n', 'o', 'w', 'n')
2559 SpecUnsupported, 'S', 'p', 'e', 'c', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd')
2560 RAPIDJSON_STRING_(SpecIllegal, 'S', 'p', 'e', 'c', 'I', 'l', 'l', 'e', 'g', 'a', 'l')
2561 RAPIDJSON_STRING_(StartUnknown, 'S', 't', 'a', 'r', 't', 'U', 'n', 'k', 'n', 'o', 'w', 'n')
2562 RAPIDJSON_STRING_(RefPlainName, 'R', 'e', 'f', 'P', 'l', 'a', 'i', 'n', 'N', 'a', 'm', 'e')
2563 RAPIDJSON_STRING_(RefInvalid, 'R', 'e', 'f', 'I', 'n', 'v', 'a', 'l', 'i', 'd')
2564 RAPIDJSON_STRING_(RefPointerInvalid,
2582 RAPIDJSON_STRING_(RefUnknown, 'R', 'e', 'f', 'U', 'n', 'k', 'n', 'o', 'w', 'n')
2583 RAPIDJSON_STRING_(RefCyclical, 'R', 'e', 'f', 'C', 'y', 'c', 'l', 'i', 'c', 'a', 'l')
2584 RAPIDJSON_STRING_(RefNoRemoteProvider,
2604 RAPIDJSON_STRING_(RefNoRemoteSchema,
2622 RAPIDJSON_STRING_(ReadOnlyAndWriteOnly,
2643 RAPIDJSON_STRING_(RegexInvalid, 'R', 'e', 'g', 'e', 'x', 'I', 'n', 'v', 'a', 'l', 'i', 'd')
2645 #undef RAPIDJSON_STRING_
2650 static const Ch kDraft03String[] = {
'h',
't',
't',
'p',
':',
'/',
'/',
'j',
's',
'o',
2651 'n',
'-',
's',
'c',
'h',
'e',
'm',
'a',
'.',
'o',
2652 'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'-',
'0',
2653 '3',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'#',
'\0'};
2654 static const Ch kDraft04String[] = {
'h',
't',
't',
'p',
':',
'/',
'/',
'j',
's',
'o',
2655 'n',
'-',
's',
'c',
'h',
'e',
'm',
'a',
'.',
'o',
2656 'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'-',
'0',
2657 '4',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'#',
'\0'};
2658 static const Ch kDraft05String[] = {
'h',
't',
't',
'p',
':',
'/',
'/',
'j',
's',
'o',
2659 'n',
'-',
's',
'c',
'h',
'e',
'm',
'a',
'.',
'o',
2660 'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'-',
'0',
2661 '5',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'#',
'\0'};
2662 static const Ch kDraft06String[] = {
'h',
't',
't',
'p',
':',
'/',
'/',
'j',
's',
'o',
2663 'n',
'-',
's',
'c',
'h',
'e',
'm',
'a',
'.',
'o',
2664 'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'-',
'0',
2665 '6',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'#',
'\0'};
2666 static const Ch kDraft07String[] = {
'h',
't',
't',
'p',
':',
'/',
'/',
'j',
's',
'o',
2667 'n',
'-',
's',
'c',
'h',
'e',
'm',
'a',
'.',
'o',
2668 'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'-',
'0',
2669 '7',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'#',
'\0'};
2670 static const Ch kDraft2019_09String[] = {
2671 'h',
't',
't',
'p',
's',
':',
'/',
'/',
'j',
's',
'o',
'n',
'-',
's',
'c',
2672 'h',
'e',
'm',
'a',
'.',
'o',
'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'/',
2673 '2',
'0',
'1',
'9',
'-',
'0',
'9',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'\0'};
2674 static const Ch kDraft2020_12String[] = {
2675 'h',
't',
't',
'p',
's',
':',
'/',
'/',
'j',
's',
'o',
'n',
'-',
's',
'c',
2676 'h',
'e',
'm',
'a',
'.',
'o',
'r',
'g',
'/',
'd',
'r',
'a',
'f',
't',
'/',
2677 '2',
'0',
'2',
'0',
'-',
'1',
'2',
'/',
's',
'c',
'h',
'e',
'm',
'a',
'\0'};
2679 if(!document.IsObject())
2685 typename ValueType::ConstMemberIterator itr =
2686 document.FindMember(SchemaType::GetSchemaString());
2687 if(itr != document.MemberEnd())
2689 if(!itr->value.IsString())
2691 const UriType draftUri(itr->value);
2693 if(draftUri.Match(
UriType(kDraft04String),
false))
2695 if(draftUri.Match(
UriType(kDraft05String),
false))
2697 if(draftUri.Match(
UriType(kDraft06String),
false))
2699 if(draftUri.Match(
UriType(kDraft07String),
false))
2701 if(draftUri.Match(
UriType(kDraft03String),
false))
2703 if(draftUri.Match(
UriType(kDraft2019_09String),
false))
2705 if(draftUri.Match(
UriType(kDraft2020_12String),
false))
2716 static const Ch kVersion20String[] = {
'2',
'.',
'0',
'\0'};
2717 static const Ch kVersion30String[] = {
'3',
'.',
'0',
'.',
'\0'};
2718 static const Ch kVersion31String[] = {
'3',
'.',
'1',
'.',
'\0'};
2719 static SizeType len = internal::StrLen<Ch>(kVersion30String);
2721 if(!document.IsObject())
2727 typename ValueType::ConstMemberIterator itr =
2728 document.FindMember(SchemaType::GetSwaggerString());
2729 if(itr == document.MemberEnd())
2730 itr = document.FindMember(SchemaType::GetOpenApiString());
2731 if(itr != document.MemberEnd())
2733 if(!itr->value.IsString())
2735 const ValueType kVersion20Value(kVersion20String);
2736 if(kVersion20Value == itr->value)
2738 const ValueType kVersion30Value(kVersion30String);
2739 if(itr->value.GetStringLength() > len &&
2740 kVersion30Value ==
ValueType(itr->value.GetString(), len))
2742 const ValueType kVersion31Value(kVersion31String);
2743 if(itr->value.GetStringLength() > len &&
2744 kVersion31Value ==
ValueType(itr->value.GetString(), len))
2755 void SetSchemaSpecification(
const ValueType& document)
2776 void CreateSchemaRecursive(
const SchemaType** schema,
2786 for(
typename ValueType::ConstMemberIterator itr = v.MemberBegin(); itr != v.MemberEnd();
2788 CreateSchemaRecursive(
2789 0,
pointer.Append(itr->name, allocator_), itr->value, document, newid);
2792 for(
SizeType i = 0; i < v.Size(); i++)
2793 CreateSchemaRecursive(0,
pointer.Append(i, allocator_), v[i], document,
id);
2805 pointer.StringifyUriFragment(sb);
2807 Method,
"GenericSchemaDocument::CreateSchema", sb.
GetString(),
id.GetString());
2816 else if(!HandleRefSchema(
pointer, schema, v, document,
id))
2829 *schema = typeless_;
2830 AddSchemaRefs(typeless_);
2843 typename ValueType::ConstMemberIterator itr = v.FindMember(SchemaType::GetRefString());
2844 if(itr == v.MemberEnd())
2848 source.StringifyUriFragment(sb);
2850 Method,
"GenericSchemaDocument::HandleRefSchema", sb.
GetString(),
id.GetString());
2852 new(schemaRef_.template Push<SchemaRefPtr>()) SchemaRefPtr(&
source);
2854 if(itr->value.IsString())
2856 SizeType len = itr->value.GetStringLength();
2863 UriType ref =
UriType(itr->value, allocator_).Resolve(scopeId, allocator_);
2865 SchemaIds,
id.GetString(), itr->value.GetString(), ref.GetString());
2870 const ValueType* base = FindId(document, ref, basePointer, docId_,
false);
2874 if(!remoteProvider_)
2881 const Ch* s = ref.GetFragString();
2882 len = ref.GetFragStringLength();
2883 if(len <= 1 || s[1] ==
'/')
2904 ref.GetStringLength());
2915 ref.GetStringLength());
2920 const Ch* s = ref.GetFragString();
2921 len = ref.GetFragStringLength();
2922 if(len <= 1 || s[1] ==
'/')
2926 if(!relPointer.IsValid())
2932 if(
const ValueType* pv = relPointer.Get(*base))
2936 for(
SizeType i = 0; i < relPointer.GetTokenCount(); i++)
2942 ref.GetStringLength());
2948 size_t unresolvedTokenIndex;
2950 document, docId_, &unresolvedTokenIndex, allocator_);
2951 CreateSchema(schema,
pointer, *pv, document, scopeId);
2959 ref.GetStringLength());
2972 else if(
const ValueType* pv = FindId(*base,
2976 ref.GetBaseStringLength(),
2985 ref.GetStringLength());
2991 size_t unresolvedTokenIndex;
2993 document, docId_, &unresolvedTokenIndex, allocator_);
2994 CreateSchema(schema,
pointer, *pv, document, scopeId);
3002 ref.GetStringLength());
3010 *schema = typeless_;
3011 AddSchemaRefs(typeless_);
3033 typename ValueType::ConstMemberIterator m = doc.FindMember(SchemaType::GetIdString());
3034 if(m != doc.MemberEnd() && m->value.GetType() ==
kStringType)
3036 localuri =
UriType(m->value, allocator_).Resolve(baseuri, allocator_);
3039 if(localuri.Match(finduri, full))
3042 "GenericSchemaDocument::FindId (match)",
3043 full ? localuri.GetString() : localuri.GetBaseString());
3049 for(m = doc.MemberBegin(); m != doc.MemberEnd(); ++m)
3059 here.Append(m->name.GetString(), m->name.GetStringLength(), allocator_));
3068 for(
typename ValueType::ConstValueIterator v = doc.Begin(); v != doc.End(); ++v)
3073 FindId(*v, finduri, resptr, localuri, full, here.Append(i, allocator_));
3087 while(!schemaRef_.Empty())
3089 SchemaRefPtr* ref = schemaRef_.template Pop<SchemaRefPtr>(1);
3090 SchemaEntry* entry = schemaMap_.template Push<SchemaEntry>();
3091 new(entry) SchemaEntry(**ref, schema,
false, allocator_);
3098 for(
const SchemaRefPtr* ref = schemaRef_.template Bottom<SchemaRefPtr>();
3099 ref != schemaRef_.template End<SchemaRefPtr>();
3108 for(
const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>();
3109 target != schemaMap_.template End<SchemaEntry>();
3111 if(
pointer == target->pointer)
3112 return target->schema;
3118 for(
const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>();
3119 target != schemaMap_.template End<SchemaEntry>();
3121 if(schema == target->schema)
3122 return target->pointer;
3126 const SchemaType* GetTypeless()
const {
return typeless_; }
3128 static const size_t kInitialSchemaMapSize = 64;
3129 static const size_t kInitialSchemaRefSize = 64;
3165 template <
typename SchemaDocumentType,
3166 typename OutputHandler =
3179 typedef typename EncodingType::Ch
Ch;
3191 StateAllocator* allocator = 0,
3192 size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
3193 size_t documentStackCapacity = kDefaultDocumentStackCapacity)
3194 : schemaDocument_(&schemaDocument),
3195 root_(schemaDocument.GetRoot()),
3196 stateAllocator_(allocator),
3197 ownStateAllocator_(0),
3198 schemaStack_(allocator, schemaStackCapacity),
3199 documentStack_(allocator, documentStackCapacity),
3203 missingDependents_(),
3219 OutputHandler& outputHandler,
3220 StateAllocator* allocator = 0,
3221 size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
3222 size_t documentStackCapacity = kDefaultDocumentStackCapacity)
3223 : schemaDocument_(&schemaDocument),
3224 root_(schemaDocument.GetRoot()),
3225 stateAllocator_(allocator),
3226 ownStateAllocator_(0),
3227 schemaStack_(allocator, schemaStackCapacity),
3228 documentStack_(allocator, documentStackCapacity),
3229 outputHandler_(&outputHandler),
3232 missingDependents_(),
3238 "GenericSchemaValidator::GenericSchemaValidator (output handler)");
3251 while(!schemaStack_.Empty())
3253 documentStack_.Clear();
3261 currentError_.SetNull();
3262 missingDependents_.SetNull();
3274 if(GetContinueOnErrors() && !error_.ObjectEmpty())
3288 return schemaStack_.Empty() ?
PointerType() : CurrentSchema().GetPointer();
3295 if(!schemaStack_.Empty())
3296 return CurrentContext().invalidKeyword;
3297 if(GetContinueOnErrors() && !error_.ObjectEmpty())
3298 return static_cast<const Ch*
>(GetErrorsString());
3306 if(!schemaStack_.Empty())
3307 return CurrentContext().invalidCode;
3308 if(GetContinueOnErrors() && !error_.ObjectEmpty())
3317 if(documentStack_.Empty())
3323 return PointerType(documentStack_.template Bottom<Ch>(),
3324 documentStack_.GetSize() /
sizeof(
Ch));
3345 exclusive ? &SchemaType::GetExclusiveMaximumString : 0);
3352 exclusive ? &SchemaType::GetExclusiveMaximumString : 0);
3359 exclusive ? &SchemaType::GetExclusiveMaximumString : 0);
3366 exclusive ? &SchemaType::GetExclusiveMinimumString : 0);
3373 exclusive ? &SchemaType::GetExclusiveMinimumString : 0);
3380 exclusive ? &SchemaType::GetExclusiveMinimumString : 0);
3386 ValueType(str, length, GetStateAllocator()).Move(),
3387 SValue(expected).Move());
3392 ValueType(str, length, GetStateAllocator()).Move(),
3393 SValue(expected).Move());
3397 currentError_.SetObject();
3398 currentError_.AddMember(GetActualString(),
3399 ValueType(str, length, GetStateAllocator()).Move(),
3400 GetStateAllocator());
3406 currentError_.SetObject();
3407 currentError_.AddMember(
3408 GetDisallowedString(),
ValueType(index).Move(), GetStateAllocator());
3424 duplicates.PushBack(index1, GetStateAllocator());
3425 duplicates.PushBack(index2, GetStateAllocator());
3426 currentError_.SetObject();
3427 currentError_.AddMember(GetDuplicatesString(), duplicates, GetStateAllocator());
3435 SValue(expectedCount).Move());
3441 SValue(expectedCount).Move());
3446 currentError_.PushBack(
ValueType(name, GetStateAllocator()).Move(), GetStateAllocator());
3450 if(currentError_.Empty())
3453 error.AddMember(GetMissingString(), currentError_, GetStateAllocator());
3454 currentError_ = error;
3460 for(
SizeType i = 0; i < count; ++i)
3465 currentError_.SetObject();
3466 currentError_.AddMember(GetDisallowedString(),
3467 ValueType(name, length, GetStateAllocator()).Move(),
3468 GetStateAllocator());
3476 missingDependents_.PushBack(
ValueType(targetName, GetStateAllocator()).Move(),
3477 GetStateAllocator());
3481 if(!missingDependents_.Empty())
3486 error.AddMember(GetMissingString(), missingDependents_.Move(), GetStateAllocator());
3487 AddErrorCode(error, code);
3488 AddErrorInstanceLocation(error,
false);
3493 AddErrorSchemaLocation(error,
3494 schemaRef.Append(sourceName.GetString(),
3495 sourceName.GetStringLength(),
3499 ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator()).Move(),
3501 GetStateAllocator());
3502 currentError_.AddMember(
3503 ValueType(sourceName, GetStateAllocator()).Move(), wrapper, GetStateAllocator());
3508 currentError_.AddMember(
ValueType(sourceName, GetStateAllocator()).Move(),
3510 GetStateAllocator());
3514 if(currentError_.ObjectEmpty())
3517 error.AddMember(GetErrorsString(), currentError_, GetStateAllocator());
3518 currentError_ = error;
3525 currentError_.SetObject();
3526 AddCurrentError(code);
3531 currentError_.PushBack(
ValueType(expectedType, GetStateAllocator()).Move(),
3532 GetStateAllocator());
3537 error.AddMember(GetExpectedString(), currentError_, GetStateAllocator());
3538 error.AddMember(GetActualString(),
3539 ValueType(actualType, GetStateAllocator()).Move(),
3540 GetStateAllocator());
3541 currentError_ = error;
3564 matches.PushBack(index1, GetStateAllocator());
3565 matches.PushBack(index2, GetStateAllocator());
3566 currentError_.SetObject();
3567 currentError_.AddMember(GetMatchesString(), matches, GetStateAllocator());
3572 currentError_.SetObject();
3577 currentError_.SetObject();
3582 currentError_.SetObject();
3586 #define RAPIDJSON_STRING_(name, ...) \
3587 static const StringRefType& Get##name##String() \
3589 static const Ch s[] = {__VA_ARGS__, '\0'}; \
3590 static const StringRefType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1)); \
3594 RAPIDJSON_STRING_(InstanceRef,
'i',
'n',
's',
't',
'a',
'n',
'c',
'e',
'R',
'e',
'f')
3598 RAPIDJSON_STRING_(
Disallowed, 'd', 'i', 's', '
a', 'l', 'l', 'o', 'w', 'e', 'd')
3602 RAPIDJSON_STRING_(ErrorMessage, 'e', 'r', 'r', 'o', 'r', 'M', 'e', 's', 's', '
a', 'g', 'e')
3603 RAPIDJSON_STRING_(Duplicates, 'd', 'u', 'p', 'l', 'i', 'c', '
a', 't', 'e', 's')
3606 #undef RAPIDJSON_STRING_
3608 #define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1) \
3611 if((!BeginValue() && !GetContinueOnErrors()) || \
3612 (!CurrentSchema().method arg1 && !GetContinueOnErrors())) \
3614 *documentStack_.template Push<Ch>() = '\0'; \
3615 documentStack_.template Pop<Ch>(1); \
3616 RAPIDJSON_SCHEMA_PRINT(InvalidDocument, documentStack_.template Bottom<Ch>()); \
3621 #define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2) \
3622 for(Context* context = schemaStack_.template Bottom<Context>(); \
3623 context != schemaStack_.template End<Context>(); \
3626 if(context->hasher) \
3627 static_cast<HasherType*>(context->hasher)->method arg2; \
3628 if(context->validators) \
3629 for(SizeType i_ = 0; i_ < context->validatorCount; i_++) \
3630 static_cast<GenericSchemaValidator*>(context->validators[i_])->method arg2; \
3631 if(context->patternPropertiesValidators) \
3632 for(SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++) \
3633 static_cast<GenericSchemaValidator*>(context->patternPropertiesValidators[i_]) \
3637 #define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2) \
3639 (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2); \
3642 #define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \
3643 RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1); \
3644 RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2); \
3645 RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)
3657 String, (CurrentContext(), str, length,
copy), (str, length,
copy));
3662 String, (CurrentContext(), str, length,
copy), (str, length,
copy));
3670 valid_ = !outputHandler_ || outputHandler_->StartObject();
3679 AppendToken(str, len);
3680 if(!CurrentSchema().
Key(CurrentContext(), str, len,
copy) && !GetContinueOnErrors())
3686 valid_ = !outputHandler_ || outputHandler_->Key(str, len,
copy);
3696 if(!CurrentSchema().
EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors())
3709 valid_ = !outputHandler_ || outputHandler_->StartArray();
3719 if(!CurrentSchema().
EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors())
3727 #undef RAPIDJSON_SCHEMA_HANDLE_BEGIN_
3728 #undef RAPIDJSON_SCHEMA_HANDLE_PARALLEL_
3729 #undef RAPIDJSON_SCHEMA_HANDLE_VALUE_
3733 const bool inheritContinueOnErrors)
3735 *documentStack_.template Push<Ch>() =
'\0';
3736 documentStack_.template Pop<Ch>(1);
3740 documentStack_.template Bottom<char>(),
3741 documentStack_.GetSize(),
3743 &GetStateAllocator());
3744 sv->SetValidateFlags(inheritContinueOnErrors
3775 virtual void*
MallocState(
size_t size) {
return GetStateAllocator().Malloc(size); }
3781 typedef typename SchemaType::Context Context;
3787 const char* basePath,
3788 size_t basePathSize,
3790 StateAllocator* allocator = 0,
3791 size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
3792 size_t documentStackCapacity = kDefaultDocumentStackCapacity)
3793 : schemaDocument_(&schemaDocument),
3795 stateAllocator_(allocator),
3796 ownStateAllocator_(0),
3797 schemaStack_(allocator, schemaStackCapacity),
3798 documentStack_(allocator, documentStackCapacity),
3802 missingDependents_(),
3808 "GenericSchemaValidator::GenericSchemaValidator (internal)",
3809 basePath && basePathSize ? basePath :
"");
3810 if(basePath && basePathSize)
3811 memcpy(documentStack_.template Push<char>(basePathSize), basePath, basePathSize);
3814 StateAllocator& GetStateAllocator()
3816 if(!stateAllocator_)
3817 stateAllocator_ = ownStateAllocator_ =
RAPIDJSON_NEW(StateAllocator)();
3818 return *stateAllocator_;
3826 if(schemaStack_.Empty())
3830 if(CurrentContext().inArray)
3832 documentStack_, CurrentContext().arrayElementIndex);
3834 if(!CurrentSchema().BeginValue(CurrentContext()) && !GetContinueOnErrors())
3837 SizeType count = CurrentContext().patternPropertiesSchemaCount;
3838 const SchemaType** sa = CurrentContext().patternPropertiesSchemas;
3839 typename Context::PatternValidatorType patternValidatorType =
3840 CurrentContext().valuePatternValidatorType;
3841 bool valueUniqueness = CurrentContext().valueUniqueness;
3843 PushSchema(*CurrentContext().valueSchema);
3847 CurrentContext().objectPatternValidatorType = patternValidatorType;
3848 ISchemaValidator**& va = CurrentContext().patternPropertiesValidators;
3849 SizeType& validatorCount = CurrentContext().patternPropertiesValidatorCount;
3851 static_cast<ISchemaValidator**
>(
MallocState(
sizeof(ISchemaValidator*) * count));
3852 std::memset(va, 0,
sizeof(ISchemaValidator*) * count);
3853 for(
SizeType i = 0; i < count; i++)
3854 va[validatorCount++] =
3858 CurrentContext().arrayUniqueness = valueUniqueness;
3866 if(!CurrentSchema().EndValue(CurrentContext()) && !GetContinueOnErrors())
3870 schemaDocument_->GetPointer(&CurrentSchema()).StringifyUriFragment(sb);
3871 *documentStack_.template Push<Ch>() =
'\0';
3872 documentStack_.template Pop<Ch>(1);
3874 ValidatorPointers, sb.
GetString(), documentStack_.template Bottom<Ch>(), depth_);
3875 void* hasher = CurrentContext().hasher;
3876 uint64_t h = hasher && CurrentContext().arrayUniqueness
3882 if(!schemaStack_.Empty())
3884 Context& context = CurrentContext();
3886 if(hasher && context.valueUniqueness)
3888 HashCodeArray*
a =
static_cast<HashCodeArray*
>(context.arrayElementHashCodes);
3890 CurrentContext().arrayElementHashCodes =
a =
3891 new(GetStateAllocator().Malloc(
sizeof(HashCodeArray)))
3895 if(itr->GetUint64() == h)
3899 if(GetContinueOnErrors())
3901 a->PushBack(h, GetStateAllocator());
3902 while(!documentStack_.Empty() &&
3903 *documentStack_.template Pop<Ch>(1) !=
'/')
3908 a->PushBack(h, GetStateAllocator());
3913 while(!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) !=
'/')
3919 void AppendToken(
const Ch* str,
SizeType len)
3921 documentStack_.template Reserve<Ch>(
3923 *documentStack_.template PushUnsafe<Ch>() =
'/';
3928 *documentStack_.template PushUnsafe<Ch>() =
'~';
3929 *documentStack_.template PushUnsafe<Ch>() =
'0';
3931 else if(str[i] ==
'/')
3933 *documentStack_.template PushUnsafe<Ch>() =
'~';
3934 *documentStack_.template PushUnsafe<Ch>() =
'1';
3937 *documentStack_.template PushUnsafe<Ch>() = str[i];
3941 RAPIDJSON_FORCEINLINE
void PushSchema(
const SchemaType& schema)
3943 new(schemaStack_.template Push<Context>()) Context(*
this, *
this, &schema, flags_);
3946 RAPIDJSON_FORCEINLINE
void PopSchema()
3948 Context* c = schemaStack_.template Pop<Context>(1);
3949 if(HashCodeArray*
a =
static_cast<HashCodeArray*
>(c->arrayElementHashCodes))
3951 a->~HashCodeArray();
3957 void AddErrorInstanceLocation(
ValueType& result,
bool parent)
3961 ((parent && instancePointer.GetTokenCount() > 0)
3962 ?
PointerType(instancePointer.GetTokens(), instancePointer.GetTokenCount() - 1)
3964 .StringifyUriFragment(sb);
3967 result.AddMember(GetInstanceRefString(), instanceRef, GetStateAllocator());
3973 SizeType len = CurrentSchema().GetURI().GetStringLength();
3975 memcpy(sb.
Push(len), CurrentSchema().GetURI().GetString(), len *
sizeof(
Ch));
3976 if(schema.GetTokenCount())
3977 schema.StringifyUriFragment(sb);
3982 result.AddMember(GetSchemaRefString(), schemaRef, GetStateAllocator());
3987 result.AddMember(GetErrorCodeString(), code, GetStateAllocator());
3993 if(member == error_.MemberEnd())
3994 error_.AddMember(keyword, error, GetStateAllocator());
3997 if(member->value.IsObject())
4000 errors.PushBack(member->value, GetStateAllocator());
4001 member->value = errors;
4003 member->value.PushBack(error, GetStateAllocator());
4009 AddErrorCode(currentError_, code);
4010 AddErrorInstanceLocation(currentError_, parent);
4011 AddErrorSchemaLocation(currentError_);
4013 ValueType(SchemaType::GetValidateErrorKeyword(code), GetStateAllocator(),
false).Move(),
4023 AddError(it->name, it->value);
4030 const typename SchemaType::ValueType& (*exclusive)() = 0)
4032 currentError_.SetObject();
4033 currentError_.AddMember(GetActualString(), actual, GetStateAllocator());
4034 currentError_.AddMember(GetExpectedString(),
4035 ValueType(expected, GetStateAllocator()).Move(),
4036 GetStateAllocator());
4038 currentError_.AddMember(
4039 ValueType(exclusive(), GetStateAllocator()).Move(),
true, GetStateAllocator());
4040 AddCurrentError(code);
4047 for(
SizeType i = 0; i < count; ++i)
4049 GetStateAllocator());
4050 currentError_.SetObject();
4051 currentError_.AddMember(GetErrorsString(), errors, GetStateAllocator());
4052 AddCurrentError(code);
4057 return *schemaStack_.template Top<Context>()->schema;
4059 Context& CurrentContext() {
return *schemaStack_.template Top<Context>(); }
4060 const Context& CurrentContext()
const {
return *schemaStack_.template Top<Context>(); }
4062 static const size_t kDefaultSchemaStackCapacity = 1024;
4063 static const size_t kDefaultDocumentStackCapacity = 256;
4064 const SchemaDocumentType* schemaDocument_;
4066 StateAllocator* stateAllocator_;
4067 StateAllocator* ownStateAllocator_;
4072 OutputHandler* outputHandler_;
4096 template <
unsigned parseFlags,
4097 typename InputStream,
4098 typename SourceEncoding,
4105 typedef typename InputStream::Ch
Ch;
4116 invalidSchemaKeyword_(),
4123 template <
typename Handler>
4129 parseResult_ = reader.template Parse<parseFlags>(is_, validator);
4131 isValid_ = validator.
IsValid();
4135 invalidSchemaKeyword_ = 0;
4145 error_.CopyFrom(validator.
GetError(), allocator_);
4148 return parseResult_;
4161 const SchemaDocumentType& sd_;
4165 const Ch* invalidSchemaKeyword_;
4168 StackAllocator allocator_;
void Free(A &a, T *p, size_t n=1)
Definition: allocators.h:485
C-runtime library allocator.
Definition: allocators.h:83
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:604
JSON schema document.
Definition: schema.h:2260
GenericSchemaDocument(const ValueType &document, const Ch *uri=0, SizeType uriLength=0, IRemoteSchemaDocumentProviderType *remoteProvider=0, Allocator *allocator=0, const PointerType &pointer=PointerType(), const Specification &spec=Specification(kDraft04))
Constructor.
Definition: schema.h:2290
const GValue & GetError() const
Definition: schema.h:2424
GValue & GetError()
Gets the error object.
Definition: schema.h:2423
const SchemaType & GetRoot() const
Get the root schema.
Definition: schema.h:2420
~GenericSchemaDocument()
Destructor.
Definition: schema.h:2379
GenericValue< EncodingType, AllocatorType > GValue
Definition: schema.h:2270
void SchemaError(const SchemaErrorCode code, const PointerType &location)
Default error method.
Definition: schema.h:2448
const Specification & GetSpecification() const
Definition: schema.h:2400
void SchemaErrorValue(const SchemaErrorCode code, const PointerType &location, const Ch *value, SizeType length)
Method for error with single string value insert.
Definition: schema.h:2455
static const Specification GetSpecification(const ValueType &document)
Static method to get the specification of any schema document.
Definition: schema.h:2405
const GValue & GetURI() const
Definition: schema.h:2398
IGenericRemoteSchemaDocumentProvider< GenericSchemaDocument > IRemoteSchemaDocumentProviderType
Definition: schema.h:2264
EncodingType::Ch Ch
Definition: schema.h:2267
static const StringRefType & GetSchemaErrorKeyword(SchemaErrorCode schemaErrorCode)
Definition: schema.h:2426
Allocator AllocatorType
Definition: schema.h:2265
internal::Schema< GenericSchemaDocument > SchemaType
Definition: schema.h:2268
ValueType::EncodingType EncodingType
Definition: schema.h:2266
bool IsSupportedSpecification() const
Definition: schema.h:2401
GenericStringRef< Ch > StringRefType
Definition: schema.h:2272
ValueT ValueType
Definition: schema.h:2262
GenericPointer< ValueType, Allocator > PointerType
Definition: schema.h:2269
GenericUri< ValueType, Allocator > UriType
Definition: schema.h:2271
void SchemaErrorPointer(const SchemaErrorCode code, const PointerType &location, const Ch *value, SizeType length, const PointerType &pointer)
Method for error with invalid pointer.
Definition: schema.h:2467
JSON Schema Validator.
Definition: schema.h:3173
virtual void DestroryHasher(void *hasher)
Definition: schema.h:3768
void BelowMinimum(int64_t actual, const SValue &expected, bool exclusive)
Definition: schema.h:3361
const ValueType & GetError() const
Definition: schema.h:3282
GenericSchemaValidator(const SchemaDocumentType &schemaDocument, StateAllocator *allocator=0, size_t schemaStackCapacity=kDefaultSchemaStackCapacity, size_t documentStackCapacity=kDefaultDocumentStackCapacity)
Constructor without output handler.
Definition: schema.h:3190
void TooLong(const Ch *str, SizeType length, SizeType expected)
Definition: schema.h:3383
void AddDependencySchemaError(const SValue &sourceName, ISchemaValidator *subvalidator)
Definition: schema.h:3506
void PropertyViolations(ISchemaValidator **subvalidators, SizeType count)
Definition: schema.h:3458
void DisallowedItem(SizeType index)
Definition: schema.h:3404
virtual unsigned GetValidateFlags() const
Definition: schema.h:3268
bool String(const Ch *str, SizeType length, bool copy)
Definition: schema.h:3659
SchemaType::SValue SValue
Definition: schema.h:3178
~GenericSchemaValidator()
Destructor.
Definition: schema.h:3242
void StartMissingProperties()
Definition: schema.h:3443
void NotAllOf(ISchemaValidator **subvalidators, SizeType count)
Definition: schema.h:3544
GenericValue< EncodingType, StateAllocator > ValueType
Definition: schema.h:3181
void DisallowedProperty(const Ch *name, SizeType length)
Definition: schema.h:3463
virtual ISchemaValidator * CreateSchemaValidator(const SchemaType &root, const bool inheritContinueOnErrors)
Definition: schema.h:3732
void Reset()
Reset the internal states.
Definition: schema.h:3249
void AboveMaximum(int64_t actual, const SValue &expected, bool exclusive)
Definition: schema.h:3340
virtual void FreeState(void *p)
Definition: schema.h:3777
void MultipleOneOf(SizeType index1, SizeType index2)
Definition: schema.h:3561
bool EndMissingProperties()
Definition: schema.h:3448
bool StartObject()
Definition: schema.h:3665
PointerType GetInvalidSchemaPointer() const
Gets the JSON pointer pointed to the invalid schema.
Definition: schema.h:3286
void NotMultipleOf(uint64_t actual, const SValue &expected)
Definition: schema.h:3332
GenericStringRef< Ch > StringRefType
Definition: schema.h:3180
bool EndArray(SizeType elementCount)
Definition: schema.h:3713
void AddExpectedType(const typename SchemaType::ValueType &expectedType)
Definition: schema.h:3529
bool Key(const Ch *str, SizeType len, bool copy)
Definition: schema.h:3674
bool Null()
Definition: schema.h:3647
void StartDependencyErrors()
Definition: schema.h:3472
void TooShort(const Ch *str, SizeType length, SizeType expected)
Definition: schema.h:3389
void TooManyItems(SizeType actualCount, SizeType expectedCount)
Definition: schema.h:3416
ValueType & GetError()
End of Implementation of ISchemaValidator.
Definition: schema.h:3281
virtual void * MallocState(size_t size)
Definition: schema.h:3775
void DuplicateItems(SizeType index1, SizeType index2)
Definition: schema.h:3421
void ResetError()
Reset the error state.
Definition: schema.h:3258
void AddMissingDependentProperty(const SValue &targetName)
Definition: schema.h:3474
EncodingType::Ch Ch
Definition: schema.h:3179
void AddMissingProperty(const SValue &name)
Definition: schema.h:3444
virtual bool IsValid() const
Definition: schema.h:3270
void AboveMaximum(uint64_t actual, const SValue &expected, bool exclusive)
Definition: schema.h:3347
void StartDisallowedType()
Definition: schema.h:3528
bool Bool(bool b)
Definition: schema.h:3648
void DisallowedWhenWriting()
Definition: schema.h:3575
bool Uint(unsigned u)
Definition: schema.h:3650
bool EndObject(SizeType memberCount)
Definition: schema.h:3690
void DisallowedWhenReading()
Definition: schema.h:3580
void NoneOf(ISchemaValidator **subvalidators, SizeType count)
Definition: schema.h:3553
void TooFewProperties(SizeType actualCount, SizeType expectedCount)
Definition: schema.h:3437
void NotMultipleOf(int64_t actual, const SValue &expected)
Definition: schema.h:3328
bool EndDependencyErrors()
Definition: schema.h:3512
const Ch * GetInvalidSchemaKeyword() const
Gets the keyword of invalid schema.
Definition: schema.h:3293
bool StartArray()
Definition: schema.h:3704
virtual void * CreateHasher()
Definition: schema.h:3758
void AboveMaximum(double actual, const SValue &expected, bool exclusive)
Definition: schema.h:3354
bool Uint64(uint64_t u)
Definition: schema.h:3652
virtual uint64_t GetHashCode(void *hasher)
Definition: schema.h:3763
PointerType GetInvalidDocumentPointer() const
Gets the JSON pointer pointed to the invalid value.
Definition: schema.h:3315
GenericSchemaValidator(const SchemaDocumentType &schemaDocument, OutputHandler &outputHandler, StateAllocator *allocator=0, size_t schemaStackCapacity=kDefaultSchemaStackCapacity, size_t documentStackCapacity=kDefaultDocumentStackCapacity)
Constructor with output handler.
Definition: schema.h:3218
void StartMissingDependentProperties()
Definition: schema.h:3473
bool Int64(int64_t i)
Definition: schema.h:3651
SchemaDocumentType::SchemaType SchemaType
Definition: schema.h:3175
void Disallowed()
Definition: schema.h:3570
SchemaType::EncodingType EncodingType
Definition: schema.h:3177
void BelowMinimum(uint64_t actual, const SValue &expected, bool exclusive)
Definition: schema.h:3368
void NotOneOf(ISchemaValidator **subvalidators, SizeType count)
Definition: schema.h:3557
void TooManyProperties(SizeType actualCount, SizeType expectedCount)
Definition: schema.h:3431
bool Int(int i)
Definition: schema.h:3649
SchemaDocumentType::PointerType PointerType
Definition: schema.h:3176
void EndDisallowedType(const typename SchemaType::ValueType &actualType)
Definition: schema.h:3534
virtual void DestroySchemaValidator(ISchemaValidator *validator)
Definition: schema.h:3751
bool RawNumber(const Ch *str, SizeType length, bool copy)
Definition: schema.h:3654
void NotMultipleOf(double actual, const SValue &expected)
Definition: schema.h:3336
ValidateErrorCode GetInvalidSchemaCode() const
Gets the error code of invalid schema.
Definition: schema.h:3304
bool Double(double d)
Definition: schema.h:3653
void DoesNotMatch(const Ch *str, SizeType length)
Definition: schema.h:3395
void TooFewItems(SizeType actualCount, SizeType expectedCount)
Definition: schema.h:3411
void SetValidateFlags(unsigned flags)
Implementation of ISchemaValidator.
Definition: schema.h:3267
void DisallowedValue(const ValidateErrorCode code=kValidateErrorEnum)
Definition: schema.h:3523
void EndMissingDependentProperties(const SValue &sourceName)
Definition: schema.h:3479
void BelowMinimum(double actual, const SValue &expected, bool exclusive)
Definition: schema.h:3375
Represents an in-memory output stream.
Definition: stringbuffer.h:42
Ch * Push(size_t count)
Definition: stringbuffer.h:75
size_t GetSize() const
Get the size of string in bytes in the string buffer.
Definition: stringbuffer.h:89
const Ch * GetString() const
Definition: stringbuffer.h:79
const Ch * GetString() const
Definition: uri.h:180
GenericUri Resolve(const GenericUri &baseuri, Allocator *allocator=0)
Resolve this URI against another (base) URI in accordance with URI resolution rules.
Definition: uri.h:259
SizeType GetBaseStringLength() const
Definition: uri.h:183
const Ch * GetBaseString() const
Definition: uri.h:182
GenericMemberIterator< false, EncodingType, AllocatorType >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:831
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:836
Definition: schema.h:2227
virtual const SchemaDocumentType * GetRemoteDocument(const GenericUri< ValueType, AllocatorType > uri, Specification &spec)
Definition: schema.h:2236
SchemaDocumentType::AllocatorType AllocatorType
Definition: schema.h:2231
virtual ~IGenericRemoteSchemaDocumentProvider()
Definition: schema.h:2233
virtual const SchemaDocumentType * GetRemoteDocument(const Ch *uri, SizeType length)=0
SchemaDocumentType::Ch Ch
Definition: schema.h:2229
SchemaDocumentType::ValueType ValueType
Definition: schema.h:2230
Default memory allocator used by the parser and DOM.
Definition: allocators.h:130
A helper class for parsing with validation.
Definition: schema.h:4102
SchemaDocumentType::PointerType PointerType
Definition: schema.h:4104
bool IsValid() const
Definition: schema.h:4152
const PointerType & GetInvalidDocumentPointer() const
Definition: schema.h:4155
ValidateErrorCode GetInvalidSchemaCode() const
Definition: schema.h:4157
InputStream::Ch Ch
Definition: schema.h:4105
bool operator()(Handler &handler)
Definition: schema.h:4124
const ValueType & GetError() const
Definition: schema.h:4156
const PointerType & GetInvalidSchemaPointer() const
Definition: schema.h:4153
const Ch * GetInvalidSchemaKeyword() const
Definition: schema.h:4154
const ParseResult & GetParseResult() const
Definition: schema.h:4151
SchemaValidatingReader(InputStream &is, const SchemaDocumentType &sd)
Constructor.
Definition: schema.h:4113
GenericValue< SourceEncoding, StackAllocator > ValueType
Definition: schema.h:4106
bool Search(InputStream &is)
Definition: regex.h:699
bool Bool(bool b)
Definition: schema.h:374
bool Uint64(uint64_t u)
Definition: schema.h:396
bool StartObject()
Definition: schema.h:426
bool Key(const Ch *str, SizeType len, bool copy)
Definition: schema.h:427
bool StartArray()
Definition: schema.h:441
Encoding::Ch Ch
Definition: schema.h:366
bool Uint(unsigned u)
Definition: schema.h:382
bool Null()
Definition: schema.h:373
bool EndObject(SizeType memberCount)
Definition: schema.h:428
Hasher(Allocator *allocator=0, size_t stackCapacity=kDefaultSize)
Definition: schema.h:368
bool Double(double d)
Definition: schema.h:403
bool String(const Ch *str, SizeType len, bool)
Definition: schema.h:420
bool Int(int i)
Definition: schema.h:375
uint64_t GetHashCode() const
Definition: schema.h:454
bool EndArray(SizeType elementCount)
Definition: schema.h:442
bool Int64(int64_t i)
Definition: schema.h:389
bool IsValid() const
Definition: schema.h:452
bool RawNumber(const Ch *str, SizeType len, bool)
Definition: schema.h:414
virtual void DestroySchemaValidator(ISchemaValidator *validator)=0
virtual void FreeState(void *p)=0
virtual void * CreateHasher()=0
virtual void DestroryHasher(void *hasher)=0
virtual ISchemaValidator * CreateSchemaValidator(const SchemaType &, const bool inheritContinueOnErrors)=0
virtual void * MallocState(size_t size)=0
virtual uint64_t GetHashCode(void *hasher)=0
virtual ~ISchemaStateFactory()
Definition: schema.h:287
virtual void SetValidateFlags(unsigned flags)=0
virtual bool IsValid() const =0
virtual unsigned GetValidateFlags() const =0
virtual ~ISchemaValidator()
Definition: schema.h:274
virtual void EndMissingDependentProperties(const SValue &sourceName)=0
virtual void DisallowedItem(SizeType index)=0
virtual void NotMultipleOf(int64_t actual, const SValue &expected)=0
virtual void DisallowedWhenWriting()=0
SchemaType::Ch Ch
Definition: schema.h:305
SchemaType::SValue SValue
Definition: schema.h:306
virtual void AddMissingDependentProperty(const SValue &targetName)=0
virtual void TooManyProperties(SizeType actualCount, SizeType expectedCount)=0
virtual bool EndMissingProperties()=0
virtual void DuplicateItems(SizeType index1, SizeType index2)=0
virtual void AddMissingProperty(const SValue &name)=0
virtual void NotAllOf(ISchemaValidator **subvalidators, SizeType count)=0
virtual void AddDependencySchemaError(const SValue &souceName, ISchemaValidator *subvalidator)=0
virtual void Disallowed()=0
virtual void TooShort(const Ch *str, SizeType length, SizeType expected)=0
virtual void BelowMinimum(int64_t actual, const SValue &expected, bool exclusive)=0
virtual void AboveMaximum(double actual, const SValue &expected, bool exclusive)=0
virtual void AddExpectedType(const typename SchemaType::ValueType &expectedType)=0
virtual void DisallowedValue(const ValidateErrorCode code)=0
virtual void DisallowedProperty(const Ch *name, SizeType length)=0
virtual void NoneOf(ISchemaValidator **subvalidators, SizeType count)=0
virtual void NotOneOf(ISchemaValidator **subvalidators, SizeType count)=0
virtual void AboveMaximum(uint64_t actual, const SValue &expected, bool exclusive)=0
virtual ~IValidationErrorHandler()
Definition: schema.h:308
virtual void AboveMaximum(int64_t actual, const SValue &expected, bool exclusive)=0
virtual bool EndDependencyErrors()=0
virtual void BelowMinimum(double actual, const SValue &expected, bool exclusive)=0
virtual void TooManyItems(SizeType actualCount, SizeType expectedCount)=0
virtual void DoesNotMatch(const Ch *str, SizeType length)=0
virtual void StartDisallowedType()=0
virtual void BelowMinimum(uint64_t actual, const SValue &expected, bool exclusive)=0
virtual void StartDependencyErrors()=0
virtual void PropertyViolations(ISchemaValidator **subvalidators, SizeType count)=0
virtual void StartMissingProperties()=0
virtual void DisallowedWhenReading()=0
virtual void EndDisallowedType(const typename SchemaType::ValueType &actualType)=0
virtual void NotMultipleOf(uint64_t actual, const SValue &expected)=0
virtual void NotMultipleOf(double actual, const SValue &expected)=0
virtual void TooFewProperties(SizeType actualCount, SizeType expectedCount)=0
virtual void TooLong(const Ch *str, SizeType length, SizeType expected)=0
virtual void StartMissingDependentProperties()=0
virtual void MultipleOneOf(SizeType index1, SizeType index2)=0
virtual void TooFewItems(SizeType actualCount, SizeType expectedCount)=0
bool Int64(Context &context, int64_t i) const
Definition: schema.h:1214
bool exclusiveMaximum_
Definition: schema.h:2174
SizeType notValidatorIndex_
Definition: schema.h:2143
bool StartArray(Context &context) const
Definition: schema.h:1444
bool CheckUint(Context &context, uint64_t i) const
Definition: schema.h:1968
bool nullable_
Definition: schema.h:2180
bool StartObject(Context &context) const
Definition: schema.h:1287
SchemaDocumentType::PointerType PointerType
Definition: schema.h:609
const UriType & GetId() const
Definition: schema.h:1022
bool additionalProperties_
Definition: schema.h:2152
bool exclusiveMinimum_
Definition: schema.h:2173
p
Definition: schema.h:1578
t
Definition: schema.h:1569
bool Int(Context &context, int i) const
Definition: schema.h:1198
bool Uint64(Context &context, uint64_t u) const
Definition: schema.h:1222
bool uniqueItems_
Definition: schema.h:2164
s x
Definition: schema.h:1588
SizeType maxLength_
Definition: schema.h:2168
bool FindPropertyIndex(const ValueType &name, SizeType *outIndex) const
Definition: schema.h:1879
d
Definition: schema.h:1566
AllocatorType * allocator_
Definition: schema.h:2129
static void AssignIfExist(SizeType &out, const ValueType &value, const ValueType &name)
Definition: schema.h:1700
IValidationErrorHandler< Schema > ErrorHandler
Definition: schema.h:615
RAPIDJSON_STRING_(PatternProperties, 'p', 'a', 't', 't', 'e', 'r', 'n', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's') RAPIDJSON_STRING_(AdditionalProperties
SizeType validatorCount_
Definition: schema.h:2142
bool readOnly_
Definition: schema.h:2178
SValue maximum_
Definition: schema.h:2171
bool CheckDoubleMultipleOf(Context &context, double d) const
Definition: schema.h:2054
i
Definition: schema.h:1568
n
Definition: schema.h:1572
const PointerType & GetPointer() const
Definition: schema.h:1026
SchemaArray oneOf_
Definition: schema.h:2139
GenericUri< ValueType, AllocatorType > UriType
Definition: schema.h:616
SizeType minItems_
Definition: schema.h:2161
s s m RAPIDJSON_STRING_(ExclusiveMaximum, 'e', 'x', 'c', 'l', 'u', 's', 'i', 'v', 'e', 'M', 'a', 'x', 'i', 'm', 'u', 'm') private typedef internal::GenericRegex< EncodingType, AllocatorType > RegexType
Definition: schema.h:1617
~Schema()
Definition: schema.h:995
static void AssignIfExist(bool &out, const ValueType &value, const ValueType &name)
Definition: schema.h:1693
void AddType(const ValueType &type)
Definition: schema.h:1796
const Specification & GetSpecification() const
Definition: schema.h:1024
s s v
Definition: schema.h:1608
bool additionalItems_
Definition: schema.h:2163
bool CheckDoubleMinimum(Context &context, double d) const
Definition: schema.h:2032
bool EndObject(Context &context, SizeType memberCount) const
Definition: schema.h:1383
static bool IsPatternMatch(const RegexType *pattern, const Ch *str, SizeType)
Definition: schema.h:1753
Specification spec_
Definition: schema.h:2132
SizeType maxProperties_
Definition: schema.h:2151
Property * properties_
Definition: schema.h:2145
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:2071
bool CheckInt(Context &context, int64_t i) const
Definition: schema.h:1903
s m
Definition: schema.h:1588
bool CheckBool(Context &context, bool) const
Definition: schema.h:1893
Schema(SchemaDocumentType *schemaDocument, const PointerType &p, const ValueType &value, const ValueType &document, AllocatorType *allocator, const UriType &id=UriType())
Definition: schema.h:619
const SchemaType * typeless_
Definition: schema.h:2134
SchemaDocumentType::AllocatorType AllocatorType
Definition: schema.h:608
bool EndArray(Context &context, SizeType elementCount) const
Definition: schema.h:1459
o
Definition: schema.h:1571
const SchemaType * additionalPropertiesSchema_
Definition: schema.h:2146
SizeType defaultValueLength_
Definition: schema.h:2176
bool Double(Context &context, double d) const
Definition: schema.h:1230
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1817
l
Definition: schema.h:1574
SchemaDocumentType::ValueType ValueType
Definition: schema.h:607
const SchemaType * additionalItemsSchema_
Definition: schema.h:2157
const SValue & GetURI() const
Definition: schema.h:1020
e
Definition: schema.h:1579
unsigned type_
Definition: schema.h:2141
bool String(Context &context, const Ch *str, SizeType length, bool) const
Definition: schema.h:1251
bool CheckDoubleMaximum(Context &context, double d) const
Definition: schema.h:2043
void AddUniqueElement(V1 &a, const V2 &v)
Definition: schema.h:1678
SizeType enumCount_
Definition: schema.h:2136
EncodingType::Ch Ch
Definition: schema.h:611
SValue minimum_
Definition: schema.h:2170
PatternProperty * patternProperties_
Definition: schema.h:2147
ValueType::EncodingType EncodingType
Definition: schema.h:610
SchemaArray allOf_
Definition: schema.h:2137
UriType id_
Definition: schema.h:2131
a
Definition: schema.h:1565
s s s
Definition: schema.h:1606
SizeType minProperties_
Definition: schema.h:2150
RegexType * CreatePattern(const ValueType &value, SchemaDocumentType *sd, const PointerType &p)
Definition: schema.h:1734
bool hasSchemaDependencies_
Definition: schema.h:2155
GenericValue< EncodingType, AllocatorType > SValue
Definition: schema.h:614
const SchemaType ** itemsTuple_
Definition: schema.h:2159
const SchemaType * not_
Definition: schema.h:2140
void CreateSchemaValidators(Context &context, const SchemaArray &schemas, const bool inheritContinueOnErrors) const
Definition: schema.h:1869
SizeType minLength_
Definition: schema.h:2167
s s M
Definition: schema.h:1610
s s u
Definition: schema.h:1605
bool Uint(Context &context, unsigned u) const
Definition: schema.h:1206
bool Key(Context &context, const Ch *str, SizeType len, bool) const
Definition: schema.h:1315
PointerType pointer_
Definition: schema.h:2133
SizeType maxItems_
Definition: schema.h:2162
Schema< SchemaDocumentType > SchemaType
Definition: schema.h:613
static const ValueType & GetValidateErrorKeyword(ValidateErrorCode validateErrorCode)
Definition: schema.h:1479
SchemaValidationContext< SchemaDocumentType > Context
Definition: schema.h:612
s s c
Definition: schema.h:1603
SValue uri_
Definition: schema.h:2130
bool Null(Context &context) const
Definition: schema.h:1179
SizeType itemsTupleCount_
Definition: schema.h:2160
SizeType patternPropertyCount_
Definition: schema.h:2148
bool hasRequired_
Definition: schema.h:2154
SizeType propertyCount_
Definition: schema.h:2149
RegexType * pattern_
Definition: schema.h:2166
bool Bool(Context &context, bool b) const
Definition: schema.h:1190
bool hasDependencies_
Definition: schema.h:2153
bool BeginValue(Context &context) const
Definition: schema.h:1028
uint64_t * enum_
Definition: schema.h:2135
r
Definition: schema.h:1576
P
Definition: schema.h:1575
static const ValueType * GetMember(const ValueType &value, const ValueType &name)
Definition: schema.h:1687
void AssignIfExist(SchemaArray &out, SchemaDocumentType &schemaDocument, const PointerType &p, const ValueType &value, const ValueType &name, const ValueType &document)
Definition: schema.h:1707
SValue multipleOf_
Definition: schema.h:2172
const SchemaType * itemsList_
Definition: schema.h:2158
RAPIDJSON_FORCEINLINE bool EndValue(Context &context) const
Definition: schema.h:1065
bool writeOnly_
Definition: schema.h:2179
SchemaArray anyOf_
Definition: schema.h:2138
A type-unsafe stack for storing different types of data.
Definition: stack.h:38
Concept for allocating, resizing and freeing memory block.
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_VALIDATE_DEFAULT_FLAGS
User-defined kValidateDefaultFlags definition.
Definition: schema.h:190
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
ValidateErrorCode
Error codes when validating.
Definition: error.h:173
SchemaErrorCode
Error codes when validating.
Definition: error.h:237
@ kValidateErrorMinProperties
Object has less members than 'minProperties' value.
Definition: error.h:194
@ kValidateErrorExclusiveMinimum
Number is less than or equal to the 'minimum' value.
Definition: error.h:181
@ kValidateErrorAdditionalItems
Definition: error.h:190
@ kValidateErrorMaxProperties
Object has more members than 'maxProperties' value.
Definition: error.h:193
@ kValidateErrorOneOfMatch
Definition: error.h:205
@ kValidateErrorRequired
Object is missing one or more members required by the schema.
Definition: error.h:195
@ kValidateErrorDependencies
Object has missing property or schema dependencies.
Definition: error.h:199
@ kValidateErrorUniqueItems
Array has duplicate items but 'uniqueItems' is true.
Definition: error.h:189
@ kValidateErrorReadOnly
Definition: error.h:211
@ kValidateErrorEnum
Property has a value that is not one of its allowed enumerated values.
Definition: error.h:201
@ kValidateErrorExclusiveMaximum
Number is greater than or equal to the 'maximum' value.
Definition: error.h:179
@ kValidateErrorType
Property has a type that is not allowed by the schema.
Definition: error.h:202
@ kValidateErrorOneOf
Property did not match any of the sub-schemas specified by 'oneOf'.
Definition: error.h:204
@ kValidateErrorMinLength
String is longer than the 'maxLength' value.
Definition: error.h:184
@ kValidateErrors
Top level error code when kValidateContinueOnErrorsFlag set.
Definition: error.h:174
@ kValidateErrorMaxLength
String is longer than the 'maxLength' value.
Definition: error.h:183
@ kValidateErrorWriteOnly
Definition: error.h:213
@ kValidateErrorAnyOf
Property did not match any of the sub-schemas specified by 'anyOf'.
Definition: error.h:208
@ kValidateErrorPattern
String does not match the 'pattern' regular expression.
Definition: error.h:185
@ kValidateErrorMaximum
Number is greater than the 'maximum' value.
Definition: error.h:178
@ kValidateErrorMaxItems
Array is longer than the 'maxItems' value.
Definition: error.h:187
@ kValidateErrorMinimum
Number is less than the 'minimum' value.
Definition: error.h:180
@ kValidateErrorMultipleOf
Number is not a multiple of the 'multipleOf' value.
Definition: error.h:177
@ kValidateErrorNone
No error.
Definition: error.h:175
@ kValidateErrorMinItems
Array is shorter than the 'minItems' value.
Definition: error.h:188
@ kValidateErrorNot
Property matched the sub-schema specified by 'not'.
Definition: error.h:209
@ kValidateErrorAdditionalProperties
Definition: error.h:196
@ kValidateErrorPatternProperties
See other errors.
Definition: error.h:198
@ kValidateErrorAllOf
Property did not match all of the sub-schemas specified by 'allOf'.
Definition: error.h:207
@ kSchemaErrorStartUnknown
Definition: error.h:240
@ kSchemaErrorSpecIllegal
Both JSON schema draft and OpenAPI version found in document.
Definition: error.h:253
@ kSchemaErrorSpecUnsupported
JSON schema draft or OpenAPI version is not supported.
Definition: error.h:252
@ kSchemaErrorRefPlainName
$ref fragment must be a JSON pointer
Definition: error.h:242
@ kSchemaErrorRefNoRemoteProvider
$ref is remote but there is no remote provider
Definition: error.h:247
@ kSchemaErrorSpecUnknown
JSON schema draft or OpenAPI version is not recognized.
Definition: error.h:251
@ kSchemaErrorRefUnknown
$ref does not resolve to a location in the target document
Definition: error.h:245
@ kSchemaErrorRefPointerInvalid
$ref fragment is not a valid JSON pointer at offset
Definition: error.h:244
@ kSchemaErrorRefNoRemoteSchema
Definition: error.h:248
@ kSchemaErrorRefCyclical
$ref is cyclical
Definition: error.h:246
@ kSchemaErrorRefInvalid
$ref must not be an empty string
Definition: error.h:243
@ kSchemaErrorRegexInvalid
Invalid regular expression in 'pattern' or 'patternProperties'.
Definition: error.h:250
@ kSchemaErrorReadOnlyAndWriteOnly
Property must not be both 'readOnly' and 'writeOnly'.
Definition: error.h:254
#define PRIu64
Definition: inttypes.h:143
#define PRId64
Definition: inttypes.h:89
__host__ constexpr __device__ auto depth(const Layout< Shape, UnrolledDescriptorType > &layout)
Get depth of the layout shape (return 0 if scalar).
Definition: layout_utils.hpp:371
__host__ T floor(T x)
Definition: math_v2.hpp:367
__host__ constexpr __device__ T min(T x)
Definition: math.hpp:116
auto copy(InputRange &&range, OutputIterator iter) -> decltype(std::copy(std::begin(std::forward< InputRange >(range)), std::end(std::forward< InputRange >(range)), iter))
Definition: algorithm.hpp:14
integral_constant< index_t, N > Number
Definition: number.hpp:12
Definition: allocators.h:459
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:41
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:135
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1697
#define RAPIDJSON_IF_CONSTEXPR
Definition: pointer.h:34
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1514
const CharType(& source)[N]
Definition: pointer.h:1559
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1517
Type
Type of JSON value.
Definition: rapidjson.h:760
@ kFalseType
false
Definition: rapidjson.h:762
@ kObjectType
object
Definition: rapidjson.h:764
@ kTrueType
true
Definition: rapidjson.h:763
@ kStringType
string
Definition: rapidjson.h:766
@ kNullType
null
Definition: rapidjson.h:761
@ kArrayType
array
Definition: rapidjson.h:765
@ kNumberType
number
Definition: rapidjson.h:767
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:746
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:429
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:326
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:742
GenericSchemaValidator< SchemaDocument > SchemaValidator
Definition: schema.h:4081
#define RAPIDJSON_SCHEMA_PRINT(name,...)
Definition: schema.h:165
#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)
Definition: schema.h:3608
ValidateFlag
Combination of validate flags.
Definition: schema.h:195
@ kValidateNoFlags
No flags are set.
Definition: schema.h:196
@ kValidateWriteFlag
Validation is for a write semantic.
Definition: schema.h:199
@ kValidateDefaultFlags
Definition: schema.h:200
@ kValidateReadFlag
Validation is for a read semantic.
Definition: schema.h:198
@ kValidateContinueOnErrorFlag
Don't stop after first validation error.
Definition: schema.h:197
GenericSchemaDocument< Value > SchemaDocument
GenericSchemaDocument using Value type.
Definition: schema.h:3146
#define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2)
Definition: schema.h:3642
SchemaDraft
Definition: schema.h:208
@ kDraftUnknown
Definition: schema.h:209
@ kDraft03
Definition: schema.h:211
@ kDraftNone
Definition: schema.h:210
@ kDraft2020_12
Definition: schema.h:219
@ kDraft07
Definition: schema.h:217
@ kDraft06
Definition: schema.h:216
@ kDraft2019_09
Definition: schema.h:218
@ kDraft04
Definition: schema.h:213
@ kDraftMin
Current minimum supported draft.
Definition: schema.h:212
@ kDraft05
Definition: schema.h:214
@ kDraftMax
Current maximum supported draft.
Definition: schema.h:215
#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)
Definition: schema.h:3637
#define RAPIDJSON_STRING_(name,...)
Definition: schema.h:3586
#define RAPIDJSON_INVALID_KEYWORD_RETURN(code)
Definition: schema.h:172
OpenApiVersion
Definition: schema.h:223
@ kVersionMax
Current maximum supported version.
Definition: schema.h:229
@ kVersion20
Definition: schema.h:227
@ kVersionMin
Current minimum supported version.
Definition: schema.h:226
@ kVersionUnknown
Definition: schema.h:224
@ kVersion30
Definition: schema.h:228
@ kVersion31
Definition: schema.h:230
@ kVersionNone
Definition: schema.h:225
#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)
Definition: schema.h:3621
IGenericRemoteSchemaDocumentProvider< SchemaDocument > IRemoteSchemaDocumentProvider
IGenericRemoteSchemaDocumentProvider using SchemaDocument.
Definition: schema.h:3148
signed __int64 int64_t
Definition: stdint.h:135
unsigned __int64 uint64_t
Definition: stdint.h:136
Reference to a constant string (not taking a copy)
Definition: document.h:417
Result of parsing (wraps ParseErrorCode)
Definition: error.h:108
Specification(OpenApiVersion o)
Definition: schema.h:236
SchemaDraft draft
Definition: schema.h:253
bool IsSupported() const
Definition: schema.h:248
OpenApiVersion oapi
Definition: schema.h:254
~Specification()
Definition: schema.h:247
Specification(SchemaDraft d)
Definition: schema.h:235
Definition: schema.h:2115
~PatternProperty()
Definition: schema.h:2117
RegexType * pattern
Definition: schema.h:2126
const SchemaType * schema
Definition: schema.h:2125
PatternProperty()
Definition: schema.h:2116
Definition: schema.h:2096
const SchemaType * dependenciesSchema
Definition: schema.h:2108
bool required
Definition: schema.h:2111
~Property()
Definition: schema.h:2105
const SchemaType * schema
Definition: schema.h:2107
SizeType dependenciesValidatorIndex
Definition: schema.h:2109
bool * dependencies
Definition: schema.h:2110
SValue name
Definition: schema.h:2106
Property()
Definition: schema.h:2097
Definition: schema.h:1669
SchemaArray()
Definition: schema.h:1670
const SchemaType ** schemas
Definition: schema.h:1672
~SchemaArray()
Definition: schema.h:1671
SizeType count
Definition: schema.h:1674
SizeType begin
Definition: schema.h:1673
bool arrayUniqueness
Definition: schema.h:597
SizeType validatorCount
Definition: schema.h:586
const SchemaType ** patternPropertiesSchemas
Definition: schema.h:589
ISchemaValidator ** validators
Definition: schema.h:585
SizeType arrayElementIndex
Definition: schema.h:593
bool valueUniqueness
Definition: schema.h:596
SizeType patternPropertiesValidatorCount
Definition: schema.h:588
ISchemaStateFactory< SchemaType > SchemaValidatorFactoryType
Definition: schema.h:505
const SchemaType * valueSchema
Definition: schema.h:580
bool * propertyExist
Definition: schema.h:594
void * hasher
Definition: schema.h:583
IValidationErrorHandler< SchemaType > ErrorHandlerType
Definition: schema.h:506
PatternValidatorType
Definition: schema.h:511
@ kPatternValidatorWithProperty
Definition: schema.h:513
@ kPatternValidatorWithAdditionalProperty
Definition: schema.h:514
@ kPatternValidatorOnly
Definition: schema.h:512
ValidateErrorCode invalidCode
Definition: schema.h:582
void * arrayElementHashCodes
Definition: schema.h:584
ISchemaValidator ** patternPropertiesValidators
Definition: schema.h:587
SizeType patternPropertiesSchemaCount
Definition: schema.h:590
Schema< SchemaDocumentType > SchemaType
Definition: schema.h:504
SchemaValidationContext(SchemaValidatorFactoryType &f, ErrorHandlerType &eh, const SchemaType *s, unsigned fl=0)
Definition: schema.h:517
const Ch * invalidKeyword
Definition: schema.h:581
~SchemaValidationContext()
Definition: schema.h:544
unsigned flags
Definition: schema.h:579
ValueType::Ch Ch
Definition: schema.h:508
SchemaType::ValueType ValueType
Definition: schema.h:507
PatternValidatorType valuePatternValidatorType
Definition: schema.h:591
ErrorHandlerType & error_handler
Definition: schema.h:577
PatternValidatorType objectPatternValidatorType
Definition: schema.h:592
SchemaValidatorFactoryType & factory
Definition: schema.h:576
bool inArray
Definition: schema.h:595
const SchemaType * schema
Definition: schema.h:578
static RAPIDJSON_FORCEINLINE void AppendIndexToken(Stack &documentStack, SizeType index)
Definition: schema.h:2201
Definition: schema.h:2185
static RAPIDJSON_FORCEINLINE void AppendIndexToken(Stack &documentStack, SizeType index)
Definition: schema.h:2186
int64_t i
Definition: schema.h:467
uint64_t u
Definition: schema.h:466