Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
rjs_json_form
Commits
d74a7691
Commit
d74a7691
authored
Aug 31, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tv4: add contains support
parent
cb7128e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
10 deletions
+39
-10
jsonform/tv4.js
jsonform/tv4.js
+39
-10
No files found.
jsonform/tv4.js
View file @
d74a7691
...
...
@@ -533,6 +533,19 @@ ValidatorContext.prototype.reset = function () {
this
.
errors
=
[];
};
ValidatorContext
.
prototype
.
validateAllValidators
=
function
validateAllValidators
(
data
,
schema
,
dataPointerPath
)
{
return
this
.
validateBasic
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateNumeric
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateString
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateArray
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateObject
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateCombinations
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateHypermedia
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateFormat
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateDefinedKeywords
(
data
,
schema
,
dataPointerPath
)
||
null
;
};
ValidatorContext
.
prototype
.
validateAll
=
function
(
data
,
schema
,
dataPathParts
,
schemaPathParts
,
dataPointerPath
)
{
var
topLevel
;
if
(
schema
===
undefined
||
schema
===
true
)
{
...
...
@@ -597,16 +610,7 @@ ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts,
}
var
errorCount
=
this
.
errors
.
length
;
var
error
=
this
.
validateBasic
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateNumeric
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateString
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateArray
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateObject
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateCombinations
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateHypermedia
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateFormat
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateDefinedKeywords
(
data
,
schema
,
dataPointerPath
)
||
null
;
var
error
=
this
.
validateAllValidators
(
data
,
schema
,
dataPointerPath
);
if
(
topLevel
)
{
while
(
this
.
scanned
.
length
)
{
...
...
@@ -892,6 +896,7 @@ ValidatorContext.prototype.validateArray = function validateArray(data, schema,
}
return
this
.
validateArrayLength
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateArrayUniqueItems
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateArrayContains
(
data
,
schema
,
dataPointerPath
)
||
this
.
validateArrayItems
(
data
,
schema
,
dataPointerPath
)
||
null
;
};
...
...
@@ -917,6 +922,28 @@ ValidatorContext.prototype.validateArrayLength = function validateArrayLength(da
return
null
;
};
ValidatorContext
.
prototype
.
validateArrayContains
=
function
validateArrayContains
(
data
,
schema
,
dataPointerPath
)
{
if
((
schema
.
contains
===
true
&&
data
.
length
>
0
)
||
schema
.
contains
===
undefined
)
{
return
null
;
}
var
error
;
if
(
data
.
length
===
0
||
schema
.
contains
===
false
)
{
error
=
true
;
}
else
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
error
=
this
.
validateAllValidators
(
data
[
i
],
schema
.
contains
,
dataPointerPath
+
"
/
"
+
i
);
if
(
!
error
)
{
return
null
;
}
}
error
=
true
;
}
if
(
error
)
{
return
this
.
createError
(
ErrorCodes
.
ARRAY_CONTAINS
,
{},
''
,
'
/contains
'
,
null
,
data
,
schema
);
}
return
null
;
};
ValidatorContext
.
prototype
.
validateArrayUniqueItems
=
function
validateArrayUniqueItems
(
data
,
schema
)
{
if
(
schema
.
uniqueItems
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
...
...
@@ -1413,6 +1440,7 @@ var ErrorCodes = {
ARRAY_LENGTH_LONG
:
401
,
ARRAY_UNIQUE
:
402
,
ARRAY_ADDITIONAL_ITEMS
:
403
,
ARRAY_CONTAINS
:
404
,
// Custom/user-defined errors
FORMAT_CUSTOM
:
500
,
KEYWORD_CUSTOM
:
501
,
...
...
@@ -1456,6 +1484,7 @@ var ErrorMessagesDefault = {
ARRAY_LENGTH_LONG
:
"
Array is too long ({length}), maximum {maximum}
"
,
ARRAY_UNIQUE
:
"
Array items are not unique (indices {match1} and {match2})
"
,
ARRAY_ADDITIONAL_ITEMS
:
"
Additional items not allowed
"
,
ARRAY_CONTAINS
:
"
Array are not contain item matching schema.contains
"
,
// Format errors
FORMAT_CUSTOM
:
"
Format validation failed ({message})
"
,
KEYWORD_CUSTOM
:
"
Keyword failed: {key} ({message})
"
,
...
...
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