• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/OpenApi/Command/OpenApiCommand.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\OpenApi\Command;
15

16
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
17
use Symfony\Component\Console\Attribute\AsCommand;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\Console\Style\SymfonyStyle;
23
use Symfony\Component\Filesystem\Filesystem;
24
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25
use Symfony\Component\Yaml\Yaml;
26

27
/**
28
 * Dumps Open API documentation.
29
 */
30
#[AsCommand(name: 'api:openapi:export')]
31
final class OpenApiCommand extends Command
32
{
33
    public function __construct(private readonly OpenApiFactoryInterface $openApiFactory, private readonly NormalizerInterface $normalizer)
34
    {
UNCOV
35
        parent::__construct();
5✔
36
    }
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function configure(): void
42
    {
UNCOV
43
        $this
5✔
UNCOV
44
            ->setDescription('Dump the Open API documentation')
5✔
UNCOV
45
            ->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML')
5✔
UNCOV
46
            ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file')
5✔
UNCOV
47
            ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'Open API version to use (2 or 3) (2 is deprecated)', '3')
5✔
UNCOV
48
            ->addOption('api-gateway', null, InputOption::VALUE_NONE, 'Enable the Amazon API Gateway compatibility mode')
5✔
UNCOV
49
            ->addOption('filter-tags', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter only matching x-apiplatform-tag operations', null);
5✔
50
    }
51

52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output): int
56
    {
UNCOV
57
        $filesystem = new Filesystem();
5✔
UNCOV
58
        $io = new SymfonyStyle($input, $output);
5✔
UNCOV
59
        $data = $this->normalizer->normalize(
5✔
UNCOV
60
            $this->openApiFactory->__invoke(['filter_tags' => $input->getOption('filter-tags')]),
5✔
UNCOV
61
            'json',
5✔
UNCOV
62
            ['spec_version' => $input->getOption('spec-version')]
5✔
UNCOV
63
        );
5✔
64

UNCOV
65
        if ($input->getOption('yaml') && !class_exists(Yaml::class)) {
5✔
66
            $output->writeln('The "symfony/yaml" component is not installed.');
×
67

68
            return 1;
×
69
        }
70

UNCOV
71
        $content = $input->getOption('yaml')
5✔
UNCOV
72
            ? 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)
1✔
UNCOV
73
            : (json_encode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES) ?: '');
4✔
74

UNCOV
75
        $filename = $input->getOption('output');
5✔
UNCOV
76
        if ($filename && \is_string($filename)) {
5✔
UNCOV
77
            $filesystem->dumpFile($filename, $content);
1✔
UNCOV
78
            $io->success(\sprintf('Data written to %s.', $filename));
1✔
79

UNCOV
80
            return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0;
1✔
81
        }
82

UNCOV
83
        $output->writeln($content);
4✔
84

UNCOV
85
        return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0;
4✔
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc