Skip to content

Commit 7efabe2

Browse files
committed
fix route yaml generation missing documentation first level key
1 parent d8529eb commit 7efabe2

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/Command/ComponentGeneration/Route/RouteTuiGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ private function generateRoute(Tui $tui, RouteTuiState $state): void
11641164

11651165
$array = $builder->build();
11661166
unset($array['components']);
1167+
$array = ['documentation' => $array];
11671168

11681169
$destination = ComponentType::Routes->value;
11691170

@@ -1174,7 +1175,8 @@ private function generateRoute(Tui $tui, RouteTuiState $state): void
11741175
// Merge with existing config to preserve manually-added fields (YAML only)
11751176
if ('php' !== pathinfo($state->loadedFrom, PATHINFO_EXTENSION)) {
11761177
$existingConfig = \Symfony\Component\Yaml\Yaml::parseFile($state->loadedFrom);
1177-
if (isset($existingConfig['paths'])) {
1178+
$existingPaths = $existingConfig['documentation']['paths'] ?? $existingConfig['paths'] ?? null;
1179+
if (null !== $existingPaths) {
11781180
$array = array_replace_recursive($existingConfig, $array);
11791181
}
11801182
}

src/Command/ComponentGeneration/Route/RouteTuiManager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ public function loadRouteConfig(string $routeName, string $componentType): array
204204
}
205205
} else {
206206
$config = \Symfony\Component\Yaml\Yaml::parseFile($file->getRealPath());
207-
if (isset($config['paths'])) {
207+
$pathsConfig = $config['documentation']['paths'] ?? $config['paths'] ?? null;
208+
if (null !== $pathsConfig) {
209+
if (isset($config['documentation']['paths'])) {
210+
$config = ['paths' => $config['documentation']['paths']];
211+
}
212+
208213
return ['methodsConfig' => $this->extractMethodsConfig($config, $path)];
209214
}
210215
}
@@ -253,7 +258,7 @@ private function parseRoutePhpFile(string $filePath, string $path): ?array
253258
$methodsConfig[$currentMethod]['tags'][] = $m[1];
254259
} elseif (preg_match("/->security\\('([^']+)'\\)/", $line, $m)) {
255260
$methodsConfig[$currentMethod]['security'][] = $m[1];
256-
} elseif (preg_match('/->response\\((\\d+)\\)/', $line, $m)) {
261+
} elseif (preg_match('/->response\((\d+)\)/', $line, $m)) {
257262
$statusCode = (int)$m[1];
258263
$methodsConfig[$currentMethod]['responses'][$statusCode] = [
259264
'schema' => null,

src/Command/Traits/GenerateFileTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ protected function buildRouteCode(array $array, string $routeName, int $indent):
779779
$pad = str_repeat(' ', $indent);
780780
$code = '';
781781

782-
$paths = $array['paths'] ?? [];
782+
$paths = $array['documentation']['paths'] ?? $array['paths'] ?? [];
783783
foreach ($paths as $path => $methods) {
784784
if (!is_array($methods)) {
785785
continue;

tests/ehyiah_api_doc_test.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@ framework:
22
router:
33
utf8: true
44
resource: '%kernel.project_dir%/config/routes.yaml'
5-
6-
ehyiah_api_doc:
7-
source_path: '/var/Swagger'
8-
dump_path: '/var/Dump'

0 commit comments

Comments
 (0)