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

api-platform / core / 13897184482

17 Mar 2025 10:29AM UTC coverage: 17.371% (+8.6%) from 8.768%
13897184482

Pull #7027

github

web-flow
Merge 6b496c593 into ba5cea729
Pull Request #7027: fix(laravel): json api default parameters

0 of 18 new or added lines in 2 files covered. (0.0%)

545 existing lines in 58 files now uncovered.

4729 of 27224 relevant lines covered (17.37%)

78.16 hits per line

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

80.46
/src/OpenApi/Factory/OpenApiFactory.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\Factory;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as DoctrineODMOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options as DoctrineOptions;
18
use ApiPlatform\JsonSchema\Schema;
19
use ApiPlatform\JsonSchema\SchemaFactoryInterface;
20
use ApiPlatform\Metadata\ApiResource;
21
use ApiPlatform\Metadata\CollectionOperationInterface;
22
use ApiPlatform\Metadata\Error;
23
use ApiPlatform\Metadata\ErrorResource;
24
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
25
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
26
use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
27
use ApiPlatform\Metadata\Exception\RuntimeException;
28
use ApiPlatform\Metadata\HeaderParameterInterface;
29
use ApiPlatform\Metadata\HttpOperation;
30
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
31
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
32
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
33
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
34
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
35
use ApiPlatform\OpenApi\Attributes\Webhook;
36
use ApiPlatform\OpenApi\Model\Components;
37
use ApiPlatform\OpenApi\Model\Contact;
38
use ApiPlatform\OpenApi\Model\Info;
39
use ApiPlatform\OpenApi\Model\License;
40
use ApiPlatform\OpenApi\Model\Link;
41
use ApiPlatform\OpenApi\Model\MediaType;
42
use ApiPlatform\OpenApi\Model\OAuthFlow;
43
use ApiPlatform\OpenApi\Model\OAuthFlows;
44
use ApiPlatform\OpenApi\Model\Operation;
45
use ApiPlatform\OpenApi\Model\Parameter;
46
use ApiPlatform\OpenApi\Model\PathItem;
47
use ApiPlatform\OpenApi\Model\Paths;
48
use ApiPlatform\OpenApi\Model\RequestBody;
49
use ApiPlatform\OpenApi\Model\Response;
50
use ApiPlatform\OpenApi\Model\SecurityScheme;
51
use ApiPlatform\OpenApi\Model\Server;
52
use ApiPlatform\OpenApi\Model\Tag;
53
use ApiPlatform\OpenApi\OpenApi;
54
use ApiPlatform\OpenApi\Options;
55
use ApiPlatform\OpenApi\Serializer\NormalizeOperationNameTrait;
56
use ApiPlatform\State\ApiResource\Error as ApiResourceError;
57
use ApiPlatform\State\Pagination\PaginationOptions;
58
use ApiPlatform\Validator\Exception\ValidationException;
59
use Psr\Container\ContainerInterface;
60
use Symfony\Component\PropertyInfo\Type;
61
use Symfony\Component\Routing\RouteCollection;
62
use Symfony\Component\Routing\RouterInterface;
63

64
/**
65
 * Generates an Open API v3 specification.
66
 */
67
final class OpenApiFactory implements OpenApiFactoryInterface
68
{
69
    use NormalizeOperationNameTrait;
70
    use TypeFactoryTrait;
71

72
    public const BASE_URL = 'base_url';
73
    public const API_PLATFORM_TAG = 'x-apiplatform-tag';
74
    public const OVERRIDE_OPENAPI_RESPONSES = 'open_api_override_responses';
75
    private readonly Options $openApiOptions;
76
    private readonly PaginationOptions $paginationOptions;
77
    private ?RouteCollection $routeCollection = null;
78
    private ?ContainerInterface $filterLocator = null;
79
    /**
80
     * @var array<string|class-string, ErrorResource>
81
     */
82
    private array $localErrorResourceCache = [];
83

84
    /**
85
     * @param array<string, string[]> $formats
86
     */
87
    public function __construct(
88
        private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory,
89
        private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory,
90
        private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
91
        private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory,
92
        private readonly SchemaFactoryInterface $jsonSchemaFactory,
93
        ?ContainerInterface $filterLocator = null,
94
        private readonly array $formats = [],
95
        ?Options $openApiOptions = null,
96
        ?PaginationOptions $paginationOptions = null,
97
        private readonly ?RouterInterface $router = null,
98
        private readonly array $errorFormats = [],
99
    ) {
100
        $this->filterLocator = $filterLocator;
1,006✔
101
        $this->openApiOptions = $openApiOptions ?: new Options('API Platform');
1,006✔
102
        $this->paginationOptions = $paginationOptions ?: new PaginationOptions();
1,006✔
103
    }
104

105
    /**
106
     * {@inheritdoc}
107
     *
108
     * You can filter openapi operations with the `x-apiplatform-tag` on an OpenApi Operation using the `filter_tags`.
109
     *
110
     * @param array{base_url?: string, filter_tags?: string[]}&array<string, mixed> $context
111
     */
112
    public function __invoke(array $context = []): OpenApi
113
    {
114
        $baseUrl = $context[self::BASE_URL] ?? '/';
32✔
115
        $contact = null === $this->openApiOptions->getContactUrl() || null === $this->openApiOptions->getContactEmail() ? null : new Contact($this->openApiOptions->getContactName(), $this->openApiOptions->getContactUrl(), $this->openApiOptions->getContactEmail());
32✔
116
        $license = null === $this->openApiOptions->getLicenseName() ? null : new License($this->openApiOptions->getLicenseName(), $this->openApiOptions->getLicenseUrl());
32✔
117
        $info = new Info($this->openApiOptions->getTitle(), $this->openApiOptions->getVersion(), trim($this->openApiOptions->getDescription()), $this->openApiOptions->getTermsOfService(), $contact, $license);
32✔
118
        $servers = '/' === $baseUrl || '' === $baseUrl ? [new Server('/')] : [new Server($baseUrl)];
32✔
119
        $paths = new Paths();
32✔
120
        $schemas = new \ArrayObject();
32✔
121
        $webhooks = new \ArrayObject();
32✔
122
        $tags = [];
32✔
123

124
        foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
32✔
125
            $resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
32✔
126
            foreach ($resourceMetadataCollection as $resourceMetadata) {
32✔
127
                $this->collectPaths($resourceMetadata, $resourceMetadataCollection, $paths, $schemas, $webhooks, $tags, $context);
32✔
128
            }
129
        }
130

131
        $securitySchemes = $this->getSecuritySchemes();
32✔
132
        $securityRequirements = [];
32✔
133

134
        foreach (array_keys($securitySchemes) as $key) {
32✔
135
            $securityRequirements[] = [$key => []];
32✔
136
        }
137

138
        $globalTags = $this->openApiOptions->getTags() ?: array_values($tags) ?: [];
32✔
139

140
        return new OpenApi(
32✔
141
            $info,
32✔
142
            $servers,
32✔
143
            $paths,
32✔
144
            new Components(
32✔
145
                $schemas,
32✔
146
                new \ArrayObject(),
32✔
147
                new \ArrayObject(),
32✔
148
                new \ArrayObject(),
32✔
149
                new \ArrayObject(),
32✔
150
                new \ArrayObject(),
32✔
151
                new \ArrayObject($securitySchemes)
32✔
152
            ),
32✔
153
            $securityRequirements,
32✔
154
            $globalTags,
32✔
155
            null,
32✔
156
            null,
32✔
157
            $webhooks
32✔
158
        );
32✔
159
    }
