Add verbose output for schema diagnosis
This commit is contained in:
parent
84d74052c1
commit
d452a548b8
@ -35,14 +35,29 @@
|
|||||||
#define RAPIDJSON_SCHEMA_HAS_REGEX 0
|
#define RAPIDJSON_SCHEMA_HAS_REGEX 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
#define RAPIDJSON_SCHEMA_VERBOSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
#include "stringbuffer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
RAPIDJSON_DIAG_PUSH
|
RAPIDJSON_DIAG_PUSH
|
||||||
RAPIDJSON_DIAG_OFF(effc++)
|
RAPIDJSON_DIAG_OFF(effc++)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) printf("Fail: %s\n", keyword)
|
||||||
|
#else
|
||||||
|
#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)\
|
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)\
|
||||||
RAPIDJSON_MULTILINEMACRO_BEGIN\
|
RAPIDJSON_MULTILINEMACRO_BEGIN\
|
||||||
context.invalidKeyword = keyword;\
|
context.invalidKeyword = keyword;\
|
||||||
|
RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword);\
|
||||||
return false;\
|
return false;\
|
||||||
RAPIDJSON_MULTILINEMACRO_END
|
RAPIDJSON_MULTILINEMACRO_END
|
||||||
|
|
||||||
@ -1330,6 +1345,9 @@ public:
|
|||||||
schemaStack_(allocator, schemaStackCapacity),
|
schemaStack_(allocator, schemaStackCapacity),
|
||||||
documentStack_(allocator, documentStackCapacity),
|
documentStack_(allocator, documentStackCapacity),
|
||||||
valid_(true)
|
valid_(true)
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
, depth_(0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1346,6 +1364,9 @@ public:
|
|||||||
schemaStack_(allocator, schemaStackCapacity),
|
schemaStack_(allocator, schemaStackCapacity),
|
||||||
documentStack_(allocator, documentStackCapacity),
|
documentStack_(allocator, documentStackCapacity),
|
||||||
valid_(true)
|
valid_(true)
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
, depth_(0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1462,24 +1483,35 @@ public:
|
|||||||
|
|
||||||
// Implementation of ISchemaValidatorFactory<SchemaType>
|
// Implementation of ISchemaValidatorFactory<SchemaType>
|
||||||
virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root) const {
|
virtual ISchemaValidator* CreateSchemaValidator(const SchemaType& root) const {
|
||||||
return new GenericSchemaValidator(root);
|
return new GenericSchemaValidator(*schemaDocument_, root
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
, depth_ + 1
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef typename SchemaType::Context Context;
|
typedef typename SchemaType::Context Context;
|
||||||
|
|
||||||
GenericSchemaValidator(
|
GenericSchemaValidator(
|
||||||
|
const SchemaDocumentType& schemaDocument,
|
||||||
const SchemaType& root,
|
const SchemaType& root,
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
unsigned depth,
|
||||||
|
#endif
|
||||||
StateAllocator* allocator = 0,
|
StateAllocator* allocator = 0,
|
||||||
size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
|
size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
|
||||||
size_t documentStackCapacity = kDefaultDocumentStackCapacity)
|
size_t documentStackCapacity = kDefaultDocumentStackCapacity)
|
||||||
:
|
:
|
||||||
schemaDocument_(),
|
schemaDocument_(&schemaDocument),
|
||||||
root_(root),
|
root_(root),
|
||||||
outputHandler_(nullOutputHandler_),
|
outputHandler_(nullOutputHandler_),
|
||||||
schemaStack_(allocator, schemaStackCapacity),
|
schemaStack_(allocator, schemaStackCapacity),
|
||||||
documentStack_(allocator, documentStackCapacity),
|
documentStack_(allocator, documentStackCapacity),
|
||||||
valid_(true)
|
valid_(true)
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
, depth_(depth)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1517,6 +1549,16 @@ private:
|
|||||||
if (!CurrentSchema().EndValue(CurrentContext()))
|
if (!CurrentSchema().EndValue(CurrentContext()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
StringBuffer sb;
|
||||||
|
const PointerType pointer = schemaDocument_->GetPointer(&CurrentSchema());
|
||||||
|
pointer.Stringify(sb);
|
||||||
|
|
||||||
|
*documentStack_.template Push<Ch>() = '\0';
|
||||||
|
documentStack_.template Pop<Ch>(1);
|
||||||
|
printf("S: %*s%s\nD: %*s%s\n\n", depth_ * 4, " ", sb.GetString(), depth_ * 4, " ", documentStack_.template Bottom<Ch>());
|
||||||
|
#endif
|
||||||
|
|
||||||
uint64_t h = CurrentContext().arrayUniqueness ? CurrentContext().hasher->GetHashCode() : 0;
|
uint64_t h = CurrentContext().arrayUniqueness ? CurrentContext().hasher->GetHashCode() : 0;
|
||||||
|
|
||||||
PopSchema();
|
PopSchema();
|
||||||
@ -1531,9 +1573,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *documentStack_.template Push<Ch>() = '\0';
|
// Remove the last token of document pointer
|
||||||
// documentStack_.template Pop<Ch>(1);
|
|
||||||
// printf("document: %s\n", documentStack_.template Bottom<Ch>());
|
|
||||||
while (!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) != '/')
|
while (!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) != '/')
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1580,6 +1620,9 @@ private:
|
|||||||
internal::Stack<StateAllocator> schemaStack_; //!< stack to store the current path of schema (BaseSchemaType *)
|
internal::Stack<StateAllocator> schemaStack_; //!< stack to store the current path of schema (BaseSchemaType *)
|
||||||
internal::Stack<StateAllocator> documentStack_; //!< stack to store the current path of validating document (Ch)
|
internal::Stack<StateAllocator> documentStack_; //!< stack to store the current path of validating document (Ch)
|
||||||
bool valid_;
|
bool valid_;
|
||||||
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
|
unsigned depth_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef GenericSchemaValidator<SchemaDocument> SchemaValidator;
|
typedef GenericSchemaValidator<SchemaDocument> SchemaValidator;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user