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

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 hits per line

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

63.08
/src/JsonSchema/SchemaFactory.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\JsonSchema;
15

16
use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory;
17
use ApiPlatform\Metadata\ApiProperty;
18
use ApiPlatform\Metadata\CollectionOperationInterface;
19
use ApiPlatform\Metadata\HttpOperation;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
22
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
23
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
24
use ApiPlatform\Metadata\ResourceClassResolverInterface;
25
use ApiPlatform\Metadata\Util\TypeHelper;
26
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
27
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
28
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
29
use Symfony\Component\TypeInfo\Type\BuiltinType;
30
use Symfony\Component\TypeInfo\Type\CollectionType;
31
use Symfony\Component\TypeInfo\Type\CompositeTypeInterface;
32
use Symfony\Component\TypeInfo\Type\GenericType;
33
use Symfony\Component\TypeInfo\Type\ObjectType;
34
use Symfony\Component\TypeInfo\TypeIdentifier;
35

36
/**
37
 * {@inheritdoc}
38
 *
39
 * @author Kévin Dunglas <dunglas@gmail.com>
40
 */
41
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface
42
{
43
    use ResourceMetadataTrait;
44
    use SchemaUriPrefixTrait;
45

46
    private const JSON_MERGE_PATCH_SCHEMA_POSTFIX = '.jsonMergePatch';
47

48
    private ?SchemaFactoryInterface $schemaFactory = null;
49
    // Edge case where the related resource is not readable (for example: NotExposed) but we have groups to read the whole related object
50
    public const OPENAPI_DEFINITION_NAME = 'openapi_definition_name';
51

52
    public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, private readonly ?NameConverterInterface $nameConverter = null, ?ResourceClassResolverInterface $resourceClassResolver = null, ?array $distinctFormats = null, private ?DefinitionNameFactoryInterface $definitionNameFactory = null)
53
    {
54
        if (!$definitionNameFactory) {
699✔
UNCOV
55
            $this->definitionNameFactory = new DefinitionNameFactory($distinctFormats);
×
56
        }
57

58
        $this->resourceMetadataFactory = $resourceMetadataFactory;
699✔
59
        $this->resourceClassResolver = $resourceClassResolver;
699✔
60
    }
61