160

161
    private function collectPaths(ApiResource $resource, ResourceMetadataCollection $resourceMetadataCollection, Paths $paths, \ArrayObject $schemas, \ArrayObject $webhooks, array &$tags, array $context = []): void
162
    {
163
        if (0 === $resource->getOperations()->count()) {
32✔
164
            return;
×
165
        }
166

167
        $defaultError = $this->getErrorResource($this->openApiOptions->getErrorResourceClass() ?? ApiResourceError::class);
32✔
168
        $defaultValidationError = $this->getErrorResource($this->openApiOptions->getValidationErrorResourceClass() ?? ValidationException::class, 422, 'Unprocessable entity');
32✔
169

170
        // This filters on our extension x-apiplatform-tag as the openapi operation tag is used for ordering operations
171
        $filteredTags = $context['filter_tags'] ?? [];
32✔
172
        if (!\is_array($filteredTags)) {
32✔
173
            $filteredTags = [$filteredTags];
2✔
174
        }
175

176
        foreach ($resource->getOperations() as $operationName => $operation) {
32✔
177
            $resourceShortName = $operation->getShortName() ?? $operation;
32✔
178
            // No path to return
179
            if (null === $operation->getUriTemplate() && null === $operation->getRouteName()) {
32✔
180
                continue;
×
181
            }
182

183
            $openapiAttribute = $operation->getOpenapi();
32✔
184

185
            // Operation ignored from OpenApi
186
            if ($operation instanceof HttpOperation && false === $openapiAttribute) {
32✔
187
                continue;
32✔
188
            }
189

190
            // See https://github.com/api-platform/core/issues/6993 we would like to allow only `false` but as we typed `bool` we have this check
191
            $operationTag = !\is_object($openapiAttribute) ? [] : ($openapiAttribute->getExtensionProperties()[self::API_PLATFORM_TAG] ?? []);
32✔
192
            if (!\is_array($operationTag)) {
32✔
193
                $operationTag = [$operationTag];
26✔
194
            }
195

196
            if ($filteredTags && $filteredTags !== array_intersect($filteredTags, $operationTag)) {
32✔
197
                continue;
4✔
198
            }
199

200
            $resourceClass = $operation->getClass() ?? $resource->getClass();
32✔
201
            $routeName = $operation->getRouteName() ?? $operation->getName();
32✔
202

203
            if (!$this->routeCollection && $this->router) {
32✔
204
                $this->routeCollection = $this->router->getRouteCollection();
32✔
205
            }
206

207
            if ($this->routeCollection && $routeName && $route = $this->routeCollection->get($routeName)) {
32✔
208
                $path = $route->getPath();
32✔
209
            } else {
210
                $path = rtrim($operation->getRoutePrefix() ?? '', '/').'/'.ltrim($operation->getUriTemplate() ?? '', '/');
×
211
            }
212

213
            $path = $this->getPath($path);
32✔
214
            $method = $operation->getMethod() ?? 'GET';
32✔
215

216
            if (!\in_array($method, PathItem::$methods, true)) {
32✔
217
                continue;
×
218
            }
219

220
            $pathItem = null;
32✔
221

222
            if ($openapiAttribute instanceof Webhook) {
32✔
223
                $pathItem = $openapiAttribute->getPathItem() ?: new PathItem();
12✔
224
                $openapiOperation = $pathItem->{'get'.ucfirst(strtolower($method))}() ?: new Operation();
12✔
225
            } elseif (!\is_object($openapiAttribute)) {
32✔
226
                $openapiOperation = new Operation();
28✔
227
            } else {
228
                $openapiOperation = $openapiAttribute;
26✔
229
            }
230

231
            // Complete with defaults
232
            $openapiOperation = new Operation(
32✔
233
                operationId: null !== $openapiOperation->getOperationId() ? $openapiOperation->getOperationId() : $this->normalizeOperationName($operationName),
32✔
234
                tags: null !== $openapiOperation->getTags() ? $openapiOperation->getTags() : [$operation->getShortName() ?: $resourceShortName],
32✔
235
                responses: null !== $openapiOperation->getResponses() ? $openapiOperation->getResponses() : [],
32✔
236
                summary: null !== $openapiOperation->getSummary() ? $openapiOperation->getSummary() : $this->getPathDescription($resourceShortName, $method, $operation instanceof CollectionOperationInterface),
32✔
237
                description: null !== $openapiOperation->getDescription() ? $openapiOperation->getDescription() : $this->getPathDescription($resourceShortName, $method, $operation instanceof CollectionOperationInterface),
32✔
238
                externalDocs: $openapiOperation->getExternalDocs(),
32✔
239
                parameters: null !== $openapiOperation->getParameters() ? $openapiOperation->getParameters() : [],
32✔
240
                requestBody: $openapiOperation->getRequestBody(),
32✔
241
                callbacks: $openapiOperation->getCallbacks(),
32✔
242
                deprecated: null !== $openapiOperation->getDeprecated() ? $openapiOperation->getDeprecated() : (bool) $operation->getDeprecationReason(),
32✔
243
                security: null !== $openapiOperation->getSecurity() ? $openapiOperation->getSecurity() : null,
32✔
244
                servers: null !== $openapiOperation->getServers() ? $openapiOperation->getServers() : null,
32✔
245
                extensionProperties: $openapiOperation->getExtensionProperties(),
32✔
246
            );
32✔
247

248
            foreach ($openapiOperation->getTags() as $v) {
32✔
249
                $tags[$v] = new Tag(name: $v, description: $resource->getDescription());
32✔
250
            }
251

252
            [$requestMimeTypes, $responseMimeTypes] = $this->getMimeTypes($operation);
32✔
253

254
            if ($path) {
32✔
255
                $pathItem = $paths->getPath($path) ?: new PathItem();
32✔
256
            } elseif (!$pathItem) {
×
257
                $pathItem = new PathItem();
×
258
            }
259

260
            $forceSchemaCollection = $operation instanceof CollectionOperationInterface && 'GET' === $method;
32✔
261
            $schema = new Schema('openapi');
32✔
262
            $schema->setDefinitions($schemas);
32✔
263

264
            $operationOutputSchemas = [];
32✔
265

266
            foreach ($responseMimeTypes as $operationFormat) {
32✔
267
                $operationOutputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection);
32✔
268
                $operationOutputSchemas[$operationFormat] = $operationOutputSchema;
32✔
269
                $this->appendSchemaDefinitions($schemas, $operationOutputSchema->getDefinitions());
32✔
270
            }
271

272
            // Set up parameters
273
            $openapiParameters = $openapiOperation->getParameters();
32✔
274
            foreach ($operation->getUriVariables() ?? [] as $parameterName => $uriVariable) {
32✔
275
                if ($uriVariable->getExpandedValue() ?? false) {
30✔
276
                    continue;
16✔
277
                }
278

279
                $parameter = new Parameter($parameterName, 'path', $uriVariable->getDescription() ?? "$resourceShortName identifier", $uriVariable->getRequired() ?? true, false, false, $uriVariable->getSchema() ?? ['type' => 'string']);
30✔
280

281
                if ($linkParameter = $uriVariable->getOpenApi()) {
30✔
282
                    $parameter = $this->mergeParameter($parameter, $linkParameter);
×
283
                }
284

285
                if ([$i, $operationParameter] = $this->hasParameter($openapiOperation, $parameter)) {
30✔
286
                    $openapiParameters[$i] = $this->mergeParameter($parameter, $operationParameter);
×
287
                    continue;
×
288
                }
289

290
                $openapiParameters[] = $parameter;
30✔
291
            }
292

293
            $openapiOperation = $openapiOperation->withParameters($openapiParameters);
32✔
294

295
            if ($operation instanceof CollectionOperationInterface && 'POST' !== $method) {
32✔
296
                foreach (array_merge($this->getPaginationParameters($operation), $this->getFiltersParameters($operation)) as $parameter) {
32✔
297
                    if ($operationParameter = $this->hasParameter($openapiOperation, $parameter)) {
32✔
298
                        continue;
×
299
                    }
300

301
                    $openapiOperation = $openapiOperation->withParameter($parameter);
32✔
302
                }
303
            }
304

305
            $entityClass = $this->getFilterClass($operation);
32✔
306
            $openapiParameters = $openapiOperation->getParameters();
32✔
307
            foreach ($operation->getParameters() ?? [] as $key => $p) {
32✔
308
                if (false === $p->getOpenApi()) {
18✔
309
                    continue;
18✔
310
                }
311

312
                if (($f = $p->getFilter()) && \is_string($f) && $this->filterLocator && $this->filterLocator->has($f)) {
14✔
313
                    $filter = $this->filterLocator->get($f);
14✔
314

315
                    if ($d = $filter->getDescription($entityClass)) {
14✔
316
                        foreach ($d as $name => $description) {
14✔
317
                            if ($prop = $p->getProperty()) {
14✔
318
                                $name = str_replace($prop, $key, $name);
12✔
319
                            }
320

321
                            $openapiParameters[] = $this->getFilterParameter($name, $description, $operation->getShortName(), $f);
14✔
322
                        }
323

324
                        continue;
14✔
325
                    }
326
                }
327

328
                $in = $p instanceof HeaderParameterInterface ? 'header' : 'query';
14✔
329
                $defaultParameter = new Parameter($key, $in, $p->getDescription() ?? "$resourceShortName $key", $p->getRequired() ?? false, false, false, $p->getSchema() ?? ['type' => 'string']);
14✔
330

331
                $linkParameter = $p->getOpenApi();
14✔
332
                if (null === $linkParameter) {
14✔
333
                    if ([$i, $operationParameter] = $this->hasParameter($openapiOperation, $defaultParameter)) {
14✔
334
                        $openapiParameters[$i] = $this->mergeParameter($defaultParameter, $operationParameter);
×
335
                    } else {
336
                        $openapiParameters[] = $defaultParameter;
14✔
337
                    }
338

339
                    continue;
14✔
340
                }
341

342
                if (\is_array($linkParameter)) {
14✔
343
                    foreach ($linkParameter as $lp) {
12✔
344
                        $parameter = $this->mergeParameter($defaultParameter, $lp);
12✔
345
                        if ([$i, $operationParameter] = $this->hasParameter($openapiOperation, $parameter)) {
12✔
346
                            $openapiParameters[$i] = $this->mergeParameter($parameter, $operationParameter);
×
347
                            continue;
×
348
                        }
349

350
                        $openapiParameters[] = $parameter;
12✔
351
                    }
352
                    continue;
12✔
353
                }
354

355
                $parameter = $this->mergeParameter($defaultParameter, $linkParameter);
14✔
356
                if ([$i, $operationParameter] = $this->hasParameter($openapiOperation, $parameter)) {
14✔
357
                    $openapiParameters[$i] = $this->mergeParameter($parameter, $operationParameter);
×
358
                    continue;
×
359
                }
360
                $openapiParameters[] = $parameter;
14✔
361
            }
362

363
            $openapiOperation = $openapiOperation->withParameters($openapiParameters);
32✔
364
            $existingResponses = $openapiOperation->getResponses() ?: [];
32✔
365
            $overrideResponses = $operation->getExtraProperties()[self::OVERRIDE_OPENAPI_RESPONSES] ?? $this->openApiOptions->getOverrideResponses();
32✔
366
            $errors = null;
32✔
367
            if ($operation instanceof HttpOperation && null !== ($errors = $operation->getErrors())) {
32✔
368
                /** @var array<class-string|string, Error> */
369
                $errorOperations = [];
12✔
370
                foreach ($errors as $error) {
12✔
371
                    $errorOperations[$error] = $this->getErrorResource($error);
12✔
372
                }
373

374
                $openapiOperation = $this->addOperationErrors($openapiOperation, $errorOperations, $resourceMetadataCollection, $schema, $schemas, $operation);
12✔
375
            }
376

377
            if ($overrideResponses || !$existingResponses) {
32✔
378
                // Create responses
379
                switch ($method) {
380
                    case 'GET':
32✔
381
                        $successStatus = (string) $operation->getStatus() ?: 200;
32✔
382
                        $openapiOperation = $this->buildOpenApiResponse($existingResponses, $successStatus, \sprintf('%s %s', $resourceShortName, $operation instanceof CollectionOperationInterface ? 'collection' : 'resource'), $openapiOperation, $operation, $responseMimeTypes, $operationOutputSchemas);
32✔
383
                        break;
32✔
384
                    case 'POST':
28✔
385
                        $successStatus = (string) $operation->getStatus() ?: 201;
28✔
386
                        $openapiOperation = $this->buildOpenApiResponse($existingResponses, $successStatus, \sprintf('%s resource created', $resourceShortName), $openapiOperation, $operation, $responseMimeTypes, $operationOutputSchemas, $resourceMetadataCollection);
28✔
387

388
                        if (null === $errors) {
28✔
389
                            $openapiOperation = $this->addOperationErrors($openapiOperation, [
28✔
390
                                $defaultError->withStatus(400)->withDescription('Invalid input'),
28✔
391
                                $defaultValidationError,
28✔
392
                            ], $resourceMetadataCollection, $schema, $schemas, $operation);
28✔
393
                        }
394
                        break;
28✔
395
                    case 'PATCH':
26✔
396
                    case 'PUT':
26✔
397
                        $successStatus = (string) $operation->getStatus() ?: 200;
26✔
398
                        $openapiOperation = $this->buildOpenApiResponse($existingResponses, $successStatus, \sprintf('%s resource updated', $resourceShortName), $openapiOperation, $operation, $responseMimeTypes, $operationOutputSchemas, $resourceMetadataCollection);
26✔
399

400
                        if (null === $errors) {
26✔
401
                            $openapiOperation = $this->addOperationErrors($openapiOperation, [
26✔
402
                                $defaultError->withStatus(400)->withDescription('Invalid input'),
26✔
403
                                $defaultValidationError,
26✔
404
                            ], $resourceMetadataCollection, $schema, $schemas, $operation);
26✔
405
                        }
406
                        break;
26✔
407
                    case 'DELETE':
26✔
408
                        $successStatus = (string) $operation->getStatus() ?: 204;
26✔
409
                        $openapiOperation = $this->buildOpenApiResponse($existingResponses, $successStatus, \sprintf('%s resource deleted', $resourceShortName), $openapiOperation);
26✔
410
                        break;
26✔
411
                }
412
            }
413

414
            if ($overrideResponses && !isset($existingResponses[403]) && $operation->getSecurity()) {
32✔
415
                $openapiOperation = $this->addOperationErrors($openapiOperation, [
12✔
416
                    $defaultError->withStatus(403)->withDescription('Forbidden'),
12✔
417
                ], $resourceMetadataCollection, $schema, $schemas, $operation);
12✔
418
            }
419

420
            if ($overrideResponses && !$operation instanceof CollectionOperationInterface && 'POST' !== $operation->getMethod() && !isset($existingResponses[404]) && null === $errors) {
32✔
421
                $openapiOperation = $this->addOperationErrors($openapiOperation, [
30✔
422
                    $defaultError->withStatus(404)->withDescription('Not found'),
30✔
423
                ], $resourceMetadataCollection, $schema, $schemas, $operation);
30✔
424
            }
425

426
            if (!$openapiOperation->getResponses()) {
32✔
427
                $openapiOperation = $openapiOperation->withResponse('default', new Response('Unexpected error'));
×
428
            }
429

430
            if (
431
                \in_array($method, ['PATCH', 'PUT', 'POST'], true)
32✔
432
                && !(false === ($input = $operation->getInput()) || (\is_array($input) && null === $input['class']))
32✔
433
            ) {
434
                $content = $openapiOperation->getRequestBody()?->getContent();
28✔
435
                if (null === $content) {
28✔
436
                    $operationInputSchemas = [];
28✔
437
                    foreach ($requestMimeTypes as $operationFormat) {
28✔
438
                        $operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection);
28✔
439
                        $operationInputSchemas[$operationFormat] = $operationInputSchema;
28✔
440
                        $this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions());
28✔
441
                    }
442
                    $content = $this->buildContent($requestMimeTypes, $operationInputSchemas);
28✔
443
                }
