File tree Expand file tree Collapse file tree 2 files changed +77
-1
lines changed Expand file tree Collapse file tree 2 files changed +77
-1
lines changed Original file line number Diff line number Diff line change @@ -222,9 +222,17 @@ private function processEnum($data, $path = '#')
222
222
{
223
223
$ enumOk = false ;
224
224
foreach ($ this ->enum as $ item ) {
225
- if ($ item === $ data ) { // todo support complex structures here
225
+ if ($ item === $ data ) {
226
226
$ enumOk = true ;
227
227
break ;
228
+ } else {
229
+ if (is_array ($ item ) || is_object ($ item )) {
230
+ $ diff = new JsonDiff ($ item , $ data , JsonDiff::STOP_ON_DIFF );
231
+ if ($ diff ->getDiffCnt () === 0 ) {
232
+ $ enumOk = true ;
233
+ break ;
234
+ }
235
+ }
228
236
}
229
237
}
230
238
if (!$ enumOk ) {
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "description" : " complex enum validation" ,
4
+ "schema" : {
5
+ "enum" : [
6
+ 6 ,
7
+ " foo" ,
8
+ [],
9
+ true ,
10
+ {
11
+ "foo" : 12
12
+ },
13
+ [{"one" : 1 ,"two" :2 }]
14
+ ]
15
+ },
16
+ "tests" : [
17
+ {
18
+ "description" : " one of the enum is valid" ,
19
+ "data" : [],
20
+ "valid" : true
21
+ },
22
+ {
23
+ "description" : " missing from enum is not valid" ,
24
+ "data" : [1 ,2 ],
25
+ "valid" : false
26
+ },
27
+ {
28
+ "description" : " something else is invalid" ,
29
+ "data" : null ,
30
+ "valid" : false
31
+ },
32
+ {
33
+ "description" : " objects are deep compared" ,
34
+ "data" : {
35
+ "foo" : false
36
+ },
37
+ "valid" : false
38
+ },
39
+ {
40
+ "description" : " objects are deep compared 2" ,
41
+ "data" : {
42
+ "foo" : 12
43
+ },
44
+ "valid" : true
45
+ },
46
+ {
47
+ "description" : " objects are deep compared 3" ,
48
+ "data" : [
49
+ {
50
+ "two" : 2 ,
51
+ "one" : 1
52
+ }
53
+ ],
54
+ "valid" : true
55
+ },
56
+ {
57
+ "description" : " objects are deep compared 4" ,
58
+ "data" : [
59
+ {
60
+ "one" : 1 ,
61
+ "two" : 2
62
+ }
63
+ ],
64
+ "valid" : true
65
+ }
66
+ ]
67
+ }
68
+ ]
You can’t perform that action at this time.
0 commit comments