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

api-platform / core / 18223414080

03 Oct 2025 01:18PM UTC coverage: 0.0% (-22.0%) from 21.956%
18223414080

Pull #7397

github

web-flow
Merge 69d085182 into 0b8237918
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

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

12304 existing lines in 405 files now uncovered.

0 of 53965 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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
    {
UNCOV
54
        if (!$definitionNameFactory) {
×
55
            $this->definitionNameFactory = new DefinitionNameFactory($distinctFormats);
×
56
        }
57

UNCOV
58
        $this->resourceMetadataFactory = $resourceMetadataFactory;
×
UNCOV
59
        $this->resourceClassResolver = $resourceClassResolver;
×
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
    {
UNCOV
67
        $schema = $schema ? clone $schema : new Schema();
×
68

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

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

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

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

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

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

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

118
        /** @var \ArrayObject<string, mixed> $definition */
UNCOV
119
        $definition = new \ArrayObject(['type' => 'object']);
×
UNCOV
120
        $definitions[$definitionName] = $definition;
×
UNCOV
121
        if ($description = $operation?->getDescription()) {
×
UNCOV
122
            $definition['description'] = $description;
×
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
UNCOV
127
        if (false === ($serializerContext[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES] ?? true)) {
×
128
            $definition['additionalProperties'] = false;
×
129
        }
130

131
        // see https://github.com/json-schema-org/json-schema-spec/pull/737
UNCOV
132
        if (Schema::VERSION_SWAGGER !== $version && $operation && $operation->getDeprecationReason()) {
×
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
UNCOV
138
        if ($operation instanceof HttpOperation && ($operation->getTypes()[0] ?? null)) {
×
UNCOV
139
            $definition['externalDocs'] = ['url' => $operation->getTypes()[0]];
×
140
        }
141

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

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

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

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

UNCOV
162
        return $schema;
×
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
    {
170
        $version = $schema->getVersion();
×
171
        if (Schema::VERSION_SWAGGER === $version || Schema::VERSION_OPENAPI === $version) {
×
172
            $additionalPropertySchema = $propertyMetadata->getOpenapiContext();
×
173
        } else {
174
            $additionalPropertySchema = $propertyMetadata->getJsonSchemaContext();
×
175
        }
176

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

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

187
        $extraProperties = $propertyMetadata->getExtraProperties();
×
188
        // see AttributePropertyMetadataFactory
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
191
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
×
192

193
            return;
×
194
        }
195

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)
201
        $propertySchemaType = $propertySchema['type'] ?? false;
×
202

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

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

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
227
        $version = $schema->getVersion();
×
228
        $refs = [];
×
229
        $isNullable = null;
×
230

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

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

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

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

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

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
259
                    $subSchemaDefinition = $subSchema->getDefinitions()[$subDefinitionName]->getArrayCopy();
×
260
                    unset($subSchemaDefinition['properties']['@id']);
×
261
                    $subSchema->getDefinitions()[$subDefinitionName] = new \ArrayObject($subSchemaDefinition);
×
262
                }
263
            }
264

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

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

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

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

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
    {
UNCOV
294
        $version = $schema->getVersion();
×
UNCOV
295
        if (Schema::VERSION_SWAGGER === $version || Schema::VERSION_OPENAPI === $version) {
×
UNCOV
296
            $additionalPropertySchema = $propertyMetadata->getOpenapiContext();
×
297
        } else {
UNCOV
298
            $additionalPropertySchema = $propertyMetadata->getJsonSchemaContext();
×
299
        }
300

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

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

UNCOV
312
            return;
×
313
        }
314

UNCOV
315
        $type = $propertyMetadata->getNativeType();
×
316

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

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

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

UNCOV
334
            return;
×
335
        }
336

UNCOV
337
        if (Schema::UNKNOWN_TYPE === $propertySchemaType) {
×
UNCOV
338
            $propertySchema = [];
×
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
UNCOV
343
        $refs = [];
×
UNCOV
344
        $isNullable = $type?->isNullable() ?? false;
×
345

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

UNCOV
353
                $valueType = $t;
×
UNCOV
354
                $isCollection = $t instanceof CollectionType;
×
355

UNCOV
356
                if ($isCollection) {
×
UNCOV
357
                    $valueType = TypeHelper::getCollectionValueType($t);
×
358
                }
359

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

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

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

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

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

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

UNCOV
400
                $refs[] = ['$ref' => $subSchemaResult['$ref']];
×
401
            }
402
        }
403

UNCOV
404
        if (!empty($refs)) {
×
UNCOV
405
            if ($isNullable) {
×
UNCOV
406
                $refs[] = ['type' => 'null'];
×
407
            }
408

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

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

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

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

UNCOV
427
        return \is_array($groups) ? $groups : [$groups];
×
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
    {
UNCOV
435
        $options = [
×
436
            /* @see https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php */
UNCOV
437
            'enable_getter_setter_extraction' => true,
×
UNCOV
438
        ];
×
439

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

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

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

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

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

UNCOV
461
        return $options;
×
462
    }
463

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

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

UNCOV
475
        return $schema[$key] ?? $schema['allOf'][0][$key] ?? $schema['anyOf'][0][$key] ?? $schema['oneOf'][0][$key] ?? null;
×
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