• 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

100.0
/src/Symfony/Bundle/SwaggerUi/SwaggerUiProvider.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\Symfony\Bundle\SwaggerUi;
15

16
use ApiPlatform\Documentation\Documentation;
17
use ApiPlatform\Documentation\Entrypoint;
18
use ApiPlatform\Metadata\Error;
19
use ApiPlatform\Metadata\Get;
20
use ApiPlatform\Metadata\HttpOperation;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
23
use ApiPlatform\OpenApi\OpenApi;
24
use ApiPlatform\State\ProviderInterface;
25

26
/**
27
 * When an HTML request is sent we provide a swagger ui documentation.
28
 *
29
 * @internal
30
 */
31
final class SwaggerUiProvider implements ProviderInterface
32
{
33
    public function __construct(private readonly ProviderInterface $decorated, private readonly OpenApiFactoryInterface $openApiFactory)
34
    {
UNCOV
35
    }
800✔
36

37
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
38
    {
39
        // We went through the DocumentationAction
UNCOV
40
        if (OpenApi::class === $operation->getClass()) {
800✔
UNCOV
41
            return $this->decorated->provide($operation, $uriVariables, $context);
10✔
42
        }
43

44
        if (
UNCOV
45
            !($operation instanceof HttpOperation)
790✔
UNCOV
46
            || !($request = $context['request'] ?? null)
790✔
UNCOV
47
            || 'html' !== $request->getRequestFormat()
790✔
UNCOV
48
            || true === ($operation->getExtraProperties()['_api_disable_swagger_provider'] ?? false)
790✔
49
        ) {
UNCOV
50
            return $this->decorated->provide($operation, $uriVariables, $context);
781✔
51
        }
52

UNCOV
53
        if (!$request->attributes->has('_api_requested_operation')) {
9✔
UNCOV
54
            $request->attributes->set('_api_requested_operation', $operation);
9✔
55
        }
56

57
        // We need to call our operation provider just in case it fails
58
        // when it fails we'll get an Error and we'll fix the status accordingly
59
        // @see features/main/content_negotiation.feature:119
60
        // When requesting DocumentationAction or EntrypointAction with Accept: text/html we render SwaggerUi
UNCOV
61
        if (!$operation instanceof Error && !\in_array($operation->getClass(), [Documentation::class, Entrypoint::class], true)) {
9✔
62
            $this->decorated->provide($operation, $uriVariables, $context);
3✔
63
        }
64

65
        // This should render only when an error occured
UNCOV
66
        $swaggerUiOperation = new Get(
8✔
UNCOV
67
            class: OpenApi::class,
8✔
UNCOV
68
            processor: 'api_platform.swagger_ui.processor',
8✔
UNCOV
69
            validate: false,
8✔
UNCOV
70
            read: false,
8✔
UNCOV
71
            write: true, // force write so that our processor gets called
8✔
UNCOV
72
            status: $operation->getStatus()
8✔
UNCOV
73
        );
8✔
74

75
        // save our operation
UNCOV
76
        $request->attributes->set('_api_operation', $swaggerUiOperation);
8✔
77

UNCOV
78
        $data = $this->openApiFactory->__invoke([
8✔
UNCOV
79
            'base_url' => $request->getBaseUrl() ?: '/',
8✔
UNCOV
80
            'filter_tags' => $request->query->all('filter_tags'),
8✔
UNCOV
81
        ]);
8✔
UNCOV
82
        $request->attributes->set('data', $data);
8✔
83

UNCOV
84
        return $data;
8✔
85
    }
86
}
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