62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function buildSchema(string $className, string $format = 'json', string $type = Schema::TYPE_OUTPUT, ?Operation $operation = null, ?Schema $schema = null, ?array $serializerContext = null, bool $forceCollection = false): Schema
66
    {
67
        $schema = $schema ? clone $schema : new Schema();
118✔
68

69
        if (!$this->isResourceClass($className)) {
118✔
70
            $operation = null;
56✔
71
            $inputOrOutputClass = $className;
56✔
72
            $serializerContext ??= [];
56✔
73
        } else {
74
            $operation = $this->findOperation($className, $type, $operation, $serializerContext, $format);
104✔
75
            $inputOrOutputClass = $this->findOutputClass($className, $type, $operation, $serializerContext);
104✔
76
            $serializerContext ??= $this->getSerializerContext($operation, $type);
104✔
77
        }
78

79
        if (null === $inputOrOutputClass) {
118✔
80
            // input or output disabled
UNCOV
81
            return $schema;
×
82
        }
83

84
        $validationGroups = $operation ? $this->getValidationGroups($operation) : [];
118✔
85
        $version = $schema->getVersion();
118✔
86
        $definitionName = $this->definitionNameFactory->create($className, $format, $inputOrOutputClass, $operation, $serializerContext);
118✔
87
        $method = $operation instanceof HttpOperation ? $operation->getMethod() : 'GET';
118✔
88
        if (!$operation) {
118✔
89
            $method = Schema::TYPE_INPUT === $type ? 'POST' : 'GET';
56✔
90
        }
91

92
        // In case of FORCE_SUBSCHEMA an object can be writable through another class even though it has no POST operation
93
        if (!($serializerContext[self::FORCE_SUBSCHEMA] ?? false) && Schema::TYPE_OUTPUT !== $type && !\in_array($method, ['POST', 'PATCH', 'PUT'], true)) {
118✔
UNCOV
94
            return $schema;
×
95
        }
96

97
        $isJsonMergePatch = 'json' === $format && 'PATCH' === $method && Schema::TYPE_INPUT === $type;
118✔
98
        if ($isJsonMergePatch) {
118✔
99
            $definitionName .= self::JSON_MERGE_PATCH_SCHEMA_POSTFIX;
16✔
100
        }
101

102
        if (!isset($schema['$ref']) && !isset($schema['type'])) {
118✔
103
            $ref = $this->getSchemaUriPrefix($version).$definitionName;
118✔
104
            if ($forceCollection || ('POST' !== $method && $operation instanceof CollectionOperationInterface)) {
118✔
105
                $schema['type'] = 'array';
52✔
106
                $schema['items'] = ['$ref' => $ref];
52✔
107
            } else {
108
                $schema['$ref'] = $ref;
108✔
109
            }
110
        }
111

112
        $definitions = $schema->getDefinitions();
118✔
113
        if (isset($definitions[$definitionName])) {
118✔
114
            // Already computed
115
            return $schema;
38✔
116
        }
117

118
        /** @var \ArrayObject<string, mixed> $definition */
119
        $definition = new \ArrayObject(['type' => 'object']);
118✔
120
        $definitions[$definitionName] = $definition;
118✔
121
        if ($description = $operation?->getDescription()) {
118✔
122
            $definition['description'] = $description;
54✔
123
        }
124

125
        // additionalProperties are allowed by default, so it does not need to be set explicitly, unless allow_extra_attributes is false
126
        // See https://json-schema.org/understanding-json-schema/reference/object.html#properties
127
        if (false === ($serializerContext[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES] ?? true)) {
118✔
UNCOV
128
            $definition['additionalProperties'] = false;
×
129
        }
130

131
        // see https://github.com/json-schema-org/json-schema-spec/pull/737
132
        if (Schema::VERSION_SWAGGER !== $version && $operation && $operation->getDeprecationReason()) {
118✔
UNCOV
133
            $definition['deprecated'] = true;
×
134
        }
135

136
        // externalDocs is an OpenAPI specific extension, but JSON Schema allows additional keys, so we always add it
137
        // See https://json-schema.org/latest/json-schema-core.html#rfc.section.6.4
138
        if ($operation instanceof HttpOperation && ($operation->getTypes()[0] ?? null)) {
118✔
139
            $definition['externalDocs'] = ['url' => $operation->getTypes()[0]];
6✔
140
        }
141

142
        $options = ['schema_type' => $type] + $this->getFactoryOptions($serializerContext, $validationGroups, $operation instanceof HttpOperation ? $operation : null);
118✔
143
        foreach ($this->propertyNameCollectionFactory->create($inputOrOutputClass, $options) as $propertyName) {
118✔
144
            $propertyMetadata = $this->propertyMetadataFactory->create($inputOrOutputClass, $propertyName, $options);
118✔
145

146
            if (false === $propertyMetadata->isReadable() && false === $propertyMetadata->isWritable()) {
118✔
147
                continue;
28✔
148
            }
149

150
            $normalizedPropertyName = $this->nameConverter ? $this->nameConverter->normalize($propertyName, $inputOrOutputClass, $format, $serializerContext) : $propertyName;
118✔
151
            if ($propertyMetadata->isRequired() && !$isJsonMergePatch) {
118✔
152
                $definition['required'][] = $normalizedPropertyName;
24✔
153
            }
154

155
            if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
118✔
UNCOV
156
                $this->buildLegacyPropertySchema($schema, $definitionName, $normalizedPropertyName, $propertyMetadata, $serializerContext, $format, $type);
×
157
            } else {
158
                $this->buildPropertySchema($schema, $definitionName, $normalizedPropertyName, $propertyMetadata, $serializerContext, $format, $type);
118✔
159
            }
160
        }
