Skip to content

Commit 038f82c

Browse files
committed
fix: protect OpenAPI generation
1 parent 258f80a commit 038f82c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/PHPDraft/Out/OpenAPI/OpenApiRenderer.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,25 +456,24 @@ private function getSchemaProperty(BasicStructureElement|ElementStructureElement
456456

457457
if ($value->type === 'enum') {
458458
$propery_data['type'] = in_array('nullable', $value->status, true) ? [ $value->type, 'null' ] : $value->type;
459-
$options = [];
459+
$options = [];
460+
if (!is_iterable($value->value)) {
461+
return $propery_data;
462+
}
460463
foreach ($value->value->value as $option) {
461464
if ($option instanceof ElementStructureElement) {
462-
$options[] = ['const' => $option->value, 'title' => $option->value];
465+
$options[] = [ 'const' => $option->value, 'title' => $option->value ];
463466
}
464467
}
465468
$propery_data['oneOf'] = $options;
466469

467470
return $propery_data;
468-
}
469-
470-
if ($value->type === 'array') {
471+
} elseif ($value->type === 'array') {
471472
$propery_data['type'] = array_unique(array_map(fn($item) => $item->type, $value->value->value));
472473
$propery_data['example'] = array_merge(array_filter(array_map(fn($item) => $item->value, $value->value->value)));
473474

474475
return $propery_data;
475-
}
476-
477-
if ($value->type === 'object') {
476+
} elseif ($value->type === 'object') {
478477
$propery_data['type'] = $value->type;
479478
$propery_data['properties'] = $this->getComponent($value->value)['properties'];
480479

0 commit comments

Comments
 (0)