Skip to content

Commit e172089

Browse files
committed
Make optional fields nullable
1 parent 6165f09 commit e172089

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Generator/Schema.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,17 @@ public static function generate(string $name, string $namespace, string $classNa
109109
'',
110110
'bool',
111111
], $property->type);
112+
113+
if ($t !== '' && is_array($schema->required) && !in_array($propertyName, $schema->required, false)) {
114+
$t = '?' . $t;
115+
$propertyStmt->setDefault(null);
116+
}
117+
112118
if ($t !== '') {
113119
$propertyStmt->setType($t);
114120
$method->setReturnType($t);
115121
}
116122
}
117-
118123
}
119124

120125
if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {

0 commit comments

Comments
 (0)