fix: Cannot pass null to nullable enum parameters (#299)

* nullable enum value

* fix tests
This commit is contained in:
SBNTT 2026-05-08 10:15:14 +02:00 • committed by GitHub
commit 06917f6af6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -374,7 +374,8 @@ final class SchemaGenerator implements SchemaGeneratorInterface
if ($jsonBackingType) {
if (isset($paramSchema['type']) && \is_array($paramSchema['type']) && \in_array('null', $paramSchema['type'])) {
$paramSchema['type'] = ['null', $jsonBackingType];
$paramSchema['type'] = [$jsonBackingType, 'null'];
$paramSchema['enum'][] = null;
} else {
$paramSchema['type'] = $jsonBackingType;
}
@ -383,7 +384,8 @@ final class SchemaGenerator implements SchemaGeneratorInterface
// Non-backed enum - use names as enum values
$paramSchema['enum'] = array_column($enumClass::cases(), 'name');
if (isset($paramSchema['type']) && \is_array($paramSchema['type']) && \in_array('null', $paramSchema['type'])) {
$paramSchema['type'] = ['null', 'string'];
$paramSchema['type'] = ['string', 'null'];
$paramSchema['enum'][] = null;
} else {
$paramSchema['type'] = 'string';
}