161

162
        return $schema;
118✔
163
    }
164

165
    /**
166
     * Builds the JSON Schema for a property using the legacy PropertyInfo component.
167
     */
168
    private function buildLegacyPropertySchema(Schema $schema, string $definitionName, string $normalizedPropertyName, ApiProperty $propertyMetadata, array $serializerContext, string $format, string $parentType): void
169
    {
UNCOV
170
        $version = $schema->getVersion();
×
UNCOV
171
        if (Schema::VERSION_SWAGGER === $version || Schema::VERSION_OPENAPI === $version) {
×
UNCOV
172
            $additionalPropertySchema = $propertyMetadata->getOpenapiContext();
×
173
        } else {
UNCOV
174
            $additionalPropertySchema = $propertyMetadata->getJsonSchemaContext();
×
175
        }
176

UNCOV
177
        $propertySchema = array_merge(
×
UNCOV
178
            $propertyMetadata->getSchema() ?? [],
×
UNCOV
179
            $additionalPropertySchema ?? []
×
UNCOV
180
        );
×
181

182
        // @see https://github.com/api-platform/core/issues/6299
UNCOV
183
        if (Schema::UNKNOWN_TYPE === ($propertySchema['type'] ?? null) && isset($propertySchema['$ref'])) {
×
UNCOV
184
            unset($propertySchema['type']);
×
185
        }
186

UNCOV
187
        $extraProperties = $propertyMetadata->getExtraProperties();
×
188
        // see AttributePropertyMetadataFactory
UNCOV
189
        if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
×
190
            // schema seems to have been declared by the user: do not override nor complete user value
UNCOV
191
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
×
192

UNCOV
193
            return;
×
194
        }
195

UNCOV
196
        $types = $propertyMetadata->getBuiltinTypes() ?? [];
×
197

198
        // never override the following keys if at least one is already set
199
        // or if property has no type(s) defined
200
        // or if property schema is already fully defined (type=string + format || enum)
UNCOV
201
        $propertySchemaType = $propertySchema['type'] ?? false;
×
202

UNCOV
203
        $isUnknown = Schema::UNKNOWN_TYPE === $propertySchemaType
×
UNCOV
204
            || ('array' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['items']['type'] ?? null))
×
UNCOV
205
            || ('object' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['additionalProperties']['type'] ?? null));
×
206

207
        // Scalar properties
208
        if (
UNCOV
209
            !$isUnknown && (
×
UNCOV
210
                [] === $types
×
UNCOV
211
                || ($propertySchema['$ref'] ?? $propertySchema['anyOf'] ?? $propertySchema['allOf'] ?? $propertySchema['oneOf'] ?? false)
×
UNCOV
212
                || (\is_array($propertySchemaType) ? \array_key_exists('string', $propertySchemaType) : 'string' !== $propertySchemaType)
×
UNCOV
213
                || ($propertySchema['format'] ?? $propertySchema['enum'] ?? false)
×
214
            )
215
        ) {
UNCOV
216
            if (isset($propertySchema['$ref'])) {
×
UNCOV
217
                unset($propertySchema['type']);
×
218
            }
219

UNCOV
220
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
×
221

222
            return;
×
223
        }
224

225
        // property schema is created in SchemaPropertyMetadataFactory, but it cannot build resource reference ($ref)
226
        // complete property schema with resource reference ($ref) only if it's related to an object
UNCOV
227
        $version = $schema->getVersion();
×
UNCOV
228
        $refs = [];
×
UNCOV
229
        $isNullable = null;
×
230