444

445
                $openapiOperation = $openapiOperation->withRequestBody(new RequestBody(
28✔
446
                    description: $openapiOperation->getRequestBody()?->getDescription() ?? \sprintf('The %s %s resource', 'POST' === $method ? 'new' : 'updated', $resourceShortName),
28✔
447
                    content: $content,
28✔
448
                    required: $openapiOperation->getRequestBody()?->getRequired() ?? true,
28✔
449
                ));
28✔
450
            }
451

452
            if ($openapiAttribute instanceof Webhook) {
32✔
453
                $webhooks[$openapiAttribute->getName()] = $pathItem->{'with'.ucfirst($method)}($openapiOperation);
12✔
454
                continue;
12✔
455
            }
456

457
            // We merge content types for errors, maybe that this logic could be applied to every resources at some point
458
            if ($operation instanceof Error && ($existingPathItem = $paths->getPath($path)) && ($existingOperation = $existingPathItem->getGet()) && ($currentResponse = $openapiOperation->getResponses()[200] ?? null)) {
32✔
459
                $errorResponse = $existingOperation->getResponses()[200];
×
460
                $currentResponseContent = $currentResponse->getContent();
×
461

462
                foreach ($errorResponse->getContent() as $mime => $content) {
×
463
                    $currentResponseContent[$mime] = $content;
×
464
                }
465

466
                $openapiOperation = $existingOperation->withResponse(200, $currentResponse->withContent($currentResponseContent));
×
467
            }
468

469
            $paths->addPath($path, $pathItem->{'with'.ucfirst($method)}($openapiOperation));
32✔
470
        }
471
    }
472

473
    private function buildOpenApiResponse(array $existingResponses, int|string $status, string $description, ?Operation $openapiOperation = null, ?HttpOperation $operation = null, ?array $responseMimeTypes = null, ?array $operationOutputSchemas = null, ?ResourceMetadataCollection $resourceMetadataCollection = null): Operation
474
    {
475
        if (isset($existingResponses[$status])) {
32✔
476
            return $openapiOperation;
×
477
        }
478
        $responseLinks = $responseContent = null;
32✔
479
        if ($responseMimeTypes && $operationOutputSchemas) {
32✔
480
            $responseContent = $this->buildContent($responseMimeTypes, $operationOutputSchemas);
32✔
481
        }
482
        if ($resourceMetadataCollection && $operation) {
32✔
483
            $responseLinks = $this->getLinks($resourceMetadataCollection, $operation);
30✔
484
        }
485

486
        return $openapiOperation->withResponse($status, new Response($description, $responseContent, null, $responseLinks));
32✔
487
    }
488

489
    /**
490
     * @param array<string, string> $responseMimeTypes
491
     * @param array<string, Schema> $operationSchemas
492
     *
493
     * @return \ArrayObject<MediaType>
494
     */
495
    private function buildContent(array $responseMimeTypes, array $operationSchemas): \ArrayObject
496
    {
497
        /** @var \ArrayObject<MediaType> $content */
498
        $content = new \ArrayObject();
32✔
499

500
        foreach ($responseMimeTypes as $mimeType => $format) {
32✔
501
            $content[$mimeType] = new MediaType(new \ArrayObject($operationSchemas[$format]->getArrayCopy(false)));
32✔
502
        }
503

504
        return $content;
32✔
505
    }
506

507
    /**
508
     * @return array[array<string, string>, array<string, string>]
509
     */
510
    private function getMimeTypes(HttpOperation $operation): array
511
    {
512
        $requestFormats = $operation->getInputFormats() ?: [];
32✔
513
        $responseFormats = $operation->getOutputFormats() ?: [];
32✔
514

515
        $requestMimeTypes = $this->flattenMimeTypes($requestFormats);
32✔
516
        $responseMimeTypes = $this->flattenMimeTypes($responseFormats);
32✔
517

518
        return [$requestMimeTypes, $responseMimeTypes];
32✔
519
    }
520

521
    /**
522
     * @param array<string, string[]> $responseFormats
523
     *
524
     * @return array<string, string>
525
     */
526
    private function flattenMimeTypes(array $responseFormats): array
527
    {
528
        $responseMimeTypes = [];
32✔
529
        foreach ($responseFormats as $responseFormat => $mimeTypes) {
32✔
530
            foreach ($mimeTypes as $mimeType) {
32✔
531
                $responseMimeTypes[$mimeType] = $responseFormat;
32✔
532
            }
533
        }
534

535
        return $responseMimeTypes;
32✔
536
    }
537

538
    /**
539
     * Gets the path for an operation.
540
     *
541
     * If the path ends with the optional _format parameter, it is removed
542
     * as optional path parameters are not yet supported.
543
     *
544
     * @see https://github.com/OAI/OpenAPI-Specification/issues/93
545
     */
546
    private function getPath(string $path): string
547
    {
548
        // Handle either API Platform's URI Template (rfc6570) or Symfony's route
549
        if (str_ends_with($path, '{._format}') || str_ends_with($path, '.{_format}')) {
32✔
550
            $path = substr($path, 0, -10);
32✔
551
        }
552

553
        return str_starts_with($path, '/') ? $path : '/'.$path;
32✔
554
    }
555

556
    private function getPathDescription(string $resourceShortName, string $method, bool $isCollection): string
557
    {
558
        switch ($method) {
559
            case 'GET':
32✔
560
                $pathSummary = $isCollection ? 'Retrieves the collection of %s resources.' : 'Retrieves a %s resource.';
32✔
561
                break;
32✔
562
            case 'POST':
28✔
563
                $pathSummary = 'Creates a %s resource.';
28✔
564
                break;
28✔
565
            case 'PATCH':
26✔
566
                $pathSummary = 'Updates the %s resource.';
26✔
567
                break;
26✔
568
            case 'PUT':
26✔
569
                $pathSummary = 'Replaces the %s resource.';
24✔
570
                break;
24✔
571
            case 'DELETE':
26✔
572
                $pathSummary = 'Removes the %s resource.';
26✔
573
                break;
26✔
574
            default:
575
                return $resourceShortName;
×
576
        }
577

578
        return \sprintf($pathSummary, $resourceShortName);
32✔
579
    }
580

581
    /**
582
     * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#linkObject.
583
     *
584
     * @return \ArrayObject<Link>
585
     */
586
    private function getLinks(ResourceMetadataCollection $resourceMetadataCollection, HttpOperation $currentOperation): \ArrayObject
