Skip to content

Commit 6ed2ec9

Browse files
authored
Merge pull request #51 from php-api-clients/take-first-oneOf-on-schema-if-exists
Take first oneOf on schema if exists
2 parents a0065b7 + cfd79a4 commit 6ed2ec9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Generator/Schema.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ public static function generate(string $name, string $namespace, string $classNa
5252
)
5353
);
5454

55+
if ($schema->oneOf !== null && count($schema->oneOf) > 0 && $schema->oneOf[0] instanceof OpenAPiSchema) {
56+
yield from self::fillUpSchema($name, $namespace, $className, $class, $schema->oneOf[0], $factory, $schemaClassNameMap, $rootNamespace);
57+
} else {
58+
yield from self::fillUpSchema($name, $namespace, $className, $class, $schema, $factory, $schemaClassNameMap, $rootNamespace);
59+
}
60+
61+
yield new File($namespace . '\\' . $className, $stmt->addStmt($class)->getNode());
62+
}
63+
64+
private static function fillUpSchema(string $name, string $namespace, string $className, \PhpParser\Builder\Class_ $class, OpenAPiSchema $schema, $factory, array $schemaClassNameMap, string $rootNamespace): iterable
65+
{
5566
foreach ($schema->properties as $propertyName => $property) {
5667
$propertyName = str_replace([
5768
'@',
@@ -178,7 +189,5 @@ public static function generate(string $name, string $namespace, string $classNa
178189

179190
$class->addStmt($propertyStmt)->addStmt($method);
180191
}
181-
182-
yield new File($namespace . '\\' . $className, $stmt->addStmt($class)->getNode());
183192
}
184193
}

0 commit comments

Comments
 (0)