diff --git a/src/Generator.php b/src/Generator.php index 9b2f048..0df7681 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -25,7 +25,7 @@ public function generate(string $namespace, string $destinationPath) $codePrinter = new Standard(); $schemaClassNameMap = []; foreach ($this->spec->components->schemas as $name => $schema) { - $schemaClassName = trim(str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($name))->toPascal())); + $schemaClassName = $this->className($name); if (strlen($schemaClassName) === 0) { continue; } @@ -46,7 +46,7 @@ public function generate(string $namespace, string $destinationPath) } foreach ($this->spec->paths as $path => $pathItem) { - $pathClassName = str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($path))->toPascal()); + $pathClassName = $this->className($path); @mkdir(dirname($destinationPath . '/Path/' . $pathClassName), 0777, true); file_put_contents($destinationPath . '/Path/' . $pathClassName . '.php', $codePrinter->prettyPrintFile([ Path::generate( @@ -58,7 +58,7 @@ public function generate(string $namespace, string $destinationPath) ), ]) . PHP_EOL); foreach ($pathItem->getOperations() as $method => $operation) { - $operationClassName = (new Convert($operation->operationId))->fromTrain()->toPascal(); + $operationClassName = $this->className((new Convert($operation->operationId))->fromTrain()->toPascal()); $operations[$method] = $operationClassName; @mkdir(dirname($destinationPath . '/Operation/' . $operationClassName), 0777, true); @@ -75,4 +75,9 @@ public function generate(string $namespace, string $destinationPath) } } + + private function className(string $className): string + { + return str_replace(['{', '}', '-'], ['Cb', 'Rcb', 'Dash'], (new Convert($className))->toPascal()); + } } \ No newline at end of file