587
    {
588
        /** @var \ArrayObject<Link> $links */
589
        $links = new \ArrayObject();
30✔
590

591
        // Only compute get links for now
592
        foreach ($resourceMetadataCollection as $resource) {
30✔
593
            foreach ($resource->getOperations() as $operationName => $operation) {
30✔
594
                $parameters = [];
30✔
595
                $method = $operation instanceof HttpOperation ? $operation->getMethod() : 'GET';
30✔
596
                if (
597
                    $operationName === $operation->getName()
30✔
598
                    || isset($links[$operationName])
30✔
599
                    || $operation instanceof CollectionOperationInterface
30✔
600
                    || 'GET' !== $method
30✔
601
                ) {
602
                    continue;
30✔
603
                }
604

605
                // Operation ignored from OpenApi
606
                if ($operation instanceof HttpOperation && (false === $operation->getOpenapi() || $operation->getOpenapi() instanceof Webhook)) {
×
607
                    continue;
×
608
                }
609

610
                $operationUriVariables = $operation->getUriVariables();
×
611
                foreach ($currentOperation->getUriVariables() ?? [] as $parameterName => $uriVariableDefinition) {
×
612
                    if (!isset($operationUriVariables[$parameterName])) {
×
613
                        continue;
×
614
                    }
615

616
                    if ($operationUriVariables[$parameterName]->getIdentifiers() === $uriVariableDefinition->getIdentifiers() && $operationUriVariables[$parameterName]->getFromClass() === $uriVariableDefinition->getFromClass()) {
×
617
                        $parameters[$parameterName] = '$request.path.'.($uriVariableDefinition->getIdentifiers()[0] ?? 'id');
×
618
                    }
619
                }
620

621
                foreach ($operationUriVariables ?? [] as $parameterName => $uriVariableDefinition) {
×
622
                    if (isset($parameters[$parameterName])) {
×
623
                        continue;
×
624
                    }
625

626
                    if ($uriVariableDefinition->getFromClass() === $currentOperation->getClass()) {
×
627
                        $parameters[$parameterName] = '$response.body#/'.($uriVariableDefinition->getIdentifiers()[0] ?? 'id');
×
628
                    }
629
                }
630

631
                $links[$operationName] = new Link(
×
632
                    $operationName,
×
633
                    new \ArrayObject($parameters),
×
634
                    null,
×
635
                    $operation->getDescription() ?? ''
×
636
                );
×
637
            }
638
        }
639

640
        return $links;
30✔
641
    }
642

643
    /**
644
     * Gets parameters corresponding to enabled filters.
645
     */
646
    private function getFiltersParameters(CollectionOperationInterface|HttpOperation $operation): array
647
    {
648
        $parameters = [];
32✔
649
        $resourceFilters = $operation->getFilters();
32✔
650
        $entityClass = $this->getFilterClass($operation);
32✔
651

652
        foreach ($resourceFilters ?? [] as $filterId) {
32✔
653
            if (!$this->filterLocator->has($filterId)) {
16✔
654
                continue;
×
655
            }
656

657
            $filter = $this->filterLocator->get($filterId);
16✔
658
            foreach ($filter->getDescription($entityClass) as $name => $description) {
16✔
659
                $parameters[] = $this->getFilterParameter($name, $description, $operation->getShortName(), $filterId);
16✔
660
            }
661
        }
662

663
        return $parameters;
32✔
664
    }
665

666
    private function getFilterClass(HttpOperation $operation): ?string
667
    {
668
        $entityClass = $operation->getClass();
32✔
669
        if ($options = $operation->getStateOptions()) {
32✔
670
            if ($options instanceof DoctrineOptions && $options->getEntityClass()) {
16✔
671
                return $options->getEntityClass();
12✔
672
            }
673

674
            if ($options instanceof DoctrineODMOptions && $options->getDocumentClass()) {
16✔
675
                return $options->getDocumentClass();
12✔
676
            }
677
        }
678

679
        return $entityClass;
32✔
680
    }
681

682
    /**
683
     * @param array<string, mixed> $description
684
     */
685
    private function getFilterParameter(string $name, array $description, string $shortName, string $filter): Parameter
686
    {
687
        if (isset($description['swagger'])) {
18✔
688
            trigger_deprecation('api-platform/core', '4.0', \sprintf('Using the "swagger" field of the %s::getDescription() (%s) is deprecated.', $filter, $shortName));
×
689
        }
690

691
        if (!isset($description['openapi']) || $description['openapi'] instanceof Parameter) {
18✔
692
            $schema = $description['schema'] ?? [];
18✔
693

694
            if (isset($description['type']) && \in_array($description['type'], Type::$builtinTypes, true) && !isset($schema['type'])) {
18✔
695
                $schema += $this->getType(new Type($description['type'], false, null, $description['is_collection'] ?? false));
18✔
696
            }
697

698
            if (!isset($schema['type'])) {
18✔
699
                $schema['type'] = 'string';
16✔
700
            }
701

702
            $style = 'array' === ($schema['type'] ?? null) && \in_array(
18✔
703
                $description['type'],
18✔
704
                [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT],
18✔
705
                true
18✔
706
            ) ? 'deepObject' : 'form';
18✔
707

708
            $parameter = isset($description['openapi']) && $description['openapi'] instanceof Parameter ? $description['openapi'] : new Parameter(in: 'query', name: $name, style: $style, explode: $description['is_collection'] ?? false);
18✔
709

710
            if ('' === $parameter->getDescription() && ($str = $description['description'] ?? '')) {
18✔
711
                $parameter = $parameter->withDescription($str);
×
712
            }
713

714
            if (false === $parameter->getRequired() && false !== ($required = $description['required'] ?? false)) {
18✔
715
                $parameter = $parameter->withRequired($required);
12✔
716
            }
717

718
            return $parameter->withSchema($schema);
18✔
719
        }
720

721
        trigger_deprecation('api-platform/core', '4.0', \sprintf('Not using "%s" on the "openapi" field of the %s::getDescription() (%s) is deprecated.', Parameter::class, $filter, $shortName));
×
722
        $schema = $description['schema'] ?? (\in_array($description['type'], Type::$builtinTypes, true) ? $this->getType(new Type($description['type'], false, null, $description['is_collection'] ?? false)) : ['type' => 'string']);
×
723

724
        return new Parameter(
×
725
            $name,
×
726
            'query',
×
727
            $description['description'] ?? '',
×
728
            $description['required'] ?? false,
×
729
            $description['openapi']['deprecated'] ?? false,
×
730
            $description['openapi']['allowEmptyValue'] ?? true,
×
731
            $schema,
×
732
            'array' === $schema['type'] && \in_array(
×
733
                $description['type'],
×
734
                [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT],
×
735
                true
×
736
            ) ? 'deepObject' : 'form',
×
737
            $description['openapi']['explode'] ?? ('array' === $schema['type']),
×
738
            $description['openapi']['allowReserved'] ?? false,
×
739
            $description['openapi']['example'] ?? null,
×
740
            isset(
×
741
                $description['openapi']['examples']
×
742
            ) ? new \ArrayObject($description['openapi']['examples']) : null
×
743
        );
×
744
    }
