FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/archive/code/node_modules/ajv/lib/dotjs/oneOf.js at main · iu5git/JavaScript · GitHub
iu5git
/
JavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
21
Star
52
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
archive
/
code
/
node_modules
/
ajv
/
lib
/
dotjs
/
oneOf.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
73 lines (73 loc) · 3.11 KB
Breadcrumbs
JavaScript
/
archive
/
code
/
node_modules
/
ajv
/
lib
/
dotjs
/
oneOf.js
Copy path
File metadata and controls
executable file
·
73 lines (73 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
;
module
.
exports
=
function
generate_oneOf
(
it
,
$keyword
,
$ruleType
)
{
var
out
=
' '
;
var
$lvl
=
it
.
level
;
var
$dataLvl
=
it
.
dataLevel
;
var
$schema
=
it
.
schema
[
$keyword
]
;
var
$schemaPath
=
it
.
schemaPath
+
it
.
util
.
getProperty
(
$keyword
)
;
var
$errSchemaPath
=
it
.
errSchemaPath
+
'/'
+
$keyword
;
var
$breakOnError
=
!
it
.
opts
.
allErrors
;
var
$data
=
'data'
+
(
$dataLvl
||
''
)
;
var
$valid
=
'valid'
+
$lvl
;
var
$errs
=
'errs__'
+
$lvl
;
var
$it
=
it
.
util
.
copy
(
it
)
;
var
$closingBraces
=
''
;
$it
.
level
++
;
var
$nextValid
=
'valid'
+
$it
.
level
;
var
$currentBaseId
=
$it
.
baseId
,
$prevValid
=
'prevValid'
+
$lvl
,
$passingSchemas
=
'passingSchemas'
+
$lvl
;
out
+=
'var '
+
(
$errs
)
+
' = errors , '
+
(
$prevValid
)
+
' = false , '
+
(
$valid
)
+
' = false , '
+
(
$passingSchemas
)
+
' = null; '
;
var
$wasComposite
=
it
.
compositeRule
;
it
.
compositeRule
=
$it
.
compositeRule
=
true
;
var
arr1
=
$schema
;
if
(
arr1
)
{
var
$sch
,
$i
=
-
1
,
l1
=
arr1
.
length
-
1
;
while
(
$i
<
l1
)
{
$sch
=
arr1
[
$i
+=
1
]
;
if
(
(
it
.
opts
.
strictKeywords
?
(
typeof
$sch
==
'object'
&&
Object
.
keys
(
$sch
)
.
length
>
0
)
||
$sch
===
false
:
it
.
util
.
schemaHasRules
(
$sch
,
it
.
RULES
.
all
)
)
)
{
$it
.
schema
=
$sch
;
$it
.
schemaPath
=
$schemaPath
+
'['
+
$i
+
']'
;
$it
.
errSchemaPath
=
$errSchemaPath
+
'/'
+
$i
;
out
+=
' '
+
(
it
.
validate
(
$it
)
)
+
' '
;
$it
.
baseId
=
$currentBaseId
;
}
else
{
out
+=
' var '
+
(
$nextValid
)
+
' = true; '
;
}
if
(
$i
)
{
out
+=
' if ('
+
(
$nextValid
)
+
' && '
+
(
$prevValid
)
+
') { '
+
(
$valid
)
+
' = false; '
+
(
$passingSchemas
)
+
' = ['
+
(
$passingSchemas
)
+
', '
+
(
$i
)
+
']; } else { '
;
$closingBraces
+=
'}'
;
}
out
+=
' if ('
+
(
$nextValid
)
+
') { '
+
(
$valid
)
+
' = '
+
(
$prevValid
)
+
' = true; '
+
(
$passingSchemas
)
+
' = '
+
(
$i
)
+
'; }'
;
}
}
it
.
compositeRule
=
$it
.
compositeRule
=
$wasComposite
;
out
+=
''
+
(
$closingBraces
)
+
'if (!'
+
(
$valid
)
+
') { var err = '
;
/* istanbul ignore else */
if
(
it
.
createErrors
!==
false
)
{
out
+=
' { keyword: \''
+
(
'oneOf'
)
+
'\' , dataPath: (dataPath || \'\') + '
+
(
it
.
errorPath
)
+
' , schemaPath: '
+
(
it
.
util
.
toQuotedString
(
$errSchemaPath
)
)
+
' , params: { passingSchemas: '
+
(
$passingSchemas
)
+
' } '
;
if
(
it
.
opts
.
messages
!==
false
)
{
out
+=
' , message: \'should match exactly one schema in oneOf\' '
;
}
if
(
it
.
opts
.
verbose
)
{
out
+=
' , schema: validate.schema'
+
(
$schemaPath
)
+
' , parentSchema: validate.schema'
+
(
it
.
schemaPath
)
+
' , data: '
+
(
$data
)
+
' '
;
}
out
+=
' } '
;
}
else
{
out
+=
' {} '
;
}
out
+=
'; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '
;
if
(
!
it
.
compositeRule
&&
$breakOnError
)
{
/* istanbul ignore if */
if
(
it
.
async
)
{
out
+=
' throw new ValidationError(vErrors); '
;
}
else
{
out
+=
' validate.errors = vErrors; return false; '
;
}
}
out
+=
'} else { errors = '
+
(
$errs
)
+
'; if (vErrors !== null) { if ('
+
(
$errs
)
+
') vErrors.length = '
+
(
$errs
)
+
'; else vErrors = null; }'
;
if
(
it
.
opts
.
allErrors
)
{
out
+=
' } '
;
}
return
out
;
}
Back
|
FazBrowse Home
|
New Git URL