Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
c34e3dfc
Commit
c34e3dfc
authored
Jul 13, 2017
by
Milo Yip
Committed by
GitHub
Jul 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1018 from miloyip/issue1017_allOfHandler
Fix #1017 allOf keyword fail with Writer handler
parents
1a77513e
fcd2e1f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
18 deletions
+27
-18
schema.h
include/rapidjson/schema.h
+8
-18
schematest.cpp
test/unittest/schematest.cpp
+19
-0
No files found.
include/rapidjson/schema.h
View file @
c34e3dfc
...
...
@@ -1594,7 +1594,7 @@ public:
ownStateAllocator_
(
0
),
schemaStack_
(
allocator
,
schemaStackCapacity
),
documentStack_
(
allocator
,
documentStackCapacity
),
outputHandler_
(
CreateNullHandler
()
),
outputHandler_
(
0
),
valid_
(
true
)
#if RAPIDJSON_SCHEMA_VERBOSE
,
depth_
(
0
)
...
...
@@ -1622,8 +1622,7 @@ public:
ownStateAllocator_
(
0
),
schemaStack_
(
allocator
,
schemaStackCapacity
),
documentStack_
(
allocator
,
documentStackCapacity
),
outputHandler_
(
outputHandler
),
nullHandler_
(
0
),
outputHandler_
(
&
outputHandler
),
valid_
(
true
)
#if RAPIDJSON_SCHEMA_VERBOSE
,
depth_
(
0
)
...
...
@@ -1634,10 +1633,6 @@ public:
//! Destructor.
~
GenericSchemaValidator
()
{
Reset
();
if
(
nullHandler_
)
{
nullHandler_
->~
OutputHandler
();
StateAllocator
::
Free
(
nullHandler_
);
}
RAPIDJSON_DELETE
(
ownStateAllocator_
);
}
...
...
@@ -1699,7 +1694,7 @@ RAPIDJSON_MULTILINEMACRO_END
}
#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)\
return valid_ = EndValue() &&
outputHandler_.method arg2
return valid_ = EndValue() &&
(!outputHandler_ || outputHandler_->method arg2)
#define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \
RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);\
...
...
@@ -1721,7 +1716,7 @@ RAPIDJSON_MULTILINEMACRO_END
bool
StartObject
()
{
RAPIDJSON_SCHEMA_HANDLE_BEGIN_
(
StartObject
,
(
CurrentContext
()));
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_
(
StartObject
,
());
return
valid_
=
outputHandler_
.
StartObject
();
return
valid_
=
!
outputHandler_
||
outputHandler_
->
StartObject
();
}
bool
Key
(
const
Ch
*
str
,
SizeType
len
,
bool
copy
)
{
...
...
@@ -1729,7 +1724,7 @@ RAPIDJSON_MULTILINEMACRO_END
AppendToken
(
str
,
len
);
if
(
!
CurrentSchema
().
Key
(
CurrentContext
(),
str
,
len
,
copy
))
return
valid_
=
false
;
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_
(
Key
,
(
str
,
len
,
copy
));
return
valid_
=
outputHandler_
.
Key
(
str
,
len
,
copy
);
return
valid_
=
!
outputHandler_
||
outputHandler_
->
Key
(
str
,
len
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
)
{
...
...
@@ -1742,7 +1737,7 @@ RAPIDJSON_MULTILINEMACRO_END
bool
StartArray
()
{
RAPIDJSON_SCHEMA_HANDLE_BEGIN_
(
StartArray
,
(
CurrentContext
()));
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_
(
StartArray
,
());
return
valid_
=
outputHandler_
.
StartArray
();
return
valid_
=
!
outputHandler_
||
outputHandler_
->
StartArray
();
}
bool
EndArray
(
SizeType
elementCount
)
{
...
...
@@ -1815,7 +1810,7 @@ private:
ownStateAllocator_
(
0
),
schemaStack_
(
allocator
,
schemaStackCapacity
),
documentStack_
(
allocator
,
documentStackCapacity
),
outputHandler_
(
CreateNullHandler
()
),
outputHandler_
(
0
),
valid_
(
true
)
#if RAPIDJSON_SCHEMA_VERBOSE
,
depth_
(
depth
)
...
...
@@ -1929,10 +1924,6 @@ private:
Context
&
CurrentContext
()
{
return
*
schemaStack_
.
template
Top
<
Context
>
();
}
const
Context
&
CurrentContext
()
const
{
return
*
schemaStack_
.
template
Top
<
Context
>
();
}
OutputHandler
&
CreateNullHandler
()
{
return
*
(
nullHandler_
=
new
(
GetStateAllocator
().
Malloc
(
sizeof
(
OutputHandler
)))
OutputHandler
);
}
static
const
size_t
kDefaultSchemaStackCapacity
=
1024
;
static
const
size_t
kDefaultDocumentStackCapacity
=
256
;
const
SchemaDocumentType
*
schemaDocument_
;
...
...
@@ -1941,8 +1932,7 @@ private:
StateAllocator
*
ownStateAllocator_
;
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)
OutputHandler
&
outputHandler_
;
OutputHandler
*
nullHandler_
;
OutputHandler
*
outputHandler_
;
bool
valid_
;
#if RAPIDJSON_SCHEMA_VERBOSE
unsigned
depth_
;
...
...
test/unittest/schematest.cpp
View file @
c34e3dfc
...
...
@@ -1329,6 +1329,25 @@ TEST(SchemaValidator, Issue825) {
VALIDATE
(
s
,
"{
\"
item
\"
:
\"
hello
\"
}"
,
true
);
}
TEST
(
SchemaValidator
,
Issue1017_allOfHandler
)
{
Document
sd
;
sd
.
Parse
(
"{
\"
allOf
\"
: [{
\"
type
\"
:
\"
object
\"
,
\"
properties
\"
: {
\"
cyanArray2
\"
: {
\"
type
\"
:
\"
array
\"
,
\"
items
\"
: {
\"
type
\"
:
\"
string
\"
}}}},{
\"
type
\"
:
\"
object
\"
,
\"
properties
\"
: {
\"
blackArray
\"
: {
\"
type
\"
:
\"
array
\"
,
\"
items
\"
: {
\"
type
\"
:
\"
string
\"
}}},
\"
required
\"
: [
\"
blackArray
\"
]}]}"
);
SchemaDocument
s
(
sd
);
StringBuffer
sb
;
Writer
<
StringBuffer
>
writer
(
sb
);
GenericSchemaValidator
<
SchemaDocument
,
Writer
<
StringBuffer
>
>
validator
(
s
,
writer
);
EXPECT_TRUE
(
validator
.
StartObject
());
EXPECT_TRUE
(
validator
.
Key
(
"cyanArray2"
,
10
,
false
));
EXPECT_TRUE
(
validator
.
StartArray
());
EXPECT_TRUE
(
validator
.
EndArray
(
0
));
EXPECT_TRUE
(
validator
.
Key
(
"blackArray"
,
10
,
false
));
EXPECT_TRUE
(
validator
.
StartArray
());
EXPECT_TRUE
(
validator
.
EndArray
(
0
));
EXPECT_TRUE
(
validator
.
EndObject
(
0
));
EXPECT_TRUE
(
validator
.
IsValid
());
EXPECT_STREQ
(
"{
\"
cyanArray2
\"
:[],
\"
blackArray
\"
:[]}"
,
sb
.
GetString
());
}
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment