Skip to content

Commit 0b3ec11

Browse files
committed
fix: protect OpenAPI generation
1 parent c555fc9 commit 0b3ec11

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/PHPDraft/Out/OpenAPI/OpenApiRenderer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ private function getSchemaProperty(BasicStructureElement|ElementStructureElement
449449
if ($value->type === 'enum') {
450450
$propery_data['type'] = in_array('nullable', $value->status, TRUE) ? [ $value->type, 'null' ] : $value->type;
451451
$options = [];
452+
if (!is_iterable($value->value)) {
453+
return $propery_data;
454+
}
452455
foreach ($value->value->value as $option) {
453456
if ($option instanceof ElementStructureElement) {
454457
$options[] = ['const' => $option->value, 'title' => $option->value];
@@ -457,18 +460,14 @@ private function getSchemaProperty(BasicStructureElement|ElementStructureElement
457460
$propery_data['oneOf'] = $options;
458461

459462
return $propery_data;
460-
}
461-
462-
if ($value->type === 'array') {
463+
} elseif ($value->type === 'array') {
463464
$propery_data['type'] = array_unique(array_map(fn($item) => $item->type,$value->value->value));
464465
$propery_data['example'] = array_merge(array_filter(array_map(fn($item) => $item->value,$value->value->value)));
465466

466467
return $propery_data;
467-
}
468-
469-
if ($value->type === 'object') {
468+
} elseif ($value->type === 'object') {
470469
$propery_data['type'] = $value->type;
471-
$propery_data['properties'] = $this->getComponent($value->value)['properties'];
470+
$propery_data['properties'] = $this->getComponent($value->value)['properties'] ?? (object) [];
472471

473472
return $propery_data;
474473
}

0 commit comments

Comments
 (0)