@@ -388,12 +388,47 @@ public function split(): \stdClass
388388
389389 public function validate (): bool
390390 {
391- if ($ this ->openapi instanceof OA \OpenApi) {
392- return $ this ->openapi ->validate ();
391+ if (!$ this ->openapi instanceof OA \OpenApi) {
392+ $ this ->context ->logger ->warning ('No openapi target set. Run the MergeIntoOpenApi processor before validate() ' );
393+
394+ return false ;
395+ }
396+
397+ $ isValid = true ;
398+ $ version = $ this ->openapi ->openapi ;
399+ $ context = new \stdClass ();
400+
401+ foreach ($ this ->collectAnnotations ($ this ->openapi ) as $ annotation ) {
402+ $ isValid = $ annotation ->validate ($ this , $ version , $ context ) && $ isValid ;
393403 }
394404
395- $ this ->context ->logger ->warning ('No openapi target set. Run the MergeIntoOpenApi processor before validate() ' );
405+ return $ isValid ;
406+
407+ }
408+
409+ /**
410+ * @return array<OA\AbstractAnnotation>
411+ */
412+ protected function collectAnnotations (OA \AbstractAnnotation $ root ): array
413+ {
414+ $ annotations = [$ root ];
415+
416+ foreach (get_object_vars ($ root ) as $ field => $ value ) {
417+ if (null === $ value || Generator::isDefault ($ value ) || is_scalar ($ value ) || in_array ($ field , $ root ::$ _blacklist )) {
418+ continue ;
419+ }
396420
397- return false ;
421+ if ($ value instanceof OA \AbstractAnnotation) {
422+ $ annotations = array_merge ($ annotations , $ this ->collectAnnotations ($ value ));
423+ } elseif (is_array ($ value )) {
424+ foreach ($ value as $ item ) {
425+ if ($ item instanceof OA \AbstractAnnotation) {
426+ $ annotations = array_merge ($ annotations , $ this ->collectAnnotations ($ item ));
427+ }
428+ }
429+ }
430+ }
431+
432+ return $ annotations ;
398433 }
399434}
0 commit comments