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

api-platform / core / 19337721455

13 Nov 2025 04:02PM UTC coverage: 0.0% (-24.6%) from 24.631%
19337721455

push

github

soyuka
Merge 4.1

0 of 56854 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/Metadata/Property/Factory/SchemaPropertyMetadataFactory.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\Metadata\Property\Factory;
15

16
use ApiPlatform\JsonSchema\Schema;
17
use ApiPlatform\Metadata\ApiProperty;
18
use ApiPlatform\Metadata\Exception\PropertyNotFoundException;
19
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
20
use ApiPlatform\Metadata\ResourceClassResolverInterface;
21
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
22
use Doctrine\Common\Collections\ArrayCollection;
23
use Ramsey\Uuid\UuidInterface;
24
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
25
use Symfony\Component\PropertyInfo\Type as LegacyType;
26
use Symfony\Component\TypeInfo\Type;
27
use Symfony\Component\TypeInfo\Type\BuiltinType;
28
use Symfony\Component\TypeInfo\Type\CollectionType;
29
use Symfony\Component\TypeInfo\Type\IntersectionType;
30
use Symfony\Component\TypeInfo\Type\ObjectType;
31
use Symfony\Component\TypeInfo\Type\UnionType;
32
use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;
33
use Symfony\Component\TypeInfo\TypeIdentifier;
34
use Symfony\Component\Uid\Ulid;
35
use Symfony\Component\Uid\Uuid;
36

37
/**
38
 * Build ApiProperty::schema.
39
 */
40
final class SchemaPropertyMetadataFactory implements PropertyMetadataFactoryInterface
41
{
42
    use ResourceClassInfoTrait;
43

44
    public const JSON_SCHEMA_USER_DEFINED = 'user_defined_schema';
45

46
    public function __construct(
47
        ResourceClassResolverInterface $resourceClassResolver,
48
        private readonly ?PropertyMetadataFactoryInterface $decorated = null,
49
    ) {
50
        $this->resourceClassResolver = $resourceClassResolver;
×
51
    }
52

53
    public function create(string $resourceClass, string $property, array $options = []): ApiProperty
54
    {
55
        if (null === $this->decorated) {
×
56
            $propertyMetadata = new ApiProperty();
×
57
        } else {
58
            try {
59
                $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
×
60
            } catch (PropertyNotFoundException) {
×
61
                $propertyMetadata = new ApiProperty();
×
62
            }
63
        }
64

65
        $extraProperties = $propertyMetadata->getExtraProperties();
×
66
        // see AttributePropertyMetadataFactory
67
        if (true === ($extraProperties[self::JSON_SCHEMA_USER_DEFINED] ?? false)) {
×
68
            // schema seems to have been declared by the user: do not override nor complete user value
69
            return $propertyMetadata;
×
70
        }
71

72
        $link = (($options['schema_type'] ?? null) === Schema::TYPE_INPUT) ? $propertyMetadata->isWritableLink() : $propertyMetadata->isReadableLink();
×
73
        $propertySchema = $propertyMetadata->getSchema() ?? [];
×
74

75
        if (null !== $propertyMetadata->getUriTemplate() || (!\array_key_exists('readOnly', $propertySchema) && false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable())) {
×
76
            $propertySchema['readOnly'] = true;
×
77
        }
78

79
        if (!\array_key_exists('writeOnly', $propertySchema) && false === $propertyMetadata->isReadable()) {
×
80
            $propertySchema['writeOnly'] = true;
×
81
        }
82

83
        if (!\array_key_exists('description', $propertySchema) && null !== ($description = $propertyMetadata->getDescription())) {
×
84
            $propertySchema['description'] = $description;
×
85
        }
86

87
        // see https://github.com/json-schema-org/json-schema-spec/pull/737
88
        if (!\array_key_exists('deprecated', $propertySchema) && null !== $propertyMetadata->getDeprecationReason()) {
×
89
            $propertySchema['deprecated'] = true;
×
90
        }
91

92
        // externalDocs is an OpenAPI specific extension, but JSON Schema allows additional keys, so we always add it
93
        // See https://json-schema.org/latest/json-schema-core.html#rfc.section.6.4
94
        if (!\array_key_exists('externalDocs', $propertySchema) && null !== ($iri = $propertyMetadata->getTypes()[0] ?? null)) {
×
95
            $propertySchema['externalDocs'] = ['url' => $iri];
×
96
        }
97

98
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
99
            return $propertyMetadata->withSchema($this->getLegacyTypeSchema($propertyMetadata, $propertySchema, $resourceClass, $property, $link));
×
100
        }
101

102
        return $propertyMetadata->withSchema($this->getTypeSchema($propertyMetadata, $propertySchema, $link));
×
103
    }
104

105
    private function getTypeSchema(ApiProperty $propertyMetadata, array $propertySchema, ?bool $link): array
106
    {
107
        $type = $propertyMetadata->getNativeType();
×
108

109
        $className = null;
×
110
        $typeIsResourceClass = function (Type $type) use (&$className): bool {
×
111
            return $type instanceof ObjectType && $this->resourceClassResolver->isResourceClass($className = $type->getClassName());
×
112
        };
×
113
        $isResourceClass = $type?->isSatisfiedBy($typeIsResourceClass);
×
114

115
        if (null !== $propertyMetadata->getUriTemplate() || (!\array_key_exists('readOnly', $propertySchema) && false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable()) && !$className) {
×
116
            $propertySchema['readOnly'] = true;
×
117
        }
118

119
        if (!\array_key_exists('default', $propertySchema) && null !== ($default = $propertyMetadata->getDefault()) && false === (\is_array($default) && empty($default)) && !$isResourceClass) {
×
120
            if ($default instanceof \BackedEnum) {
×
121
                $default = $default->value;
×
122
            }
123
            $propertySchema['default'] = $default;
×
124
        }
125

126
        if (!\array_key_exists('example', $propertySchema) && null !== ($example = $propertyMetadata->getExample()) && false === (\is_array($example) && empty($example))) {
×
127
            $propertySchema['example'] = $example;
×
128
        }
129

130
        $hasType = $this->getSchemaValue($propertySchema, 'type') || $this->getSchemaValue($propertyMetadata->getJsonSchemaContext() ?? [], 'type') || $this->getSchemaValue($propertyMetadata->getOpenapiContext() ?? [], 'type');
×
131
        $hasRef = $this->getSchemaValue($propertySchema, '$ref') || $this->getSchemaValue($propertyMetadata->getJsonSchemaContext() ?? [], '$ref') || $this->getSchemaValue($propertyMetadata->getOpenapiContext() ?? [], '$ref');
×
132

133
        // never override the following keys if at least one is already set or if there's a custom openapi context
134
        if ($hasType || $hasRef || !$type) {
×
135
            return $propertySchema;
×
136
        }
137

138
        if ($type instanceof CollectionType && null !== $propertyMetadata->getUriTemplate()) {
×
139
            $type = $type->getCollectionValueType();
×
140
        }
141

142
        return $propertySchema + $this->getJsonSchemaFromType($type, $link);
×
143
    }
144

145
    /**
146
     * Applies nullability rules to a generated JSON schema based on the original type's nullability.
147
     *
148
     * @param array<string, mixed> $schema     the base JSON schema generated for the non-null type
149
     * @param bool                 $isNullable whether the original type allows null
150
     *
151
     * @return array<string, mixed> the JSON schema with nullability applied
152
     */
153
    private function applyNullability(array $schema, bool $isNullable): array
154
    {
155
        if (!$isNullable) {
×
156
            return $schema;
×
157
        }
158

159
        if (isset($schema['type']) && 'null' === $schema['type'] && 1 === \count($schema)) {
×
160
            return $schema;
×
161
        }
162

163
        if (isset($schema['anyOf']) && \is_array($schema['anyOf'])) {
×
164
            $hasNull = false;
×
165
            foreach ($schema['anyOf'] as $anyOfSchema) {
×
166
                if (isset($anyOfSchema['type']) && 'null' === $anyOfSchema['type']) {
×
167
                    $hasNull = true;
×
168
                    break;
×
169
                }
170
            }
171
            if (!$hasNull) {
×
172
                $schema['anyOf'][] = ['type' => 'null'];
×
173
            }
174

175
            return $schema;
×
176
        }
177

178
        if (isset($schema['type'])) {
×
179
            $currentType = $schema['type'];
×
180
            $schema['type'] = \is_array($currentType) ? array_merge($currentType, ['null']) : [$currentType, 'null'];
×
181

182
            if (isset($schema['enum'])) {
×
183
                $schema['enum'][] = null;
×
184

185
                return $schema;
×
186
            }
187

188
            return $schema;
×
189
        }
190

191
        return ['anyOf' => [$schema, ['type' => 'null']]];
×
192
    }
193

194
    /**
195
     * Converts a TypeInfo Type into a JSON Schema definition array.
196
     *
197
     * @return array<string, mixed>
198
     */
199
    private function getJsonSchemaFromType(Type $type, ?bool $readableLink = null): array
200
    {
201
        $isNullable = $type->isNullable();
×
202

203
        if ($type instanceof UnionType) {
×
204
            $subTypes = array_filter($type->getTypes(), fn ($t) => !($t instanceof BuiltinType && $t->isIdentifiedBy(TypeIdentifier::NULL)));
×
205

206
            foreach ($subTypes as $t) {
×
207
                $s = $this->getJsonSchemaFromType($t, $readableLink);
×
208
                // We can not find what type this is, let it be computed at runtime by the SchemaFactory
209
                if (($s['type'] ?? null) === Schema::UNKNOWN_TYPE) {
×
210
                    return $s;
×
211
                }
212
            }
213

214
            $schemas = array_map(fn ($t) => $this->getJsonSchemaFromType($t, $readableLink), $subTypes);
×
215

216
            if (0 === \count($schemas)) {
×
217
                $schema = [];
×
218
            } elseif (1 === \count($schemas)) {
×
219
                $schema = current($schemas);
×
220
            } else {
221
                $schema = ['anyOf' => array_values($schemas)];
×
222
            }
223

224
            return $this->applyNullability($schema, $isNullable);
×
225
        }
226

227
        if ($type instanceof IntersectionType) {
×
228
            $schemas = [];
×
229
            foreach ($type->getTypes() as $t) {
×
230
                while ($t instanceof WrappingTypeInterface) {
×
231
                    $t = $t->getWrappedType();
×
232
                }
233

234
                $subSchema = $this->getJsonSchemaFromType($t, $readableLink);
×
235
                if (!empty($subSchema)) {
×
236
                    $schemas[] = $subSchema;
×
237
                }
238
            }
239

240
            return $this->applyNullability(['allOf' => $schemas], $isNullable);
×
241
        }
242

243
        if ($type instanceof CollectionType) {
×
244
            $valueType = $type->getCollectionValueType();
×
245
            $valueSchema = $this->getJsonSchemaFromType($valueType, $readableLink);
×
246
            $keyType = $type->getCollectionKeyType();
×
247

248
            // Associative array (string keys)
249
            if ($keyType->isSatisfiedBy(fn (Type $t) => $t instanceof BuiltinType && $t->isIdentifiedBy(TypeIdentifier::INT))) {
×
250
                $schema = [
×
251
                    'type' => 'array',
×
252
                    'items' => $valueSchema,
×
253
                ];
×
254
            } else { // List (int keys)
255
                $schema = [
×
256
                    'type' => 'object',
×
257
                    'additionalProperties' => $valueSchema,
×
258
                ];
×
259
            }
260

261
            return $this->applyNullability($schema, $isNullable);
×
262
        }
263

264
        if ($type instanceof ObjectType) {
×
265
            $schema = $this->getClassSchemaDefinition($type->getClassName(), $readableLink);
×
266

267
            return $this->applyNullability($schema, $isNullable);
×
268
        }
269

270
        if ($type instanceof BuiltinType) {
×
271
            $schema = match ($type->getTypeIdentifier()) {
×
272
                TypeIdentifier::INT => ['type' => 'integer'],
×
273
                TypeIdentifier::FLOAT => ['type' => 'number'],
×
274
                TypeIdentifier::BOOL => ['type' => 'boolean'],
×
275
                TypeIdentifier::TRUE => ['type' => 'boolean', 'const' => true],
×
276
                TypeIdentifier::FALSE => ['type' => 'boolean', 'const' => false],
×
277
                TypeIdentifier::STRING => ['type' => 'string'],
×
278
                TypeIdentifier::ARRAY => ['type' => 'array', 'items' => []],
×
279
                TypeIdentifier::ITERABLE => ['type' => 'array', 'items' => []],
×
280
                TypeIdentifier::OBJECT => ['type' => 'object'],
×
281
                TypeIdentifier::RESOURCE => ['type' => 'string'],
×
282
                TypeIdentifier::CALLABLE => ['type' => 'string'],
×
283
                TypeIdentifier::MIXED => ['type' => 'string'],
×
284
                default => ['type' => 'null'],
×
285
            };
×
286

287
            return $this->applyNullability($schema, $isNullable);
×
288
        }
289

290
        return ['type' => Schema::UNKNOWN_TYPE];
×
291
    }
292

293
    /**
294
     * Gets the JSON Schema definition for a class.
295
     */
296
    private function getClassSchemaDefinition(?string $className, ?bool $readableLink): array
297
    {
298
        if (null === $className) {
×
299
            return ['type' => 'string'];
×
300
        }
301

302
        if (is_a($className, \DateTimeInterface::class, true)) {
×
303
            return ['type' => 'string', 'format' => 'date-time'];
×
304
        }
305

306
        if (is_a($className, \DateInterval::class, true)) {
×
307
            return ['type' => 'string', 'format' => 'duration'];
×
308
        }
309

310
        if (is_a($className, UuidInterface::class, true) || is_a($className, Uuid::class, true)) {
×
311
            return ['type' => 'string', 'format' => 'uuid'];
×
312
        }
313

314
        if (is_a($className, Ulid::class, true)) {
×
315
            return ['type' => 'string', 'format' => 'ulid'];
×
316
        }
317

318
        if (is_a($className, \SplFileInfo::class, true)) {
×
319
            return ['type' => 'string', 'format' => 'binary'];
×
320
        }
321

322
        $isResourceClass = $this->isResourceClass($className);
×
323
        if (!$isResourceClass && is_a($className, \BackedEnum::class, true)) {
×
324
            $enumCases = array_map(static fn (\BackedEnum $enum): string|int => $enum->value, $className::cases());
×
325
            $type = \is_string($enumCases[0] ?? '') ? 'string' : 'integer';
×
326

327
            return ['type' => $type, 'enum' => $enumCases];
×
328
        }
329

330
        if (false === $readableLink && $isResourceClass) {
×
331
            return [
×
332
                'type' => 'string',
×
333
                'format' => 'iri-reference',
×
334
                'example' => 'https://example.com/',
×
335
            ];
×
336
        }
337

338
        return ['type' => Schema::UNKNOWN_TYPE];
×
339
    }
340

341
    private function getLegacyTypeSchema(ApiProperty $propertyMetadata, array $propertySchema, string $resourceClass, string $property, ?bool $link): array
342
    {
343
        $types = $propertyMetadata->getBuiltinTypes() ?? [];
×
344
        $className = ($types[0] ?? null)?->getClassName() ?? null;
×
345

346
        if (null !== $propertyMetadata->getUriTemplate() || (!\array_key_exists('readOnly', $propertySchema) && false === $propertyMetadata->isWritable() && !$propertyMetadata->isInitializable()) && !$className) {
×
347
            $propertySchema['readOnly'] = true;
×
348
        }
349

350
        if (!\array_key_exists('default', $propertySchema) && !empty($default = $propertyMetadata->getDefault()) && (!$className || !$this->isResourceClass($className))) {
×
351
            if ($default instanceof \BackedEnum) {
×
352
                $default = $default->value;
×
353
            }
354
            $propertySchema['default'] = $default;
×
355
        }
356

357
        if (!\array_key_exists('example', $propertySchema) && !empty($example = $propertyMetadata->getExample())) {
×
358
            $propertySchema['example'] = $example;
×
359
        }
360

361
        // never override the following keys if at least one is already set or if there's a custom openapi context
362
        if (
363
            [] === $types
×
364
            || ($propertySchema['type'] ?? $propertySchema['$ref'] ?? $propertySchema['anyOf'] ?? $propertySchema['allOf'] ?? $propertySchema['oneOf'] ?? false)
×
365
            || \array_key_exists('type', $propertyMetadata->getOpenapiContext() ?? [])
×
366
        ) {
367
            return $propertySchema;
×
368
        }
369

370
        if ($propertyMetadata->getUriTemplate()) {
×
371
            return $propertySchema + [
×
372
                'type' => 'string',
×
373
                'format' => 'iri-reference',
×
374
                'example' => 'https://example.com/',
×
375
            ];
×
376
        }
377

378
        $valueSchema = [];
×
379
        foreach ($types as $type) {
×
380
            // Temp fix for https://github.com/symfony/symfony/pull/52699
381
            if (ArrayCollection::class === $type->getClassName()) {
×
382
                $type = new LegacyType($type->getBuiltinType(), $type->isNullable(), $type->getClassName(), true, $type->getCollectionKeyTypes(), $type->getCollectionValueTypes());
×
383
            }
384

385
            if ($isCollection = $type->isCollection()) {
×
386
                $keyType = $type->getCollectionKeyTypes()[0] ?? null;
×
387
                $valueType = $type->getCollectionValueTypes()[0] ?? null;
×
388
            } else {
389
                $keyType = null;
×
390
                $valueType = $type;
×
391
            }
392

393
            if (null === $valueType) {
×
394
                $builtinType = 'string';
×
395
                $className = null;
×
396
            } else {
397
                $builtinType = $valueType->getBuiltinType();
×
398
                $className = $valueType->getClassName();
×
399
            }
400

401
            if ($isCollection && null !== $propertyMetadata->getUriTemplate()) {
×
402
                $keyType = null;
×
403
                $isCollection = false;
×
404
            }
405

406
            $propertyType = $this->getLegacyType(new LegacyType($builtinType, $type->isNullable(), $className, $isCollection, $keyType, $valueType), $link);
×
407
            if (!\in_array($propertyType, $valueSchema, true)) {
×
408
                $valueSchema[] = $propertyType;
×
409
            }
410
        }
411

412
        if (1 === \count($valueSchema)) {
×
413
            return $propertySchema + $valueSchema[0];
×
414
        }
415

416
        // multiple builtInTypes detected: determine oneOf/allOf if union vs intersect types
417
        try {
418
            $reflectionClass = new \ReflectionClass($resourceClass);
×
419
            $reflectionProperty = $reflectionClass->getProperty($property);
×
420
            $composition = $reflectionProperty->getType() instanceof \ReflectionUnionType ? 'oneOf' : 'allOf';
×
421
        } catch (\ReflectionException) {
×
422
            // cannot detect types
423
            $composition = 'anyOf';
×
424
        }
425

426
        return $propertySchema + [$composition => $valueSchema];
×
427
    }
428

429
    private function getLegacyType(LegacyType $type, ?bool $readableLink = null): array
430
    {
431
        if (!$type->isCollection()) {
×
432
            return $this->addNullabilityToTypeDefinition($this->legacyTypeToArray($type, $readableLink), $type);
×
433
        }
434

435
        $keyType = $type->getCollectionKeyTypes()[0] ?? null;
×
436
        $subType = ($type->getCollectionValueTypes()[0] ?? null) ?? new LegacyType($type->getBuiltinType(), false, $type->getClassName(), false);
×
437

438
        if (null !== $keyType && LegacyType::BUILTIN_TYPE_STRING === $keyType->getBuiltinType()) {
×
439
            return $this->addNullabilityToTypeDefinition([
×
440
                'type' => 'object',
×
441
                'additionalProperties' => $this->getLegacyType($subType, $readableLink),
×
442
            ], $type);
×
443
        }
444

445
        return $this->addNullabilityToTypeDefinition([
×
446
            'type' => 'array',
×
447
            'items' => $this->getLegacyType($subType, $readableLink),
×
448
        ], $type);
×
449
    }
450

451
    private function legacyTypeToArray(LegacyType $type, ?bool $readableLink = null): array
452
    {
453
        return match ($type->getBuiltinType()) {
×
454
            LegacyType::BUILTIN_TYPE_INT => ['type' => 'integer'],
×
455
            LegacyType::BUILTIN_TYPE_FLOAT => ['type' => 'number'],
×
456
            LegacyType::BUILTIN_TYPE_BOOL => ['type' => 'boolean'],
×
457
            LegacyType::BUILTIN_TYPE_OBJECT => $this->getLegacyClassType($type->getClassName(), $type->isNullable(), $readableLink),
×
458
            default => ['type' => 'string'],
×
459
        };
×
460
    }