745

746
    private function getPaginationParameters(CollectionOperationInterface|HttpOperation $operation): array
747
    {
748
        if (!$this->paginationOptions->isPaginationEnabled()) {
32✔
749
            return [];
×
750
        }
751

752
        $parameters = [];
32✔
753

754
        if ($operation->getPaginationEnabled() ?? $this->paginationOptions->isPaginationEnabled()) {
32✔
755
            $parameters[] = new Parameter($this->paginationOptions->getPaginationPageParameterName(), 'query', 'The collection page number', false, false, true, ['type' => 'integer', 'default' => 1]);
32✔
756

757
            if ($operation->getPaginationClientItemsPerPage() ?? $this->paginationOptions->getClientItemsPerPage()) {
32✔
758
                $schema = [
32✔
759
                    'type' => 'integer',
32✔
760
                    'default' => $operation->getPaginationItemsPerPage() ?? $this->paginationOptions->getItemsPerPage(),
32✔
761
                    'minimum' => 0,
32✔
762
                ];
32✔
763

764
                if (null !== $maxItemsPerPage = ($operation->getPaginationMaximumItemsPerPage() ?? $this->paginationOptions->getMaximumItemsPerPage())) {
32✔
UNCOV
765
                    $schema['maximum'] = $maxItemsPerPage;
×
766
                }
767

768
                $parameters[] = new Parameter($this->paginationOptions->getItemsPerPageParameterName(), 'query', 'The number of items per page', false, false, true, $schema);
32✔
769
            }
770
        }
771

772
        if ($operation->getPaginationClientEnabled() ?? $this->paginationOptions->isPaginationClientEnabled()) {
32✔
773
            $parameters[] = new Parameter($this->paginationOptions->getPaginationClientEnabledParameterName(), 'query', 'Enable or disable pagination', false, false, true, ['type' => 'boolean']);
32✔
774
        }
775

776
        return $parameters;
32✔
777
    }
778

779
    private function getOauthSecurityScheme(): SecurityScheme
780
    {
781
        $oauthFlow = new OAuthFlow($this->openApiOptions->getOAuthAuthorizationUrl(), $this->openApiOptions->getOAuthTokenUrl() ?: null, $this->openApiOptions->getOAuthRefreshUrl() ?: null, new \ArrayObject($this->openApiOptions->getOAuthScopes()));
32✔
782
        $description = \sprintf(
32✔
783
            'OAuth 2.0 %s Grant',
32✔
784
            strtolower(preg_replace('/[A-Z]/', ' \\0', lcfirst($this->openApiOptions->getOAuthFlow())))
32✔
785
        );
32✔
786
        $implicit = $password = $clientCredentials = $authorizationCode = null;
32✔
787

788
        switch ($this->openApiOptions->getOAuthFlow()) {
32✔
789
            case 'implicit':
32✔
790
                $implicit = $oauthFlow;
32✔
791
                break;
32✔
792
            case 'password':
×
793
                $password = $oauthFlow;
×
794
                break;
×
795
            case 'application':
×
796
            case 'clientCredentials':
×
797
                $clientCredentials = $oauthFlow;
×
798
                break;
×
799
            case 'accessCode':
×
800
            case 'authorizationCode':
×
801
                $authorizationCode = $oauthFlow;
×
802
                break;
×
803
            default:
804
                throw new \LogicException('OAuth flow must be one of: implicit, password, clientCredentials, authorizationCode');
×
805
        }
806

807
        return new SecurityScheme($this->openApiOptions->getOAuthType(), $description, null, null, null, null, new OAuthFlows($implicit, $password, $clientCredentials, $authorizationCode), null);
32✔
808
    }
809

810
    private function getSecuritySchemes(): array
811
    {
812
        $securitySchemes = [];
32✔
813

814
        if ($this->openApiOptions->getOAuthEnabled()) {
32✔
815
            $securitySchemes['oauth'] = $this->getOauthSecurityScheme();
32✔
816
        }
817

818
        foreach ($this->openApiOptions->getApiKeys() as $key => $apiKey) {
32✔
819
            $description = \sprintf('Value for the %s %s parameter.', $apiKey['name'], $apiKey['type']);
32✔
820
            $securitySchemes[$key] = new SecurityScheme('apiKey', $description, $apiKey['name'], $apiKey['type']);
32✔
821
        }
822

823
        foreach ($this->openApiOptions->getHttpAuth() as $key => $httpAuth) {
32✔
824
            $description = \sprintf('Value for the http %s parameter.', $httpAuth['scheme']);
×
825
            $securitySchemes[$key] = new SecurityScheme('http', $description, null, null, $httpAuth['scheme'], $httpAuth['bearerFormat'] ?? null);
×
826
        }
827

828
        return $securitySchemes;
32✔
829
    }
830

831
    /**
832
     * @param \ArrayObject<string, mixed> $schemas
833
     * @param \ArrayObject<string, mixed> $definitions
834
     */
835
    private function appendSchemaDefinitions(\ArrayObject $schemas, \ArrayObject $definitions): void
836
    {
837
        foreach ($definitions as $key => $value) {
32✔
838
            $schemas[$key] = $value;
32✔
839
        }
840
    }
841

842
    /**
843
     * @return array{0: int, 1: Parameter}|null
844
     */
