From 29bfa280580a7de02c59cb29dc56330e7f3e169a Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 3 May 2021 23:17:47 +0200 Subject: [PATCH] No Ghost classes Signed-off-by: Cees-Jan Kiewiet --- src/Generator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index dc9a55c..9b2f048 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -25,10 +25,14 @@ public function generate(string $namespace, string $destinationPath) $codePrinter = new Standard(); $schemaClassNameMap = []; foreach ($this->spec->components->schemas as $name => $schema) { - $schemaClassNameMap[spl_object_hash($schema)] = str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($name))->toPascal()); + $schemaClassName = trim(str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($name))->toPascal())); + if (strlen($schemaClassName) === 0) { + continue; + } + $schemaClassNameMap[spl_object_hash($schema)] = $schemaClassName; } foreach ($this->spec->components->schemas as $name => $schema) { - $schemaClassName = str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($name))->toPascal()); + $schemaClassName = $schemaClassNameMap[spl_object_hash($schema)]; @mkdir(dirname($destinationPath . '/Schema/' . $schemaClassName), 0777, true); file_put_contents($destinationPath . '/Schema/' . $schemaClassName . '.php', $codePrinter->prettyPrintFile([ Schema::generate(