Skip to content

Commit c086dfe

Browse files
authored
fix(openapi): optional yaml component (#6445)
1 parent 65ac0d2 commit c086dfe

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/OpenApi/Command/OpenApiCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656
$data = $this->normalizer->normalize($this->openApiFactory->__invoke(), 'json', [
5757
'spec_version' => $input->getOption('spec-version'),
5858
]);
59+
60+
if ($input->getOption('yaml') && !class_exists(Yaml::class)) {
61+
$output->writeln('The "symfony/yaml" component is not installed.');
62+
63+
return 1;
64+
}
65+
5966
$content = $input->getOption('yaml')
6067
? Yaml::dump($data, 10, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK | Yaml::DUMP_NUMERIC_KEY_AS_STRING)
6168
: (json_encode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES) ?: '');

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array
529529
}
530530

531531
$loader->load('openapi.xml');
532+
533+
if (class_exists(Yaml::class)) {
534+
$loader->load('openapi/yaml.xml');
535+
}
536+
532537
$loader->load('swagger_ui.xml');
533538

534539
if ($config['event_listeners_backward_compatibility_layer']) {

src/Symfony/Bundle/Resources/config/openapi.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@
100100
<tag name="serializer.encoder" />
101101
</service>
102102

103-
<service id="api_platform.yamlopenapi.encoder" class="ApiPlatform\Serializer\YamlEncoder" public="false">
104-
<argument>yamlopenapi</argument>
105-
<argument type="service" id="serializer.encoder.yaml" on-invalid="null" />
106-
107-
<tag name="serializer.encoder" />
108-
</service>
109103
</services>
110104

111105
</container>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
<services>
7+
<service id="api_platform.yamlopenapi.encoder" class="ApiPlatform\Serializer\YamlEncoder" public="false">
8+
<argument>yamlopenapi</argument>
9+
<argument type="service" id="serializer.encoder.yaml" on-invalid="null" />
10+
11+
<tag name="serializer.encoder" />
12+
</service>
13+
</services>
14+
</container>

0 commit comments

Comments
 (0)