Skip to content

Commit 8539421

Browse files
committed
Detect odd nullable structure inside oneOf or anyOf
1 parent ec369bb commit 8539421

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Gatherer/Type.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,51 @@ public static function gather(
1717
bool $required,
1818
SchemaRegistry $schemaRegistry,
1919
): PropertyType {
20-
if (is_array($property->allOf)) {
20+
if (is_array($property->allOf) && count($property->allOf) > 0) {
2121
return self::gather(
2222
$className,
2323
$propertyName,
2424
$property->allOf[0],
2525
$required,
2626
$schemaRegistry,
2727
);
28-
} else if (is_array($property->oneOf)) {
28+
} else if (is_array($property->oneOf) && count($property->oneOf) > 0) {
29+
// Check if nullable
30+
if (
31+
count($property->oneOf) === 2 &&
32+
count(array_filter($property->oneOf, static fn (\cebe\openapi\spec\Schema $schema): bool => $schema->type === 'null')) === 1
33+
) {
34+
return self::gather(
35+
$className,
36+
$propertyName,
37+
current(array_filter($property->oneOf, static fn (\cebe\openapi\spec\Schema $schema): bool => $schema->type !== 'null')),
38+
false,
39+
$schemaRegistry,
40+
);
41+
}
42+
2943
return self::gather(
3044
$className,
3145
$propertyName,
3246
$property->oneOf[0],
3347
$required,
3448
$schemaRegistry,
3549
);
36-
} else if (is_array($property->anyOf)) {
50+
} else if (is_array($property->anyOf) && count($property->anyOf) > 0) {
51+
// Check if nullable
52+
if (
53+
count($property->anyOf) === 2 &&
54+
count(array_filter($property->anyOf, static fn (\cebe\openapi\spec\Schema $schema): bool => $schema->type === 'null')) === 1
55+
) {
56+
return self::gather(
57+
$className,
58+
$propertyName,
59+
current(array_filter($property->anyOf, static fn (\cebe\openapi\spec\Schema $schema): bool => $schema->type !== 'null')),
60+
false,
61+
$schemaRegistry,
62+
);
63+
}
64+
3765
return self::gather(
3866
$className,
3967
$propertyName,

0 commit comments

Comments
 (0)