Skip to content

Commit 31046f6

Browse files
authored
add option to overwrite json schema title (#12)
1 parent 5e81412 commit 31046f6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Command/ConvertSingleAvscToJsonCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected function configure(): void
2929
->setDescription('Convert avsc schema to json schema')
3030
->addArgument('avscSchema', InputArgument::REQUIRED, 'Avsc schema file path')
3131
->addArgument('jsonSchema', InputArgument::REQUIRED, 'Json schema file path')
32+
->addArgument('title', InputArgument::OPTIONAL, 'Set a specific title for the json schema')
3233
->addOption(
3334
'noDefaultAsRequired',
3435
null,
@@ -40,6 +41,9 @@ protected function configure(): void
4041

4142
public function execute(InputInterface $input, OutputInterface $output): ?int
4243
{
44+
/** @var string|null $title */
45+
$title = $input->getArgument('title');
46+
4347
/** @var string $avscSchema */
4448
$avscSchema = $input->getArgument('avscSchema');
4549

@@ -58,6 +62,12 @@ public function execute(InputInterface $input, OutputInterface $output): ?int
5862
$avsc = file_get_contents($avscSchema);
5963
$json = $this->converter->convert($avsc, ['markNoDefaultAsRequired' => $noDefaultAsRequired]);
6064

65+
if (null !== $title) {
66+
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
67+
$data['title'] = $title;
68+
$json = json_encode($data, JSON_THROW_ON_ERROR);
69+
}
70+
6171
if (false === file_exists($outputDirectory)) {
6272
mkdir($outputDirectory, 0755, true);
6373
}

0 commit comments

Comments
 (0)