845
    private function hasParameter(Operation $operation, Parameter $parameter): ?array
846
    {
847
        foreach ($operation->getParameters() as $key => $existingParameter) {
32✔
848
            if ($existingParameter->getName() === $parameter->getName() && $existingParameter->getIn() === $parameter->getIn()) {
32✔
849
                return [$key, $existingParameter];
×
850
            }
851
        }
852

853
        return null;
32✔
854
    }
855

856
    private function mergeParameter(Parameter $actual, Parameter $defined): Parameter
857
    {
858
        foreach (
859
            [
14✔
860
                'name',
14✔
861
                'in',
14✔
862
                'description',
14✔
863
                'required',
14✔
864
                'deprecated',
14✔
865
                'allowEmptyValue',
14✔
866
                'style',
14✔
867
                'explode',
14✔
868
                'allowReserved',
14✔
869
                'example',
14✔
870
            ] as $method
14✔
871
        ) {
872
            $newValue = $defined->{"get$method"}();
14✔
873
            if (null !== $newValue && $actual->{"get$method"}() !== $newValue) {
14✔
874
                $actual = $actual->{"with$method"}($newValue);
14✔
875
            }
876
        }
877

878
        foreach (['examples', 'content', 'schema'] as $method) {
14✔
879
            $newValue = $defined->{"get$method"}();
14✔
880
            if ($newValue && \count($newValue) > 0 && $actual->{"get$method"}() !== $newValue) {
14✔
881
                $actual = $actual->{"with$method"}($newValue);
×
882
            }
883
        }
884

885
        return $actual;
14✔
886
    }
887

888
    /**
889
     * @param ErrorResource[]              $errors
890
     * @param \ArrayObject<string, Schema> $schemas
891
     */
892
    private function addOperationErrors(
893
        Operation $operation,
894
        array $errors,
895
        ResourceMetadataCollection $resourceMetadataCollection,
896
        Schema $schema,
897
        \ArrayObject $schemas,
898
        HttpOperation $originalOperation,
899
    ): Operation {
900
        foreach ($errors as $errorResource) {
30✔
901
            $responseMimeTypes = $this->flattenMimeTypes($errorResource->getOutputFormats() ?: $this->errorFormats);
30✔
902
            foreach ($errorResource->getOperations() as $errorOperation) {
30✔
903
                if (false === $errorOperation->getOpenApi()) {
30✔
904
                    continue;
30✔
905
                }
906

907
                $responseMimeTypes += $this->flattenMimeTypes($errorOperation->getOutputFormats() ?: $this->errorFormats);
12✔
908
            }
909

910
            foreach ($responseMimeTypes as $mime => $format) {
30✔
911
                if (!isset($this->errorFormats[$format])) {
30✔
912
                    unset($responseMimeTypes[$mime]);
×
913
                }
914
            }
915

916
            $operationErrorSchemas = [];
30✔
917
            foreach ($responseMimeTypes as $operationFormat) {
30✔
918
                $operationErrorSchema = $this->jsonSchemaFactory->buildSchema($errorResource->getClass(), $operationFormat, Schema::TYPE_OUTPUT, null, $schema);
30✔
919
                $operationErrorSchemas[$operationFormat] = $operationErrorSchema;
30✔
920
                $this->appendSchemaDefinitions($schemas, $operationErrorSchema->getDefinitions());
30✔
921
            }
922

923
            if (!$status = $errorResource->getStatus()) {
30✔
924
                throw new RuntimeException(\sprintf('The error class "%s" has no status defined, please either implement ProblemExceptionInterface, or make it an ErrorResource with a status', $errorResource->getClass()));
×
925
            }
926

927
            $operation = $this->buildOpenApiResponse($operation->getResponses() ?: [], $status, $errorResource->getDescription() ?? '', $operation, $originalOperation, $responseMimeTypes, $operationErrorSchemas, $resourceMetadataCollection);
30✔
928
        }
929

930
        return $operation;
30✔
931
    }
932

933
    /**
934
     * @param string|class-string $error
935
     */
936
    private function getErrorResource(string $error, ?int $status = null, ?string $description = null): ErrorResource
937
    {
938
        if ($this->localErrorResourceCache[$error] ?? null) {
32✔
939
            return $this->localErrorResourceCache[$error];
32✔
940
        }
941

942
        if (is_a($error, ProblemExceptionInterface::class, true)) {
32✔
943
            try {
944
                /** @var ProblemExceptionInterface $exception */
945
                $exception = new $error();
32✔
946
                $status = $exception->getStatus();
32✔
947
                $description = $exception->getTitle();
32✔
948
            } catch (\TypeError) {
32✔
949
            }
950
        } elseif (class_exists($error)) {
×
951
            throw new RuntimeException(\sprintf('The error class "%s" does not implement "%s". Did you forget a use statement?', $error, ProblemExceptionInterface::class));
×
952
        }
953

954
        $defaultErrorResourceClass = $this->openApiOptions->getErrorResourceClass() ?? ApiResourceError::class;
32✔
955

956
        try {
957
            $errorResource = $this->resourceMetadataFactory->create($error)[0] ?? new ErrorResource(status: $status, description: $description, class: $defaultErrorResourceClass);
32✔
958
            if (!($errorResource instanceof ErrorResource)) {
32✔
959
                throw new RuntimeException(\sprintf('The error class %s is not an ErrorResource', $error));
×
960
            }
961

962
            // Here we want the exception status and expression to override the resource one when available
963
            if ($status) {
32✔
964
                $errorResource = $errorResource->withStatus($status);
32✔
965
            }
966

967
            if ($description) {
32✔
968
                $errorResource = $errorResource->withDescription($description);
32✔
969
            }
970
        } catch (ResourceClassNotFoundException|OperationNotFoundException) {
×
971
            $errorResource = new ErrorResource(status: $status, description: $description, class: $defaultErrorResourceClass);
×
972
        }
973

974
        if (!$errorResource->getClass()) {
32✔
975
            $errorResource = $errorResource->withClass($error);
×
976
        }
977

978
        return $this->localErrorResourceCache[$error] = $errorResource;
32✔
979
    }
980
}
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