@@ -13,8 +13,17 @@ class AnnotationData
1313
1414 public string $ className ;
1515 public string $ methodName ;
16+ /**
17+ * @var AnnotationParameterData[]
18+ */
1619 public array $ pathParams ;
20+ /**
21+ * @var AnnotationParameterData[]
22+ */
1723 public array $ queryParams ;
24+ /**
25+ * @var AnnotationParameterData[]
26+ */
1827 public array $ bodyParams ;
1928 public ?string $ endpointDescription ;
2029
@@ -68,9 +77,26 @@ private function getBodyAnnotation(): string | null
6877 // only json is supported due to the media type
6978 $ head = '@OA\RequestBody(@OA\MediaType(mediaType="application/json",@OA\Schema ' ;
7079 $ body = new ParenthesesBuilder ();
80+ // list of all required properties
81+ $ required = [];
7182
7283 foreach ($ this ->bodyParams as $ bodyParam ) {
7384 $ body ->addValue ($ bodyParam ->toPropertyAnnotation ());
85+ if ($ bodyParam ->required ) {
86+ $ required [] = $ bodyParam ->name ;
87+ }
88+ }
89+
90+ // add a list of required properties
91+ if (count ($ required ) > 0 ) {
92+ // stringify the list (it has to be in '{"name1","name1",...}' format)
93+ $ requiredString = "{ " ;
94+ foreach ($ required as $ name ) {
95+ $ requiredString .= "\"$ name \", " ;
96+ }
97+ $ requiredString .= "} " ;
98+
99+ $ body ->addValue ("required= " . $ requiredString );
74100 }
75101
76102 return $ head . $ body ->toString () . ")) " ;
0 commit comments