UNCOV
231
        foreach ($types as $type) {
×
UNCOV
232
            $subSchema = new Schema($version);
×
UNCOV
233
            $subSchema->setDefinitions($schema->getDefinitions()); // Populate definitions of the main schema
×
234

UNCOV
235
            $isCollection = $type->isCollection();
×
UNCOV
236
            if ($isCollection) {
×
UNCOV
237
                $valueType = $type->getCollectionValueTypes()[0] ?? null;
×
238
            } else {
UNCOV
239
                $valueType = $type;
×
240
            }
241

UNCOV
242
            $className = $valueType?->getClassName();
×
UNCOV
243
            if (null === $className) {
×
UNCOV
244
                continue;
×
245
            }
246

UNCOV
247
            $subSchemaFactory = $this->schemaFactory ?: $this;
×
UNCOV
248
            $subSchema = $subSchemaFactory->buildSchema($className, $format, $parentType, null, $subSchema, $serializerContext + [self::FORCE_SUBSCHEMA => true], false);
×
UNCOV
249
            if (!isset($subSchema['$ref'])) {
×
UNCOV
250
                continue;
×
251
            }
252

UNCOV
253
            if (false === $propertyMetadata->getGenId()) {
×
UNCOV
254
                $subDefinitionName = $this->definitionNameFactory->create($className, $format, $className, null, $serializerContext);
×
255

UNCOV
256
                if (isset($subSchema->getDefinitions()[$subDefinitionName])) {
×
257
                    // @see https://github.com/api-platform/core/issues/7162
258
                    // Need to rebuild the definition without @id property and set it back to the sub-schema
UNCOV
259
                    $subSchemaDefinition = $subSchema->getDefinitions()[$subDefinitionName]->getArrayCopy();
×
UNCOV
260
                    unset($subSchemaDefinition['properties']['@id']);
×
UNCOV
261
                    $subSchema->getDefinitions()[$subDefinitionName] = new \ArrayObject($subSchemaDefinition);
×
262
                }
263
            }
264

UNCOV
265
            if ($isCollection) {
×
UNCOV
266
                $key = ($propertySchema['type'] ?? null) === 'object' ? 'additionalProperties' : 'items';
×
UNCOV
267
                $propertySchema[$key]['$ref'] = $subSchema['$ref'];
×
UNCOV
268
                unset($propertySchema[$key]['type']);
×
UNCOV
269
                break;
×
270
            }
271

UNCOV
272
            $refs[] = ['$ref' => $subSchema['$ref']];
×
UNCOV
273
            $isNullable = $isNullable ?? $type->isNullable();
×
274
        }
275

UNCOV
276
        if ($isNullable) {
×
UNCOV
277
            $refs[] = ['type' => 'null'];
×
278
        }
279

UNCOV
280
        $c = \count($refs);
×
UNCOV
281
        if ($c > 1) {
×
UNCOV
282
            $propertySchema['anyOf'] = $refs;
×
UNCOV
283
            unset($propertySchema['type']);
×
UNCOV
284
        } elseif (1 === $c) {
×
UNCOV
285
            $propertySchema['$ref'] = $refs[0]['$ref'];
×
UNCOV
286
            unset($propertySchema['type']);
×
287
        }
288

UNCOV
289
        $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
×
290
    }
291

292
    private function buildPropertySchema(Schema $schema, string $definitionName, string $normalizedPropertyName, ApiProperty $propertyMetadata, array $serializerContext, string $format, string $parentType): void
293
    {
294
        $version = $schema->getVersion();
118✔
295
        if (Schema::VERSION_SWAGGER === $version || Schema::VERSION_OPENAPI === $version) {
118✔
296
            $additionalPropertySchema = $propertyMetadata->getOpenapiContext();
22✔
297
        } else {
298
            $additionalPropertySchema = $propertyMetadata->getJsonSchemaContext();
96✔
299
        }
300

301
        $propertySchema = array_merge(
118✔
302
            $propertyMetadata->getSchema() ?? [],
118✔
303
            $additionalPropertySchema ?? []
118✔
304
        );
118✔
305

306
        $extraProperties = $propertyMetadata->getExtraProperties();
118✔
307
        // see AttributePropertyMetadataFactory
308
        if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
118✔
309
            // schema seems to have been declared by the user: do not override nor complete user value
310
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
32✔
311

312
            return;
32✔
313
        }
