fix: Cannot pass null to nullable enum parameters (#299)
* nullable enum value * fix tests
This commit is contained in:
parent
797472777f
commit
06917f6af6
2 changed files with 5 additions and 3 deletions
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ final class SchemaGeneratorTest extends TestCase
|
|||
$this->assertEquals(['type' => 'string', 'description' => 'Backed string enum', 'enum' => ['A', 'B']], $schema['properties']['stringEnum']);
|
||||
$this->assertEquals(['type' => 'integer', 'description' => 'Backed int enum', 'enum' => [1, 2]], $schema['properties']['intEnum']);
|
||||
$this->assertEquals(['type' => 'string', 'description' => 'Unit enum', 'enum' => ['Yes', 'No']], $schema['properties']['unitEnum']);
|
||||
$this->assertEquals(['type' => ['null', 'string'], 'enum' => ['A', 'B'], 'default' => null], $schema['properties']['nullableEnum']);
|
||||
$this->assertEquals(['type' => ['string', 'null'], 'enum' => ['A', 'B', null], 'default' => null], $schema['properties']['nullableEnum']);
|
||||
$this->assertEquals(['type' => 'integer', 'enum' => [1, 2], 'default' => 1], $schema['properties']['enumWithDefault']);
|
||||
$this->assertEqualsCanonicalizing(['stringEnum', 'intEnum', 'unitEnum'], $schema['required']);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue