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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

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

11040 existing lines in 370 files now uncovered.

0 of 48303 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/Schema.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
/**
17
 * Represents a JSON Schema document.
18
 *
19
 * Both the standard version and the OpenAPI flavors (v2 and v3) are supported.
20
 *
21
 * @see https://json-schema.org/latest/json-schema-core.html
22
 * @see https://github.com/OAI/OpenAPI-Specification
23
 *
24
 * @author Kévin Dunglas <dunglas@gmail.com>
25
 */
26
final class Schema extends \ArrayObject
27
{
28
    public const TYPE_INPUT = 'input';
29
    public const TYPE_OUTPUT = 'output';
30
    public const VERSION_JSON_SCHEMA = 'json-schema';
31
    public const VERSION_OPENAPI = 'openapi';
32
    public const VERSION_SWAGGER = 'swagger';
33
    public const UNKNOWN_TYPE = 'unknown_type';
34

35
    public function __construct(private readonly string $version = self::VERSION_JSON_SCHEMA)
36
    {
UNCOV
37
        parent::__construct(self::VERSION_JSON_SCHEMA === $this->version ? ['$schema' => 'http://json-schema.org/draft-07/schema#'] : []);
×
38
    }
39

40
    /**
41
     * The flavor used for this document: JSON Schema, OpenAPI v2 or OpenAPI v3.
42
     */
43
    public function getVersion(): string
44
    {
UNCOV
45
        return $this->version;
×
46
    }
47

48
    /**
49
     * {@inheritdoc}
50
     *
51
     * @param bool $includeDefinitions if set to false, definitions will not be included in the resulting array
52
     */
53
    public function getArrayCopy(bool $includeDefinitions = true): array
54
    {
UNCOV
55
        $schema = parent::getArrayCopy();
×
56

UNCOV
57
        if (!$includeDefinitions) {
×
UNCOV
58
            unset($schema['definitions'], $schema['components']);
×
59
        }
60

UNCOV
61
        return $schema;
×
62
    }
63

64
    /**
65
     * Retrieves the definitions used by this schema.
66
     */
67
    public function getDefinitions(): \ArrayObject
68
    {
UNCOV
69
        $definitions = $this['definitions'] ?? $this['components']['schemas'] ?? new \ArrayObject();
×
UNCOV
70
        $this->setDefinitions($definitions);
×
71

UNCOV
72
        return $definitions;
×
73
    }
74

75
    /**
76
     * Associates existing definitions to this schema.
77
     */
78
    public function setDefinitions(\ArrayObject $definitions): void
79
    {
UNCOV
80
        if (self::VERSION_OPENAPI === $this->version) {
×
UNCOV
81
            $this['components']['schemas'] = $definitions;
×
82

UNCOV
83
            return;
×
84
        }
85

UNCOV
86
        $this['definitions'] = $definitions;
×
87
    }
88

89
    /**
90
     * Returns the name of the root definition, if defined.
91
     */
92
    public function getRootDefinitionKey(): ?string
93
    {
UNCOV
94
        if (!isset($this['$ref'])) {
×
UNCOV
95
            return null;
×
96
        }
97

UNCOV
98
        return $this->removeDefinitionKeyPrefix($this['$ref']);
×
99
    }
100

101
    /**
102
     * Returns the name of the items definition, if defined.
103
     */
104
    public function getItemsDefinitionKey(): ?string
105
    {
UNCOV
106
        $ref = $this['items']['$ref'] ?? null;
×
UNCOV
107
        if (null === $ref) {
×
108
            return null;
×
109
        }
110

UNCOV
111
        return $this->removeDefinitionKeyPrefix($ref);
×
112
    }
113

114
    /**
115
     * Checks if this schema is initialized.
116
     */
117
    public function isDefined(): bool
118
    {
UNCOV
119
        return isset($this['$ref']) || isset($this['type']);
×
120
    }
121

122
    private function removeDefinitionKeyPrefix(string $definitionKey): string
123
    {
124
        // strlen('#/definitions/') = 14
125
        // strlen('#/components/schemas/') = 21
UNCOV
126
        $prefix = self::VERSION_OPENAPI === $this->version ? 21 : 14;
×
127

UNCOV
128
        return substr($definitionKey, $prefix);
×
129
    }
130
}
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