@@ -18,6 +18,7 @@ class AnnotationParameterData
18
18
public bool $ nullable ;
19
19
public ?string $ example ;
20
20
public ?string $ nestedArraySwaggerType ;
21
+ public ?int $ arrayDepth ;
21
22
public ?array $ nestedObjectParameterData ;
22
23
public ?ParameterConstraints $ constraints ;
23
24
@@ -30,6 +31,7 @@ public function __construct(
30
31
bool $ nullable ,
31
32
?string $ example = null ,
32
33
?string $ nestedArraySwaggerType = null ,
34
+ ?int $ arrayDepth = null ,
33
35
?array $ nestedObjectParameterData = null ,
34
36
?ParameterConstraints $ constraints = null ,
35
37
) {
@@ -41,30 +43,54 @@ public function __construct(
41
43
$ this ->nullable = $ nullable ;
42
44
$ this ->example = $ example ;
43
45
$ this ->nestedArraySwaggerType = $ nestedArraySwaggerType ;
46
+ $ this ->arrayDepth = $ arrayDepth ;
44
47
$ this ->nestedObjectParameterData = $ nestedObjectParameterData ;
45
48
$ this ->constraints = $ constraints ;
46
49
}
47
50
48
51
private function addArrayItemsIfArray (ParenthesesBuilder $ container )
49
52
{
50
- ///TODO: nested constraints should be added here
51
53
if ($ this ->swaggerType !== "array " ) {
52
54
return ;
53
55
}
54
56
55
57
$ itemsHead = "@OA \\Items " ;
56
- $ items = new ParenthesesBuilder ();
58
+ $ layers = [];
59
+ for ($ i = 0 ; $ i < $ this ->arrayDepth ; $ i ++) {
60
+ $ items = new ParenthesesBuilder ();
61
+
62
+ // add array time for all nested arrays
63
+ if ($ i < $ this ->arrayDepth - 1 ) {
64
+ $ items ->addKeyValue ("type " , "array " );
65
+ // handle bottommost elements
66
+ } else {
67
+ // add element type if present
68
+ if ($ this ->nestedArraySwaggerType !== null ) {
69
+ $ items ->addKeyValue ("type " , $ this ->nestedArraySwaggerType );
70
+ }
71
+
72
+ // add example value
73
+ if ($ this ->example != null ) {
74
+ $ items ->addKeyValue ("example " , $ this ->example );
75
+ }
76
+
77
+ // add constraints
78
+ $ this ->constraints ?->addConstraints($ items );
79
+ }
57
80
58
- if ($ this ->nestedArraySwaggerType !== null ) {
59
- $ items ->addKeyValue ("type " , $ this ->nestedArraySwaggerType );
81
+ $ layers [] = $ items ;
60
82
}
61
83
62
- // add example value
63
- if ($ this ->example != null ) {
64
- $ items ->addKeyValue ("example " , $ this ->example );
84
+ // serialize the layers from the bottom up
85
+ $ layers = array_reverse ($ layers );
86
+ $ serialized_layer = $ itemsHead . $ layers [0 ]->toString ();
87
+ for ($ i = 1 ; $ i < $ this ->arrayDepth ; $ i ++) {
88
+ $ layer = $ layers [$ i ];
89
+ $ layer ->addValue ($ serialized_layer );
90
+ $ serialized_layer = $ itemsHead . $ layer ->toString ();
65
91
}
66
92
67
- $ container ->addValue ($ itemsHead . $ items -> toString () );
93
+ $ container ->addValue ($ serialized_layer );
68
94
}
69
95
70
96
private function addObjectParamsIfObject (ParenthesesBuilder $ container )
@@ -133,8 +159,10 @@ public function toPropertyAnnotation(): string
133
159
$ body ->addKeyValue ("description " , $ this ->description );
134
160
}
135
161
136
- // handle param constraints
137
- $ this ->constraints ?->addConstraints($ body );
162
+ // handle param constraints (array constrains have to be added to the element, not the array)
163
+ if ($ this ->swaggerType !== "array " ) {
164
+ $ this ->constraints ?->addConstraints($ body );
165
+ }
138
166
139
167
// handle arrays
140
168
$ this ->addArrayItemsIfArray ($ body );
0 commit comments