314

315
        $type = $propertyMetadata->getNativeType();
118✔
316

317
        // Type is defined in an allOf, anyOf, or oneOf
318
        $propertySchemaType = $this->getSchemaValue($propertySchema, 'type');
118✔
319
        $currentRef = $this->getSchemaValue($propertySchema, '$ref');
118✔
320
        $isSchemaDefined = null !== ($currentRef ?? $this->getSchemaValue($propertySchema, 'format') ?? $this->getSchemaValue($propertySchema, 'enum'));
118✔
321
        if (!$isSchemaDefined && Schema::UNKNOWN_TYPE !== $propertySchemaType) {
118✔
322
            $isSchemaDefined = true;
116✔
323
        }
324

325
        // Check if the type is considered "unknown" by SchemaPropertyMetadataFactory
326
        if (isset($propertySchema['additionalProperties']['type']) && Schema::UNKNOWN_TYPE === $propertySchema['additionalProperties']['type']) {
118✔
327
            $isSchemaDefined = false;
6✔
328
        }
329

330
        if ($isSchemaDefined && Schema::UNKNOWN_TYPE !== $propertySchemaType) {
118✔
331
            // If schema is defined and not marked as unknown, or if no type info exists, return early
332
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
118✔
333

334
            return;
118✔
335
        }
336

337
        if (Schema::UNKNOWN_TYPE === $propertySchemaType) {
64✔
338
            $propertySchema = [];
64✔
339
        }
340

341
        // property schema is created in SchemaPropertyMetadataFactory, but it cannot build resource reference ($ref)
342
        // complete property schema with resource reference ($ref) if it's related to an object/resource
343
        $refs = [];
64✔
344
        $isNullable = $type?->isNullable() ?? false;
64✔
345

346
        // TODO: refactor this with TypeInfo we shouldn't have to loop like this, the below code handles object refs
347
        if ($type) {
64✔
348
            foreach ($type instanceof CompositeTypeInterface ? $type->getTypes() : [$type] as $t) {
64✔
349
                if ($t instanceof BuiltinType && TypeIdentifier::NULL === $t->getTypeIdentifier()) {
64✔
350
                    continue;
26✔
351
                }
352

353
                $valueType = $t;
64✔
354
                $isCollection = $t instanceof CollectionType;
64✔
355

356
                if ($isCollection) {
64✔
357
                    $valueType = TypeHelper::getCollectionValueType($t);
38✔
358
                }
359

360
                if (!$valueType instanceof ObjectType && !$valueType instanceof GenericType) {
64✔
UNCOV
361
                    continue;
×
362
                }
363

364
                if ($valueType instanceof ObjectType) {
64✔
365
                    $className = $valueType->getClassName();
64✔
366
                } else {
367
                    // GenericType
UNCOV
368
                    $className = $valueType->getWrappedType()->getClassName();
×
369
                }
370

371
                $subSchemaInstance = new Schema($version);
64✔
372
                $subSchemaInstance->setDefinitions($schema->getDefinitions());
64✔
373
                $subSchemaFactory = $this->schemaFactory ?: $this;
64✔
374
                $subSchemaResult = $subSchemaFactory->buildSchema($className, $format, $parentType, null, $subSchemaInstance, $serializerContext + [self::FORCE_SUBSCHEMA => true], false);
64✔
375
                if (!isset($subSchemaResult['$ref'])) {
64✔
UNCOV
376
                    continue;
×
377
                }
378

379
                if (false === $propertyMetadata->getGenId()) {
64✔
380
                    $subDefinitionName = $this->definitionNameFactory->create($className, $format, $className, null, $serializerContext);
2✔
381
                    if (isset($subSchemaResult->getDefinitions()[$subDefinitionName]['properties']['@id'])) {
2✔
UNCOV
382
                        unset($subSchemaResult->getDefinitions()[$subDefinitionName]['properties']['@id']);
×
383
                    }
384
                }
385

386
                if ($isCollection) {
64✔
387
                    $key = ($propertySchema['type'] ?? null) === 'object' ? 'additionalProperties' : 'items';
38✔
388
                    if (!isset($propertySchema['type'])) {
38✔
389
                        $propertySchema['type'] = 'array';
38✔
390
                    }
391

392
                    if (!isset($propertySchema[$key]) || !\is_array($propertySchema[$key])) {
38✔
393
                        $propertySchema[$key] = [];
38✔
394
                    }
395
                    $propertySchema[$key] = ['$ref' => $subSchemaResult['$ref']];
38✔
396
                    $refs = [];
38✔
397
                    break;
38✔
398
                }
399

400
                $refs[] = ['$ref' => $subSchemaResult['$ref']];
48✔
401
            }
402
        }
