Skip to content

Commit 9e52685

Browse files
authored
Merge pull request #17 from ensi-platform/task-100773
#100773 Global template parameters
2 parents b848fae + 57a6403 commit 9e52685

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config/openapi-server-generator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
* You can use as many yaml/json openapi entrypoints as you want.
1212
* Key = openapi entrypoint file with path.
1313
* Value = list of entities and their generator params.
14+
*
15+
* All values from 'params' will be available inside any template.
16+
* apiVersion = {{ apiVersion}} in template.
1417
*/
1518
'api_docs_mappings' => [
1619
public_path('api-docs/v1/index.yaml') => [
20+
'params' => [
21+
'apiVersion' => 1,
22+
],
1723
'controllers' => [],
1824
'enums' => [
1925
'namespace' => "App\\Http\\ApiV1\\OpenApiGenerated\\Enums\\",

src/Generators/BaseGenerator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function setOptions(array $options): static
3434

3535
protected function replacePlaceholders(string $content, array $placeholders, bool $removeExcessLineBreaks = false): string
3636
{
37+
$placeholders = array_merge($placeholders, $this->formattedGlobalParams());
3738
$content = str_replace(array_keys($placeholders), array_values($placeholders), $content);
3839

3940
// Убираем двойные переносы строк
@@ -78,4 +79,14 @@ protected function prepareDestinationDir(string $toDir): void
7879
$this->filesystem->ensureDirectoryExists($toDir);
7980
$this->filesystem->cleanDirectory($toDir);
8081
}
82+
83+
private function formattedGlobalParams(): array
84+
{
85+
$params = [];
86+
foreach ($this->options['params'] ?? [] as $key => $value) {
87+
$params["{{ $key }}"] = $value;
88+
}
89+
90+
return $params;
91+
}
8192
}

0 commit comments

Comments
 (0)