@@ -18,7 +18,9 @@ class AnnotationParameterData
1818 public bool $ nullable ;
1919 public ?string $ example ;
2020 public ?string $ nestedArraySwaggerType ;
21+ public ?int $ arrayDepth ;
2122 public ?array $ nestedObjectParameterData ;
23+ public ?ParameterConstraints $ constraints ;
2224
2325 public function __construct (
2426 string $ swaggerType ,
@@ -29,7 +31,9 @@ public function __construct(
2931 bool $ nullable ,
3032 ?string $ example = null ,
3133 ?string $ nestedArraySwaggerType = null ,
34+ ?int $ arrayDepth = null ,
3235 ?array $ nestedObjectParameterData = null ,
36+ ?ParameterConstraints $ constraints = null ,
3337 ) {
3438 $ this ->swaggerType = $ swaggerType ;
3539 $ this ->name = $ name ;
@@ -39,7 +43,9 @@ public function __construct(
3943 $ this ->nullable = $ nullable ;
4044 $ this ->example = $ example ;
4145 $ this ->nestedArraySwaggerType = $ nestedArraySwaggerType ;
46+ $ this ->arrayDepth = $ arrayDepth ;
4247 $ this ->nestedObjectParameterData = $ nestedObjectParameterData ;
48+ $ this ->constraints = $ constraints ;
4349 }
4450
4551 private function addArrayItemsIfArray (ParenthesesBuilder $ container )
@@ -49,18 +55,42 @@ private function addArrayItemsIfArray(ParenthesesBuilder $container)
4955 }
5056
5157 $ itemsHead = "@OA \\Items " ;
52- $ 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+ }
5380
54- if ($ this ->nestedArraySwaggerType !== null ) {
55- $ items ->addKeyValue ("type " , $ this ->nestedArraySwaggerType );
81+ $ layers [] = $ items ;
5682 }
5783
58- // add example value
59- if ($ this ->example != null ) {
60- $ 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 ();
6191 }
6292
63- $ container ->addValue ($ itemsHead . $ items -> toString () );
93+ $ container ->addValue ($ serialized_layer );
6494 }
6595
6696 private function addObjectParamsIfObject (ParenthesesBuilder $ container )
@@ -85,6 +115,7 @@ private function generateSchemaAnnotation(): string
85115 $ body = new ParenthesesBuilder ();
86116
87117 $ body ->addKeyValue ("type " , $ this ->swaggerType );
118+ $ body ->addKeyValue ("nullable " , $ this ->nullable );
88119 $ this ->addArrayItemsIfArray ($ body );
89120
90121 return $ head . $ body ->toString ();
@@ -128,6 +159,11 @@ public function toPropertyAnnotation(): string
128159 $ body ->addKeyValue ("description " , $ this ->description );
129160 }
130161
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+ }
166+
131167 // handle arrays
132168 $ this ->addArrayItemsIfArray ($ body );
133169
0 commit comments