403

404
        if (!empty($refs)) {
64✔
405
            if ($isNullable) {
48✔
406
                $refs[] = ['type' => 'null'];
26✔
407
            }
408

409
            if (($c = \count($refs)) > 1) {
48✔
410
                $propertySchema = ['anyOf' => $refs];
28✔
411
            } elseif (1 === $c) {
32✔
412
                $propertySchema = ['$ref' => $refs[0]['$ref']];
32✔
413
            }
414
        }
415

416
        if (null !== $propertyMetadata->getUriTemplate() || (!\array_key_exists('readOnly', $propertySchema) && false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable()) && !isset($propertySchema['$ref'])) {
64✔
417
            $propertySchema['readOnly'] = true;
2✔
418
        }
419

420
        $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
64✔
421
    }
422

423
    private function getValidationGroups(Operation $operation): array
424
    {
425
        $groups = $operation->getValidationContext()['groups'] ?? [];
104✔
426

427
        return \is_array($groups) ? $groups : [$groups];
104✔
428
    }
429

430
    /**
431
     * Gets the options for the property name collection / property metadata factories.
432
     */
433
    private function getFactoryOptions(array $serializerContext, array $validationGroups, ?HttpOperation $operation = null): array
434
    {
435
        $options = [
118✔
436
            /* @see https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php */
437
            'enable_getter_setter_extraction' => true,
118✔
438
        ];
118✔
439

440
        if (isset($serializerContext[AbstractNormalizer::GROUPS])) {
118✔
441
            /* @see https://github.com/symfony/symfony/blob/v4.2.6/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php */
442
            $options['serializer_groups'] = (array) $serializerContext[AbstractNormalizer::GROUPS];
42✔
443
        }
444

445
        if ($operation && ($normalizationGroups = $operation->getNormalizationContext()['groups'] ?? null)) {
118✔
446
            $options['normalization_groups'] = $normalizationGroups;
44✔
447
        }
448

449
        if ($operation && ($denormalizationGroups = $operation->getDenormalizationContext()['groups'] ?? null)) {
118✔
450
            $options['denormalization_groups'] = $denormalizationGroups;
14✔
451
        }
452

453
        if ($validationGroups) {
118✔
UNCOV
454
            $options['validation_groups'] = $validationGroups;
×
455
        }
456

457
        if ($operation && ($ignoredAttributes = $operation->getNormalizationContext()['ignored_attributes'] ?? null)) {
118✔
458
            $options['ignored_attributes'] = $ignoredAttributes;
32✔
459
        }
460

461
        return $options;
118✔
462
    }
463

464
    public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void
465
    {
466
        $this->schemaFactory = $schemaFactory;
699✔
467
    }
468

469
    private function getSchemaValue(array $schema, string $key): array|string|null
470
    {
471
        if (isset($schema['items'])) {
118✔
472
            $schema = $schema['items'];
74✔
473
        }
474

475
        return $schema[$key] ?? $schema['allOf'][0][$key] ?? $schema['anyOf'][0][$key] ?? $schema['oneOf'][0][$key] ?? null;
118✔
476
    }
477
}
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