461

462
    /**
463
     * Gets the JSON Schema document which specifies the data type corresponding to the given PHP class, and recursively adds needed new schema to the current schema if provided.
464
     *
465
     * Note: if the class is not part of exceptions listed above, any class is considered as a resource.
466
     *
467
     * @throws PropertyNotFoundException
468
     *
469
     * @return array<string, mixed>
470
     */
471
    private function getLegacyClassType(?string $className, bool $nullable, ?bool $readableLink): array
472
    {
473
        if (null === $className) {
×
474
            return ['type' => 'string'];
×
475
        }
476

477
        if (is_a($className, \DateTimeInterface::class, true)) {
×
478
            return [
×
479
                'type' => 'string',
×
480
                'format' => 'date-time',
×
481
            ];
×
482
        }
483

484
        if (is_a($className, \DateInterval::class, true)) {
×
485
            return [
×
486
                'type' => 'string',
×
487
                'format' => 'duration',
×
488
            ];
×
489
        }
490

491
        if (is_a($className, UuidInterface::class, true) || is_a($className, Uuid::class, true)) {
×
492
            return [
×
493
                'type' => 'string',
×
494
                'format' => 'uuid',
×
495
            ];
×
496
        }
497

498
        if (is_a($className, Ulid::class, true)) {
×
499
            return [
×
500
                'type' => 'string',
×
501
                'format' => 'ulid',
×
502
            ];
×
503
        }
504

505
        if (is_a($className, \SplFileInfo::class, true)) {
×
506
            return [
×
507
                'type' => 'string',
×
508
                'format' => 'binary',
×
509
            ];
×
510
        }
511

512
        $isResourceClass = $this->isResourceClass($className);
×
513
        if (!$isResourceClass && is_a($className, \BackedEnum::class, true)) {
×
514
            $enumCases = array_map(static fn (\BackedEnum $enum): string|int => $enum->value, $className::cases());
×
515

516
            $type = \is_string($enumCases[0] ?? '') ? 'string' : 'integer';
×
517

518
            if ($nullable) {
×
519
                $enumCases[] = null;
×
520
            }
521

522
            return [
×
523
                'type' => $type,
×
524
                'enum' => $enumCases,
×
525
            ];
×
526
        }
527

528
        if (false === $readableLink && $isResourceClass) {
×
529
            return [
×
530
                'type' => 'string',
×
531
                'format' => 'iri-reference',
×
532
                'example' => 'https://example.com/',
×
533
            ];
×
534
        }
535

536
        // When this is set, we compute the schema at SchemaFactory::buildPropertySchema as it
537
        // will end up being a $ref to another class schema, we don't have enough informations here
538
        return ['type' => Schema::UNKNOWN_TYPE];
×
539
    }
540

541
    /**
542
     * @param array<string, mixed> $jsonSchema
543
     *
544
     * @return array<string, mixed>
545
     */
546
    private function addNullabilityToTypeDefinition(array $jsonSchema, LegacyType $type): array
547
    {
548
        if (!$type->isNullable()) {
×
549
            return $jsonSchema;
×
550
        }
551

552
        if (\array_key_exists('$ref', $jsonSchema)) {
×
553
            return ['anyOf' => [$jsonSchema, ['type' => 'null']]];
×
554
        }
555

556
        return [...$jsonSchema, ...[
×
557
            'type' => \is_array($jsonSchema['type'])
×
558
                ? array_merge($jsonSchema['type'], ['null'])
×
559
                : [$jsonSchema['type'], 'null'],
×
560
        ]];
×
561
    }
562

563
    private function getSchemaValue(array $schema, string $key): array|string|null
564
    {
565
        if (isset($schema['items'])) {
×
566
            $schema = $schema['items'];
×
567
        }
568

569
        return $schema[$key] ?? $schema['allOf'][0][$key] ?? $schema['anyOf'][0][$key] ?? $schema['oneOf'][0][$key] ?? null;
×
570
    }
571
}
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

© 2026 Coveralls, Inc